A kernel module is code that can be added to a running kernel, often a device driver or a filesystem. This keeps the base kernel smaller and avoids a reboot when support is needed.
Most modules load automatically when the kernel detects matching hardware.
See what is loaded
lsmodModule Size Used by
nf_tables 372736 0
e1000e 344064 0Used by shows a use count and, where relevant, which modules depend on this one. Features built into the kernel do not appear.
For details about one module:
modinfo e1000efilename: /lib/modules/6.8.0-45-generic/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
license: GPL v2
description: Intel(R) PRO/1000 Network DriverThe output is shortened, and some distributions compress module files, so the name may end in .ko.xz or .ko.zst.
Load and unload
sudo modprobe dummy
lsmod | grep dummy
sudo modprobe -r dummydummy is a virtual network driver that is convenient for practice. modprobe finds the module by name and loads its dependencies first. modprobe -r removes it, and can also remove dependencies that are no longer used.
The older insmod takes a file path and does not resolve dependencies. rmmod removes a single module. Prefer modprobe.
Removing a driver that is in use may be refused. Removing the one for your network card or disk can cut you off, so practise on a test machine.
Make settings persist
A module loaded with modprobe is gone after a reboot. On systemd based systems, list a module name in a file to load it at every boot:
echo dummy | sudo tee /etc/modules-load.d/dummy.confOptions and blacklists go in /etc/modprobe.d/:
options dummy numdummies=2
blacklist pcspkrblacklist stops a module being loaded automatically through its hardware aliases. It does not stop you loading it by name, or another module pulling it in as a dependency. If the module is included in the initramfs, you may need to rebuild that too.
Modules are built for a particular kernel. Third party drivers must be rebuilt after updates, which tools such as DKMS can automate. With Secure Boot enabled, the system may refuse unsigned modules.
Module files are part of the system layout covered in the packages and filesystem lab.
Try it
- Run
lsmod | headand pick a module. - Run
modinfoon it and read the description. - On a test virtual machine, load
dummy, confirm it withlsmod, then remove it. - Look in
/etc/modprobe.d/to see existing settings.
Check your understanding
Kernel modules
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.