Whenever you install proprietary device drivers on Linux—such as official NVIDIA graphics drivers, VirtualBox host virtualisation modules, Broadcom or Realtek Wi-Fi chipsets, or ZFS filesystems—those software packages exist as out-of-tree kernel modules. Because the Linux kernel maintains no stable internal binary interface (ABI), kernel modules compiled for one kernel release cannot execute on another.
To eliminate the need to manually recompile drivers after every routine security update, Linux systems rely on DKMS (Dynamic Kernel Module Support). DKMS automatically detects kernel upgrades and rebuilds your third-party drivers against the new kernel headers. However, when compiler toolchains change or a module fails to compile automatically, your system may boot to a blank screen or lose network connectivity. In this tutorial, we will explore how to monitor, build, rebuild, and remove DKMS modules across your Linux system.
Installing DKMS and Essential Kernel Development Headers
Before DKMS can compile C code into binary kernel objects (.ko files), your system requires both the DKMS framework and the development headers matching your active kernel release.
On Ubuntu, Debian, and Linux Mint:
sudo apt update
sudo apt install dkms build-essential linux-headers-$(uname -r) -y
On Fedora, RHEL, Rocky Linux, and AlmaLinux:
sudo dnf install dkms kernel-devel-$(uname -r) kernel-headers gcc make -y
On Arch Linux and Manjaro:
sudo pacman -S dkms linux-headers base-devel
Inspecting Current DKMS Module Status with dkms status
The first diagnostic step is auditing which modules are registered on your system and whether they are active, built, or broken:
dkms status
The command will output entries structured like the following:
nvidia/550.67, 6.8.0-40-generic, x86_64: installed
virtualbox-guest/7.0.16, 6.8.0-40-generic, x86_64: installed
r8168/8.052.01, 6.8.0-45-generic, x86_64: built
Notice the three possible operational states:
- installed: The module compiled cleanly and is actively loaded into the running kernel tree.
- built: The binary module compiled successfully but has not yet been formally linked into the kernel modules directory.
- added: The driver source code resides in
/usr/src/, but compilation has not yet been executed.
Automatically Rebuilding All Modules with dkms autoinstall
If you recently performed a distribution upgrade and rebooted to discover that your Wi-Fi interface has disappeared or your secondary monitors are unrecognised, your out-of-tree drivers likely failed to compile during the package manager transaction. You can force DKMS to rebuild every registered driver against your currently booted kernel:
sudo dkms autoinstall
DKMS will scan your system, detect any missing modules for $(uname -r), execute compilation threads, and update your initramfs storage image automatically.
Manually Building and Installing a Specific Module
If a specific driver fails to compile automatically, you can step through the DKMS pipeline manually. Every DKMS module follows a standard three-stage lifecycle: add, build, and install.
1. Adding Module Source Code to the Tree
When driver source code is placed into /usr/src/<module>-<version>/, inform DKMS of its presence:
sudo dkms add -m r8168 -v 8.052.01
2. Compiling the Module
Compile the source code against your active kernel:
sudo dkms build -m r8168 -v 8.052.01
If compilation fails, inspect the detailed build log generated at /var/lib/dkms/r8168/8.052.01/build/make.log to identify missing compiler flags or syntax errors.
3. Installing the Compiled Binary
Once built without errors, register the binary with the kernel:
sudo dkms install -m r8168 -v 8.052.01
You can immediately load the newly compiled module into memory using modprobe:
sudo modprobe r8168
Targeting a Specific or Inactive Kernel Version
If you are preparing an upcoming kernel update before rebooting your production server, you can instruct DKMS to build a module for a target kernel rather than the currently running one using the -k switch:
sudo dkms build -m nvidia -v 550.67 -k 6.8.0-45-generic
sudo dkms install -m nvidia -v 550.67 -k 6.8.0-45-generic
This guarantees that when you restart your machine into kernel 6.8.0-45-generic, your display drivers are already compiled and ready to initialise without graphic corruption.
Removing Obsolete or Broken DKMS Modules
Old or incompatible driver versions left behind by previous software installations can cause package management conflicts during routine apt upgrade transactions. To purge an old driver version completely across all kernels, use the remove command with the --all flag:
sudo dkms remove -m r8168 -v 8.050.00 --all
Verify that the stale module has been deleted by checking dkms status once more.
Troubleshooting Common DKMS Failures
If your build fails, check the following common causes:
- Missing Matching Kernel Headers: The version of
linux-headersmust exactly matchuname -rdown to the minor patch release. If your running kernel is6.8.0-40-generic, runningapt install linux-headers-genericmight pull down a newer release, causing a mismatch. Always specifylinux-headers-$(uname -r). - Secure Boot Signature Rejection: If your motherboard has UEFI Secure Boot enabled, the Linux kernel will refuse to load newly compiled DKMS modules unless they are cryptographically signed using a Machine Owner Key (MOK). Follow distribution instructions to enroll your local MOK key with
mokutil. - GCC Compiler Mismatch: In rare cases where a custom kernel was compiled with a newer version of GCC than your default system compiler, DKMS will abort. Ensure your active GCC version matches the toolchain reported in
cat /proc/version.
Ensuring System Stability Across Kernel Upgrades
Understanding how to manage DKMS modules ensures that your critical proprietary hardware—from high-performance GPUs to enterprise network adapters—remains resilient across operating system updates. By auditing module health with dkms status and resolving compilation snags before rebooting, you eliminate unexpected boot halts and maintain uninterrupted system uptime.