Tutorials on How to Install a Kernel Module (ko) on secureboot-enabled Fedora 42

Hello, I encountered problems when inserting module several days ago, now I solved it, and I wrote a tutorials about it. So I want to share it here.

Setting up DKMS


sudo dnf install dkms openssl

sudo dkms generate_mok

# we need this defined password later

MOK_PASSWD="fedora"

sudo mokutil -i /var/lib/dkms/mok.pub << EOI

${MOK_PASSWD}

${MOK_PASSWD}

EOI

# use this command to enter "UEFI key management"

sudo systemctl reboot

After rebooting, press any key to enter MOK management at the blue screen, see Figure below

Select “Enroll MOK”, choose “Continue”, select “Yes”, enter password “fedora” at the password prompt, then reboot

Writing dkms.conf and Building the ko

# dkms.conf

MAKE="make"
CLEAN="make clean"
BUILT_MODULE_NAME=simproc
BUILT_MODULE_LOCATION=./
PACKAGE_NAME=simproc
PACKAGE_VERSION=1.0
DEST_MODULE_LOCATION[0]="/extra"
# REMAKE_INITRD=yes

Follow my dkms.conf, modify BUILT_MODULE_NAME and PACKAGE_NAME to your ko name

DEST_MODULE_LOCATION specifies where to store the compressed ko file:

/kernel represents /lib/modules/6.14.6-300.fc42.x86_64/kernel

/updates represents /lib/modules/6.14.6-300.fc42.x86_64/updates

/extra represents /lib/modules/6.14.6-300.fc42.x86_64/extra

After writing the config, create a new directory under /usr/src, the directory name must be PACKAGE_NAME-PACKAGE_VERSION

For example: sudo mkdir /usr/src/simproc-1.0

Then copy the source code and Makefile needed to build the ko to /usr/src/simproc-1.0:


$ ls

dkms.conf Makefile README.md simproc.c usertest.c

$ sudo cp -r . /usr/src/simproc-1.0

$ cd /usr/src/simproc-1.0

Build under /usr/src/simproc-1.0:


$ sudo dkms build -m simproc -v 1.0

Deprecated feature: CLEAN (/usr/src/simproc-1.0/dkms.conf)

Creating symlink /var/lib/dkms/simproc/1.0/source -> /usr/src/simproc-1.0

Sign command: /lib/modules/6.14.6-300.fc42.x86_64/build/scripts/sign-file

Signing key: /var/lib/dkms/mok.key

Public certificate (MOK): /var/lib/dkms/mok.pub

Building module(s)... done.

Signing module /var/lib/dkms/simproc/1.0/build/./simproc.ko

$ sudo dkms install -m simproc -v 1.0

Deprecated feature: CLEAN (/var/lib/dkms/simproc/1.0/source/dkms.conf)

Installing /lib/modules/6.14.6-300.fc42.x86_64/extra/simproc.ko.xz

Running depmod..... done.

Installing the ko


$ cd /lib/modules/6.14.6-300.fc42.x86_64/extra/

# under /lib/modules/6.14.6-300.fc42.x86_64/extra/

$ sudo xz -d simproc.ko.xz

$ sudo insmod simproc.ko

$ sudo dmesg | tail -10

Reference Links

How to insmod ko on Fedora 42

What does DKMS do? How do I use it?

dell/dkms

Kernel modules contain .ko.xz files

my simproc repo

This part can be simplified:

sudo modprobe simproc

Thank you. I seldom used modprobe before. I found they are in kmod package just now.