Linux Kernel Modules
Three types of kernel modules:
- Built-in Kernel Modules (Compiled into the Kernel)
- Standard Kernel Modules (Managed by modprobe and lsmod)
- DKMS Modules (Dynamic Kernel Modules)
cat /boot/config-$(uname -r) | grep module_name # check if built-in ( y is built in )
Built-in Kernel Modules (Compiled into the Kernel)
- These modules are statically compiled into the kernel itself.
- They do not appear as separate .ko (kernel object) files.
- Example: Core drivers like ext4 (filesystem) or nf_conntrack (networking).
cat /boot/config-$(uname -r) | grep CONFIG_MODULES
If CONFIG_MODULES is set to n, that module is built-in.
Standard Kernel Modules (Managed by modprobe and lsmod)
- These modules are included with the Linux kernel package.
- They reside in /lib/modules/$(uname -r)/kernel/.
- They are automatically loaded when needed.
- Example: i915 (Intel graphics), snd_hda_intel (audio driver), xfs (filesystem).
lsmod # list standard modules
modinfo module_name # detailed info on module
modinfo module_name | grep depends # check dependencies
sudo modprobe module_name # load module
sudo modprobe -r module_name # unload module, also removes dependent modules
sudo rmmod module_name # unload module
sudo modprobe -n module_name # check if module is available ( no output if availabe, error if missing )
sudo insmod /path/to/module.ko # load custom .ko file
sudo depmod -a # automatically clean up unneeded modules
sudo apt autoremove # remove orphaned modules after kernel upgrade
find /lib/modules/$(uname -r) -type f -name '*.ko*' | sed 's|.*/||; s|\.ko.*||' | sort # show all modules, loaded or not
grep -r 'blacklist' /etc/modprobe.d/ # check for blocked modules
Blacklist to prevent module from automatically loading:
sudo nano /etc/modprobe.d/blacklist.conf
blacklist module_name
sudo update-initramfs -u
Alternate method:
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash modprobe.blacklist=nouveau"
sudo update-grub
sudo reboot
Persistent Module Loading at Boot:
/etc/modules-load.d/ # add new file here:
sudo nano /etc/modules-load.d/custom_modules.conf
v4l2loopback
iwlwifi
reboot
DKMS Modules (Dynamic Kernel Modules)
- These are not part of the default kernel and need to be manually installed or compiled.
- They are stored in /usr/src/ and rebuilt automatically when the kernel updates.
- Used for third-party or proprietary drivers.
- Example: nvidia-dkms, broadcom-sta-dkms, zfs-dkms.
Common DKMS Modules
Module | Package Name | Purpose |
NVIDIA Driver | nvidia-dkms-version | NVIDIA GPU driver with DKMS support |
VirtualBox | virtualbox-dkms | Kernel support for VirtualBox guest additions |
Broadcom Wi-Fi | broadcom-sta-dkms | Broadcom wireless drivers |
Realtek Wi-Fi | rtl8821ce-dkms | Realtek wireless card drivers |
ZFS | zfs-dkms | ZFS file system support |
- DKMS (Dynamic Kernel Module Support) is a framework that automatically recompiles and reinstalls kernel modules when the kernel is updated. This ensures that custom or third-party drivers remain functional after a kernel upgrade.
Install DKMS and modules for Debian/Ubuntu/Arch :
sudo apt update
sudo apt install dkms # install DKMS ( Ubuntu )
sudo apt install virtualbox-dkms # install a DKMS module ( Ubuntu package ):
sudo apt remove broadcom-sta-dkms # remove
sudo pacman -S dkms # install DKMS ( Arch )
sudo pacman -S nvidia-dkms # install a DKMS module ( Arch package )
Manual install:
sudo cp -r mymodule-1.0 /usr/src/ # copy module
sudo dkms add -m mymodule -v 1.0 # add to DKMS
sudo dkms build -m mymodule -v 1.0 # build
sudo dkms install -m mymodule -v 1.0 # install
sudo dkms remove -m mymodule -v 1.0 --all # remove
Rebuild all after kernel update, usually not needed for kernel package install, probably needed after custom kernel build:
sudo dkms autoinstall
Commands and info:
dkms status # list DKMS managed modules that are installed
/usr/src/ # source here
/var/lib/dkms///build/ # build stuff here
/lib/modules/$(uname -r)/updates/dkms/ # binaries here
</code></pre>