Dynamic Kernel Module Support

From LinuxReviews
Jump to navigationJump to search

DKMS (Dynamic Kernel Module Support) is a framework for third party kernel modules which are automatically rebuilt when new kernels are installed. It is highly useful if you are using out-of-tree kernel modules. The most common use-case for DKMS is to install wrappers for binary blob drivers.

DKMS is free software under the GNU GPL v2. All the major Linux distributions support it.

HOWTO use DKMS[edit]

Let's say you would like to use the no longer supported (EOL) but more updated than the kernels it87 module which used to be maintained by the Gerg and you would like to build it with DKMS when you update your kernel.

The first and most important step is to ensure that the kernel development package is installed (if you are not building kernels yourself). That package is typically named something like kernel-devel (Fedora, RHEL, CentOS). You will also need the dkms package (dnf -y install dkms kernel-devel)

The next step would be to acquire the source and put it in /usr/src

cd /usr/src
git clone https://github.com/richard378/it87-eol.git

Now you have a folder called it87-eol in /usr/src. The next step would be to make a dkms.conf which tells DKMS how to (ab)use that source directory. That file would be placed in the module directory, in this case /usr/src/it87-eol. Luckily, it87 comes with a fine dkms.conf file which looks like this:

MAKE="make TARGET=${kernelver}"
CLEAN="make clean"
PACKAGE_NAME="it87"
PACKAGE_VERSION="to be filled by make dkms"
BUILT_MODULE_NAME[0]="it87"
DEST_MODULE_LOCATION[0]="/kernel/drivers/hwmon/it87"
AUTOINSTALL="yes"

You would have to write that file yourself it it wasn't included. In this case it is.

Now it is time to inform DKMS that you have a out-of-tree module you would like to use. This is done with dkms add with two arguments: -m for module and -v for version. In this case that would be it87 and eol. Thus; the dmks add command becomes:

dkms add -m it87 -v eol

That should, in this case, show:

Creating symlink /var/lib/dkms/it87/eol/source ->
                 /usr/src/it87-eol

DKMS: add completed.

The next step is to build the module:

dkms build -m it87 -v eol

And then install it:

dkms install -m it87 -v eol

dkms will install the modules in /lib/modules/`uname -r`/ under the folder specified in DEST_MODULE_LOCATION[0] in the dkms.conf That command will run depmod and make the module available.

The Magic[edit]

Linux distributions setup dkms to recompile and install dkms modules when the kernel is updated. This Fedora/RHEL/CentOS does this by installing a /etc/kernel/postinst.d/dkms script which is executed when new kernels are installed.

Links[edit]