1. Overview

The Linux kernel is the most crucial component of the Linux operating system and what actually defines it. On the other hand, kernel modules are additional, often pluggable, pieces of code that extend the functionality of the kernel. These modules, usually for hardware drivers, can come from various sources. Some are included directly in the kernel source tree, while others come from an external source, such as a hardware vendor.

The process of installing and managing external kernel modules can be tricky. This is exactly where DKMS (Dynamic Kernel Module Support) steps in. It’s a framework that simplifies the installation and management of these modules.

In this tutorial, we’ll discuss DKMS in detail and learn how to install a module with it.

2. What Is DKMS?

DKMS is a framework that enables us to manage and build kernel modules whose source code resides outside the main kernel source tree. These external modules often come from hardware vendors and don’t exist in the standard kernel distribution.

This framework also monitors the system for kernel updates and automatically triggers a rebuild of the external modules whenever we install a new kernel. This rebuild process utilizes the latest kernel headers to ensure compatibility with the new kernel release.

3. Pros and Cons of DKMS

There are advantages and drawbacks to all systems and DKMS isn’t an exception in this case.

To begin with, let’s go through the benefits of this framework that make it a valuable tool for managing and installing external kernel modules:

  • automates the process of rebuilding external modules whenever we install a new kernel
  • eliminates the need to manually recompile modules after updates
  • not limited to hardware vendors
  • works with various external modules, including those developed by the open-source community for specific functionalities or custom filesystems
  • provides support for installing .rpm and .deb packages
  • compatible with most Linux distributions

DKMS also has some cons that make it a bit tricky to use:

  • compared to installing pre-compiled modules from the distribution’s repositories, installing via this utility can introduce additional complexity
  • there’s a chance that a DKMS rebuild might fail due to incompatibilities between the module and the new kernel
  • problems with DKMS could leave the system largely unusable until the issue is resolved
  • relies on the availability of kernel headers for the specific kernel version, but some distributions might not provide these headers in their repositories

The next section discusses the process that we can follow to use DKMS on a Linux distribution.

4. Using DKMS

After understanding the basic idea of DKMS, let’s go through its practical usage.

4.1. Installation

The first step is to check if the system includes dkms as an installed utility:

$ dkms --version
dkms:2.8

Evidently, the DKMS version that’s on the system is 2.8.

If we don’t get an output like the above, then it might indicate that we don’t have the DKMS tool on the system. In this case, we go ahead and install it, most often via a local package manager such as apt:

$ sudo apt install dkms

Once the installation is complete, we download the required external module.

4.2. Acquire Modules

Usually, we get modules from verified sources on the Web in the form of a .tar archive. Let’s assume that we downloaded a module named mod-v2.3.tar.gz, which we want to install on the machine using DKMS.

Now, let’s navigate to the directory where the archive is stored and extract the contents of the archive using the tar command:

$ cd /usr/lib
$ tar -xf mod-v2.3.tar.gz

The -f option specifies the archive we want to extract, i.e., mod-v2.3.tar.gz, while the -x option instructs tar to extract the contents of the archive to the current directory.

4.3. Creating and Editing the dkms.conf File

Now, let’s navigate to the extracted directory:

$ cd mod-v2.3

Then, let’s create the dkms.conf file in the directory:

$ touch dkms.conf

This file specifies the process of building and installing a particular module.

The next step is to open the file and insert some necessary information about the process of building and installing the mod-v2.3 module:

$ cat dkms.conf
PACKAGE_NAME="mod"
PACKAGE_VERSION="2.3"
MAKE="make --uname_r=$kernelver"
CLEAN="make clean"
BUILT_MODULE_NAME="$mod"
DEST_MODULE_LOCATION="/kernel/drivers"
REMAKE_INITRD="yes"
AUTOINSTALL="yes

After saving the file, let’s proceed to the next step.

4.4. Installing the Module

To begin with, let’s use dkms to add the module to the DKMS tree:

$ dkms add -m mod -v 2.3

In particular, the -m option specifies the module to be added, i.e., mod. On the other hand, the -v option indicates the module version, i.e., 2.3.

Next, let’s leverage the dkms to build the module with respect to the currently running kernel version:

$ dkms build -m mod -v 2.3 -k 6.4.16-33

The -k option specifies the kernel version that we’re currently operating on, i.e., 6.4.16-33.

Finally, we utilize dkms to install the module on the system:

$ dkms install -m mod -v 2.3

After this point, there should be no need to rebuild this module manually after each kernel update, as DKMS should automatically rebuild it whenever we upgrade to a newer version.

5. Conclusion

In this article, we had a detailed discussion about DKMS, its pros and cons, and the step-by-step process of using this framework on a Linux distribution.

In general, DKMS is a valuable tool for Linux users who rely on external kernel modules. It automates updates and offers flexibility, but it’s not without limitations. If we’re comfortable with the command line and understand the potential risks involved, DKMS can be a great way to manage our external modules.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments