Skip to main content
Consider sponsoring Nitrux at Open Collective. Open Collective is a platform where communities can collect and disburse money transparently to sustain and grow their projects; Click here to learn more.

Dynamic Kernel Module Support (DKMS) is a framework that allows kernel modules to be dynamically built for each kernel on your system in a simplified and organized fashion.

In today’s tutorial, we’ll see how to use DKMS to build kernel modules in Nitrux.

Difficulty: ★★☆☆☆

📜 Table of Contents

  1. Building DKMS modules in Nitrux
  2. Installing DKMS modules in Nitrux
  3. Loading DKMS modules in Nitrux
  4. Troubleshooting
    1. Common Limitations
    2. Debugging Failed Builds

Building DKMS modules in Nitrux

For this tutorial, we will build the Zenergy module. This kernel module is based on the AMD_ENERGY driver but with some jiffies added so non-root users can read it safely. The Zenergy kernel module is necessary for software like MangoHud to display the CPU power consumption for AMD Zen processors.

The DKMS source directory is typically located in /usr/src. Since this directory is in the root, we need to use

overlayroot-chroot
overlayroot-chroot.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo overlayroot-chroot
mount -t devtmpfs dev /dev
git clone https://github.com/Nitrux/zenergy.git /usr/src/zenergy-1.0
sudo overlayroot-chroot mount -t devtmpfs dev /dev git clone https://github.com/Nitrux/zenergy.git /usr/src/zenergy-1.0
sudo overlayroot-chroot

mount -t devtmpfs dev /dev

git clone https://github.com/Nitrux/zenergy.git /usr/src/zenergy-1.0

We add the Zenergy module to DKMS by specifying the module name (zenergy) and version (1.0). This command registers the module with DKMS, preparing it for the build:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
dkms add -m zenergy -v 1.0
dkms add -m zenergy -v 1.0
dkms add -m zenergy -v 1.0

With the module added, build it using DKMS. This compiles the module for the currently running kernel:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
dkms build -m zenergy -v 1.0
dkms build -m zenergy -v 1.0
dkms build -m zenergy -v 1.0

Installing DKMS modules in Nitrux

Finally, install the module. The flag ensures the module installs even if previous versions or similar modules are installed:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
dkms install --force -m zenergy -v 1.0
dkms install --force -m zenergy -v 1.0
dkms install --force -m zenergy -v 1.0

After these steps, your zenergy module should be built and installed successfully. We can exit the shell session using the following commands.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
umount /dev
sync
exit
umount /dev sync exit
umount /dev
sync
exit

We must reboot to load the changes into the overlay.

Loading DKMS modules in Nitrux

Once the Zenergy module is installed, it must be loaded into the kernel for the system to use actively. Here’s how to manually load the module or set it to load automatically at boot.

To manually load the Zenergy module, use the following command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
modprobe zenergy
modprobe zenergy
modprobe zenergy

This command will insert the module into the running kernel. You can check if it loaded successfully with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
lsmod | grep zenergy
lsmod | grep zenergy
lsmod | grep zenergy

If the module is listed in the output, it is active in the kernel.

Alternatively, add it to the module loading configuration to ensure it loads automatically at each boot.

To ensure the Zenergy module loads automatically at each boot, add it to the module loading configuration.

Once again, we use

overlayroot-chroot
overlayroot-chroot to add a file to the root directory.

  • Create a configuration file in /etc/modules-load.d/:
    echo "zenergy" | tee /etc/modules-load.d/zenergy.conf
    echo "zenergy" | tee /etc/modules-load.d/zenergy.conf
    • 🔰 Information: This file tells the system to load the Zenergy module at boot.
  • We must reboot to load the changes into the overlay.

After rebooting, confirm that the module is active by running:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
lsmod | grep zenergy
lsmod | grep zenergy
lsmod | grep zenergy

If it appears in the list, the module will be successfully loaded on boot.

Troubleshooting

If you encounter issues during the DKMS module build or installation, you can use the following strategies to diagnose and resolve problems.

Common Limitations

  1. Kernel ABI Changes: DKMS might fail if the kernel ABI significantly changes. For better compatibility, it’s recommended that DKMS be used on a stable-release kernel.
  2. Initramfs Compatibility: DKMS modules will not load correctly if there are conflicts with modules in the initramfs.

Debugging Failed Builds

If the DKMS build fails, DKMS generates a make.log file, which logs the compilation steps and errors. You can view this log file to get more information about the issue. The log file is located in the following directory:

/var/lib/dkms/zenergy/1.0/build/make.log
/var/lib/dkms/zenergy/1.0/build/make.log

Opening this file will provide detailed error messages and help identify the exact problem.


That’s it; this concludes today’s tutorial.