How To Install DKMS on Fedora 42
Dynamic Kernel Module Support, commonly known as DKMS, is an essential framework for Linux users who need to maintain kernel modules across system updates. Originally developed by Dell, DKMS has become a critical tool for ensuring hardware compatibility and driver persistence through kernel upgrades on Linux distributions. For Fedora 42 users, understanding how to properly install and configure DKMS is particularly important as the distribution continues to evolve with frequent kernel updates.
This comprehensive guide will walk you through the installation process of DKMS on Fedora 42, explain its functionality, compare it with Fedora’s native akmods system, and provide detailed instructions for common use cases. Whether you’re dealing with proprietary hardware drivers or custom kernel modules, this guide will help you maintain them seamlessly across kernel updates.
Understanding DKMS (Dynamic Kernel Module Support)
DKMS serves as a framework that allows kernel modules to be automatically rebuilt when a new kernel is installed. This solves a common problem in Linux environments where kernel modules need to be reinstalled or reconfigured after system updates.
The primary purpose of DKMS is to maintain functionality of hardware drivers and other kernel modules that aren’t included in the mainline kernel. When you update your kernel, DKMS automatically rebuilds and installs these modules for the new kernel version, ensuring your hardware continues to function properly without manual intervention.
DKMS is particularly useful for:
- Proprietary hardware drivers (like NVIDIA graphics cards)
- Custom-built kernel modules
- Third-party drivers not included in the kernel
- Experimental or testing modules
The framework works by storing the source code of kernel modules and rebuilding them automatically when a new kernel is detected. This approach ensures that your system remains functional after kernel updates without requiring manual reinstallation of drivers.
DKMS vs. Akmods: Understanding Fedora’s Kernel Module Management
Fedora Linux, including Fedora 42, comes with a native kernel module management system called akmods. Understanding the differences between DKMS and akmods helps you make an informed decision about which to use for your specific needs.
Akmods (Automatic Kernel Module System):
- Developed specifically for Fedora and Red Hat-based distributions
- Builds modules at boot time rather than during kernel installation
- Works well for most standard Fedora configurations
- Integrates well with Fedora’s package management system
DKMS:
- Distribution-agnostic solution that works across many Linux distributions
- Builds modules immediately during kernel installation
- More configurable and flexible for complex setups
- Better suited for custom modules and certain proprietary drivers
While akmods works well for most Fedora users, DKMS provides additional flexibility and control. You can use both systems simultaneously on Fedora 42, though this requires careful configuration to avoid conflicts.
For users working with custom hardware drivers or specific proprietary software like NVIDIA drivers, DKMS often provides a more reliable solution, especially when dealing with frequent kernel updates.
Prerequisites for Installing DKMS on Fedora 42
Before installing DKMS on your Fedora 42 system, ensure that you have the following prerequisites in place:
- Administrator Privileges: You need sudo or root access to install packages and modify system configurations.
- Updated System: Make sure your Fedora 42 system is fully updated. Run:
sudo dnf update
- Essential Packages: Several development packages are required for DKMS to function properly. These include:
- Kernel headers
- Development tools
- Compilers
- Build utilities
- Backup Important Data: As with any system modification, it’s wise to back up important data before proceeding.
- Check Current Kernel Version: Know your current kernel version by running:
uname -r
This information will be helpful during the installation and configuration process.
Basic DKMS Installation on Fedora 42
Installing DKMS on Fedora 42 is straightforward using the DNF package manager. Follow these steps for a basic installation:
- Install Required Dependencies:
sudo dnf install kernel-devel kernel-headers gcc make perl
This command installs the kernel development headers, GCC compiler, Make build tool, and Perl, which are all required by DKMS.
- Install DKMS Package:
sudo dnf install dkms
The DNF package manager will download and install the DKMS package (version 3.1.7-2.fc42 in Fedora 42) and its dependencies.
- Verify Installation:
dkms --version
This command confirms that DKMS has been installed correctly and displays the installed version.
- Enable DKMS Service:
sudo systemctl enable dkms
This ensures that DKMS runs automatically during system startup and kernel updates.
- Check DKMS Status:
sudo systemctl status dkms
Verify that the DKMS service is active and properly configured.
With these steps completed, you have successfully installed DKMS on your Fedora 42 system. The next sections will cover more advanced configuration and usage scenarios.
Understanding the DKMS Directory Structure
To work effectively with DKMS, it’s important to understand its directory structure and how it organizes kernel modules. The main directories used by DKMS include:
- /usr/src/: The primary location where module source code is stored. Each module should have its own directory named according to the format
<module>-<version>
. - /var/lib/dkms/: Contains the DKMS database and built modules organized by module name, version, and kernel version.
- /etc/dkms/: Contains global configuration files for DKMS behavior.
- /lib/modules/<kernel-version>/updates/dkms/: Where DKMS installs the built modules for each kernel version.
The core of DKMS functionality revolves around the dkms.conf file, which must be present in each module’s source directory. This file contains instructions for building and installing the module, including:
- Module name and version
- Build commands
- Installation paths
- Dependencies
- Special build options
Understanding this structure helps you troubleshoot issues and configure DKMS for custom modules.
Working with DKMS Tarballs
DKMS provides powerful functionality for working with packaged modules in tarball format. These tarballs contain the necessary files for DKMS to build and install modules across kernel updates.
Types of DKMS Tarballs
DKMS works with several types of tarballs:
- Generic module source tarballs: These contain module source code and a dkms.conf file.
- Specially created DKMS tarballs: These include module source, pre-built module binaries, and a dkms.conf file.
- Source-less tarballs: These contain only pre-built module binaries and a dkms.conf file.
Loading Tarballs into DKMS
To load a tarball into the DKMS tree, use the ldtarball command:
sudo dkms ldtarball /path/to/dkms_enabled.tar.gz
This command examines the tarball to ensure it contains a valid dkms.conf file. If found, it extracts the contents to /usr/src/<module>-<moduleversion>/
. If the tarball contains pre-built binaries, they are placed in the “built” state but not automatically installed.
Creating DKMS Tarballs
You can create your own DKMS tarballs using the mktarball command:
sudo dkms mktarball -m <module> -v <version>
To create a binary-only tarball (type 3), add the --binaries-only
flag:
sudo dkms mktarball -m <module> -v <version> --binaries-only
These tarballs can be distributed to other systems, making it easier to deploy the same kernel modules across multiple machines.
Installing NVIDIA Drivers with DKMS on Fedora 42
One of the most common use cases for DKMS on Fedora 42 is installing and maintaining NVIDIA proprietary drivers. The following steps will guide you through this process:
Preparing Your System
- Check Your GPU Model:
lspci | grep -i nvidia
Identify your NVIDIA GPU model to determine the appropriate driver version.
- Install Required Dependencies:
sudo dnf install gcc14 kernel-devel kernel-headers
Note that Fedora 42 uses GCC 15.x by default, but NVIDIA drivers are currently compatible with GCC 14.x, so we install that specifically.
- Disable Nouveau Driver:
Create a file at/etc/modprobe.d/blacklist-nouveau.conf
with the following content:blacklist nouveau options nouveau modeset=0
- Update Initial RAM Disk:
sudo dracut --force
Downloading and Installing the NVIDIA Driver
- Download the Driver:
wget https://us.download.nvidia.com/XFree86-x86_64/570.144/NVIDIA-Linux-x86_64-570.144.run
- Make the Installer Executable:
chmod +x NVIDIA-Linux-x86_64-570.144.run
- Switch to a Text Console:
PressCtrl+Alt+F2
to switch to a text console. - Stop the Display Server:
sudo systemctl isolate multi-user.target
- Install the Driver with DKMS Support:
sudo ./NVIDIA-Linux-x86_64-570.144.run --dkms
The
--dkms
flag tells the installer to register the NVIDIA kernel module with DKMS. - Return to Graphical Interface:
sudo systemctl isolate graphical.target
- Verify Installation:
nvidia-smi
This command should display information about your NVIDIA GPU and driver.
- Check DKMS Status for NVIDIA Modules:
dkms status
You should see the NVIDIA modules listed with your current kernel version.
This setup ensures that your NVIDIA drivers will be automatically rebuilt whenever you update your kernel.
Installing Custom Hardware Drivers Using DKMS
Beyond NVIDIA drivers, DKMS is useful for maintaining various custom hardware drivers across kernel updates. Here’s how to configure a custom driver with DKMS:
Setting Up the Directory Structure
- Create the Module Source Directory:
sudo mkdir -p /usr/src/mymodule-1.0
Replace “mymodule” with your module name and “1.0” with its version.
- Copy Module Source:
sudo cp -r /path/to/module/source/* /usr/src/mymodule-1.0/
Creating the DKMS Configuration File
- Create dkms.conf:
Create a file at/usr/src/mymodule-1.0/dkms.conf
with content similar to:PACKAGE_NAME="mymodule" PACKAGE_VERSION="1.0" MAKE="make -C src/" CLEAN="make -C src/ clean" BUILT_MODULE_NAME[0]="mymodule" DEST_MODULE_LOCATION[0]="/kernel/drivers/misc" AUTOINSTALL="yes"
- Adjust the Configuration:
Modify the MAKE, CLEAN, BUILT_MODULE_NAME, and DEST_MODULE_LOCATION values according to your module’s specific requirements.
Registering and Building with DKMS
- Register the Module with DKMS:
sudo dkms add -m mymodule -v 1.0
- Build the Module:
sudo dkms build -m mymodule -v 1.0
- Install the Module:
sudo dkms install -m mymodule -v 1.0
- Load the Module:
sudo modprobe mymodule
- Verify Module Loading:
lsmod | grep mymodule
This process registers your custom module with DKMS, ensuring it’s automatically rebuilt and installed whenever your kernel is updated.
DKMS Command Reference and Usage
Understanding the core DKMS commands is essential for effectively managing kernel modules. Here are the most important commands and their usage:
Essential DKMS Commands
dkms add: Adds a module to the DKMS tree
sudo dkms add -m <module> -v <version>
dkms build: Builds a module for the current kernel
sudo dkms build -m <module> -v <version>
dkms install: Installs a built module
sudo dkms install -m <module> -v <version>
dkms status: Shows the status of all DKMS-managed modules
dkms status
dkms remove: Removes a module from DKMS management
sudo dkms remove -m <module> -v <version> --all
dkms autoinstall: Builds and installs all modules for all kernels
sudo dkms autoinstall
dkms ldtarball: Loads a DKMS-enabled tarball
sudo dkms ldtarball /path/to/dkms_enabled.tar.gz
dkms mktarball: Creates a DKMS-enabled tarball
sudo dkms mktarball -m <module> -v <version>
Most commands accept additional options that modify their behavior, such as --force
to override safety checks or --all
to apply the operation to all module versions.
Troubleshooting Common DKMS Issues on Fedora 42
DKMS is generally reliable, but issues can occur, especially when dealing with kernel updates or module compatibility. Here are solutions for common problems:
Failed Module Builds
If a module fails to build with DKMS, check the build log:
cat /var/lib/dkms/<module>/<version>/build/make.log
Common causes include:
- Missing dependencies: Install required development packages.
- Compiler version mismatch: Some modules require specific compiler versions. For example, NVIDIA drivers on Fedora 42 require GCC 14.x while the system defaults to GCC 15.x.
- Module incompatibility with kernel version: Check if the module supports your current kernel version.
Kernel Header Missing Errors
If DKMS complains about missing kernel headers:
sudo dnf install kernel-devel-$(uname -r)
This installs headers specifically for your running kernel.
Module Version Mismatches
When DKMS warns about differences between built and installed modules:
sudo dkms install -m <module> -v <version> -k $(uname -r) --force
This forces reinstallation of the module for your current kernel.
Problems After Kernel Updates
If modules aren’t automatically rebuilding after kernel updates:
- Check the DKMS service status:
sudo systemctl status dkms
- Manually trigger a rebuild:
sudo dkms autoinstall
- Verify that the AUTOINSTALL parameter is set to “yes” in your dkms.conf file.
DKMS Configuration File Errors
If DKMS fails due to configuration errors:
- Check the syntax of your dkms.conf file
- Ensure all required variables are defined
- Verify paths and commands in the configuration file
For persistent issues, examining the DKMS logs in /var/lib/dkms/<module>/<version>/
can provide valuable diagnostic information.
Advanced DKMS Usage Scenarios
Beyond basic installations, DKMS supports several advanced scenarios that can be useful for system administrators and power users.
Using DKMS on Systems Without Compilers
You can use DKMS with pre-built binary modules on systems that don’t have compilers installed:
- Build the modules on a development system with the same kernel
- Create a binary-only tarball:
sudo dkms mktarball -m <module> -v <version> --binaries-only
- Transfer the tarball to the target system
- Load it with:
sudo dkms ldtarball /path/to/tarball.tar.gz
- Install the pre-built modules:
sudo dkms install -m <module> -v <version>
Automating DKMS with Scripts
You can create scripts to automate DKMS operations, especially useful for system deployment:
#!/bin/bash
# Example script to manage DKMS modules
# Install dependencies
dnf install -y dkms kernel-devel gcc make
# Download module source
wget -O /tmp/module.tar.gz http://example.com/module.tar.gz
# Load into DKMS
dkms ldtarball /tmp/module.tar.gz
# Build and install
dkms install -m mymodule -v 1.0
# Verify installation
dkms status
Integration with System Update Processes
To better integrate DKMS with your system update workflow:
- Create a post-update hook in
/etc/dnf/plugins/post-transaction-actions.d/dkms.action
:kernel-core:update:dkms autoinstall
- This ensures that DKMS rebuilds modules whenever the kernel is updated.
Best Practices for DKMS Management
To maintain a healthy system with DKMS-managed modules, follow these best practices:
Regular Maintenance
- Clean up old modules regularly:
sudo dkms remove -m <module> -v <version> --all
This removes modules that are no longer needed.
- Keep an eye on DKMS status:
dkms status
Regularly check the status of DKMS modules to identify potential issues.
- Update module sources:
Keep module sources updated to ensure compatibility with newer kernels.
Security Considerations
- Only install trusted modules: DKMS modules have kernel-level access, so only install modules from trusted sources.
- Sign modules for Secure Boot:
If using Secure Boot, ensure your modules are signed:sudo dkms sign -m <module> -v <version> -k <kernel>
- Maintain backups of working modules:
sudo dkms mktarball -m <module> -v <version>
Create backups of working modules before updates.
Congratulations! You have successfully installed DKMS. Thanks for using this tutorial for installing the DKMS (Dynamic Kernel Module Support) on your Fedora 42 Linux system. For additional help or useful information, we recommend you check the official DKMS website.