Skip to content

Linux Foundations / Understand the system underneath ยท Step 25 of 38

Lesson: Kernel modulesSwitch
โ† Linux Foundations

System administration

Kernel modules

List, inspect, load and configure kernel modules safely.

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

bash
lsmod
Module                  Size  Used by
nf_tables             372736  0
e1000e                344064  0

Used 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:

bash
modinfo e1000e
filename:       /lib/modules/6.8.0-45-generic/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
license:        GPL v2
description:    Intel(R) PRO/1000 Network Driver

The output is shortened, and some distributions compress module files, so the name may end in .ko.xz or .ko.zst.

Load and unload

bash
sudo modprobe dummy
lsmod | grep dummy
sudo modprobe -r dummy

dummy 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:

bash
echo dummy | sudo tee /etc/modules-load.d/dummy.conf

Options and blacklists go in /etc/modprobe.d/:

options dummy numdummies=2
blacklist pcspkr

blacklist 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

  1. Run lsmod | head and pick a module.
  2. Run modinfo on it and read the description.
  3. On a test virtual machine, load dummy, confirm it with lsmod, then remove it.
  4. 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.