Where to start First steps track · 15 stages
Linux Labs

Kernel modules

4 min Ubuntu 24.04

Kernel modules: loading and unloading with modprobe, kernel messages in dmesg, module parameters.

Cheat sheet

7 commands Printable version
  • uname -r kernel version
  • lsmod loaded modules
  • sudo modprobe nf_tables load a module
  • sudo modprobe -r nf_tables unload a module
  • modinfo nf_tables info about a module
  • dmesg -T kernel messages with readable timestamps
  • journalctl -k | grep -i oom OOM-killer

Overview

Kernel modules are loadable drivers and subsystems (networking, filesystems, hardware). Most load automatically when a device is detected.

bash
uname -r                          # kernel version
lsmod                             # loaded modules (name, size, used by)
dmesg | tail                      # kernel messages (or journalctl -k)

Recipes

3

Commands

bash
sudo modprobe nf_tables           # load a module (with its dependencies)
sudo modprobe -r nf_tables        # unload it (-r, if unused)
sudo modprobe overlay dm_mod      # several at once
modinfo nf_tables                 # info: path, parameters, dependencies, alias
modinfo -p i915                   # a module's available PARAMETERS
lsmod | grep nf_                  # what's loaded
sudo depmod -a                    # rebuild the dependency map (after a manual install)

# module parameters at load time:
sudo modprobe usbcore autosuspend=-1
# permanently — /etc/modprobe.d/*.conf:
echo 'options i915 enable_psr=0' | sudo tee /etc/modprobe.d/i915.conf

Autoload and blacklist

bash
# load at boot:
echo nf_tables | sudo tee /etc/modules-load.d/nft.conf

# blacklist:
echo 'blacklist pcspkr' | sudo tee /etc/modprobe.d/no-beep.conf
sudo update-initramfs -u          # if the module loads from initramfs — rebuild it
# hard block from the kernel cmdline: module_blacklist=nouveau (in GRUB_CMDLINE, see boot-grub)

dmesg / kernel messages

bash
sudo dmesg -T | grep -i <module>  # what the module wrote at load time
sudo journalctl -k -b -1          # the kernel of the previous boot

This is where driver and hardware problems show up. The kernel buffer, message levels, root-only access and common lines are covered in dmesg.

Troubleshooting

5

A device/driver isn't working

dmesg | grep -i <device> for initialization errors. lsmod to see whether the module is loaded; sudo modprobe <module> to load it manually; modinfo for the needed parameters/firmware.

The OOM-killer killed a process

dmesg -T | grep -i oom or journalctl -k | grep -i oom — the kernel killed a process under memory pressure (see oom-killer).

A module doesn't load at boot

Add it to /etc/modules-load.d/*.conf; check modinfo and dependencies (depmod -a). If it loads from initramfs — run update-initramfs -u.

modprobe -r: "Module is in use"

Something is using the module (lsmod's "Used by" column). Stop the consumer, or unload dependent modules first.

The disk is throwing I/O errors

dmesg showing "I/O error, dev sdX" is a sign of a failing disk; check SMART (smartctl -a) and make a backup (see filesystems).

See also

  • boot-grub — Boot stages, GRUB, systemd targets, emergency recovery mode.
  • journalctl — Reading the systemd journal (journald) — filters by service, time, priority.
Loading…