Kernel Modules

Kernel module inspection, loading, blacklisting, parameter tuning, and DKMS for out-of-tree modules.

Module Inventory

List all loaded kernel modules — sorted by size for quick audit
lsmod | sort -k2 -rn | head -20
Count loaded modules — baseline for security auditing
lsmod | awk 'NR>1' | wc -l
Show module dependency tree — what a module pulls in
modinfo -F depends btrfs
List all available modules on the system — installed, not necessarily loaded
find /lib/modules/$(uname -r) -name '*.ko*' | wc -l

Module Information

Full module details — filename, description, author, parameters, alias
modinfo btrfs
Show only module parameters — tunables available at load time
modinfo -F parm snd_hda_intel
Show module file path — where the .ko lives on disk
modinfo -F filename btrfs
Check current parameter values for a loaded module
systool -v -m snd_hda_intel | awk '/Parameters/,/^$/'
systool is in the sysfsutils package on Arch.

Loading and Unloading

Load a module with dependencies — standard method
sudo modprobe vfio-pci
Load with parameters — set tunables at load time
sudo modprobe snd_hda_intel power_save=1 power_save_controller=Y
Unload a module and its unused dependencies
sudo modprobe -r vfio-pci
Dry-run module load — show what would happen without doing it
sudo modprobe -n -v vfio-pci
Rebuild module dependency database — after manually adding modules
sudo depmod -a

Module Location and Structure

Module directory for the running kernel
ls /lib/modules/$(uname -r)/
Find all modules in a category — e.g., network drivers
find /lib/modules/$(uname -r)/kernel/drivers/net -name '*.ko*' | head -20
Find which module provides support for specific hardware
lspci -k | awk '/Kernel driver|Kernel modules/'
Find the module for a specific device — PCI device to driver mapping
lspci -v -s $(lspci | awk '/Ethernet/{print $1}') | awk '/driver|module/'

Blacklisting

Blacklist a module — prevent auto-loading but allow manual modprobe
echo 'blacklist pcspkr' | sudo tee /etc/modprobe.d/blacklist-pcspkr.conf
Hard blacklist — prevent both auto and manual loading
printf 'blacklist nouveau\ninstall nouveau /bin/false\n' | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
Check if a module is blacklisted — search all modprobe.d configs
grep -r 'blacklist' /etc/modprobe.d/
Verify blacklist is effective — module should not appear
sudo modprobe nouveau 2>&1 ; lsmod | awk '/nouveau/'

DKMS — Dynamic Kernel Module Support

List DKMS-managed modules — status across kernel versions
dkms status
Build a DKMS module for the current kernel
sudo dkms build -m <module-name> -v <version>
Install a DKMS module after building
sudo dkms install -m <module-name> -v <version>
Remove a DKMS module — all versions for all kernels
sudo dkms remove -m <module-name> -v <version> --all
DKMS automatically rebuilds modules when a new kernel is installed, provided the dkms package hook is active.

Persistent Module Loading

Load module at every boot — systemd modules-load.d
echo 'br_netfilter' | sudo tee /etc/modules-load.d/br_netfilter.conf
Load module with parameters at every boot — combine modules-load.d + modprobe.d
echo 'snd_hda_intel' | sudo tee /etc/modules-load.d/snd-hda-intel.conf
echo 'options snd_hda_intel power_save=1' | sudo tee /etc/modprobe.d/snd-hda-intel.conf
Verify module auto-loads after reboot — check before and after
lsmod | awk '/br_netfilter/'

Hardware-to-Module Mapping

Find which module a USB device uses
lsusb -t
Find module for block device — useful for storage driver identification
udevadm info --query=all --name=/dev/sda | awk '/DRIVER/'
List all hardware with assigned kernel modules
lspci -k 2>/dev/null | awk '/^[0-9]/{dev=$0} /Kernel (driver|modules)/{print dev; print}'

RHCSA Patterns

Full workflow — blacklist, persist alternative, verify
# Blacklist the unwanted module
printf 'blacklist nouveau\ninstall nouveau /bin/false\n' | sudo tee /etc/modprobe.d/blacklist-nouveau.conf

# Rebuild initramfs to apply at boot
sudo mkinitcpio -P

# Verify after reboot
lsmod | awk '/nouveau/'
Load module with parameters persistently — three-file pattern
echo 'vfio-pci' | sudo tee /etc/modules-load.d/vfio-pci.conf
echo 'options vfio-pci ids=10de:1234,10de:5678' | sudo tee /etc/modprobe.d/vfio-pci.conf
sudo mkinitcpio -P

See Also

  • Kernel — the kernel these modules extend