Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 220System · Kernel

How to load a kernel module at boot

Kubernetes needs overlay and br_netfilter, WireGuard needs wireguard, a special network card needs an option for its driver — and a hardened server should not load usb-storage at all. Kernel modules are loaded with modprobe, made permanent with a file in /etc/modules-load.d/, configured in /etc/modprobe.d/, and blocked with a blacklist. This how-to does all four and checks the result.

  • 5 Lessen
  • 7 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

220.1

The quick answer

lsmod | grep br_netfilter
modprobe br_netfilter
printf 'overlay\nbr_netfilter\n' > /etc/modules-load.d/k8s.conf
systemctl restart systemd-modules-load
lsmod | grep -E 'overlay|br_netfilter'

220.2

Step by step

  1. Is it loaded? (line 1) — lsmod lists loaded modules. Info about a module, its options and file: modinfo br_netfilter.
  2. Load it now (line 2) — modprobe also loads modules it depends on.
  3. Load it at every boot (lines 3–4) — one module name per line in /etc/modules-load.d/NAME.conf; systemd-modules-load reads these files at boot.
  4. Module options — for example a driver parameter:
/etc/modprobe.d/bonding.conf
options bonding max_bonds=0

Options apply when the module is loaded; reload the module (modprobe -r then modprobe) or reboot.

  1. Block a module (hardening, for example no USB storage):
/etc/modprobe.d/disable-usb-storage.conf
blacklist usb-storage
install usb-storage /bin/false

blacklist stops automatic loading; the install … /bin/false line also stops a manual modprobe usb-storage.

  1. Early boot — if the module is needed before the root file system is mounted (storage drivers), rebuild the initramfs after the change: dracut -f (RHEL) or update-initramfs -u (Debian/Ubuntu).
  2. Unload — modprobe -r MODULE (fails while in use; lsmod shows the "Used by" count).

220.3

Check that it worked

After a reboot lsmod | grep -E 'overlay|br_netfilter' lists both; systemctl status systemd-modules-load shows no errors; modprobe usb-storage fails (exit code 1) on the hardened server.

220.4

Common problems

ProblemCauseFix
Module X not found in directory /lib/modules/…Not built for this kernel, or kernel updated without reboot.Install the module package for the running kernel; reboot after kernel updates.
Module not loaded after rebootFile not ending in .conf, or a typo.systemctl status systemd-modules-load; fix the name.
Key was rejected by serviceSecure Boot blocks an unsigned module.Use signed modules (distribution packages) or enroll your key.
Blacklisted module still loadsAnother module depends on it, or loaded from the initramfs.Add install … /bin/false; rebuild the initramfs.
Options ignoredModule was already loaded.Reload the module or reboot.
modprobe: FATAL: … in useSomething uses the module.Stop the user (interface, mount) first.

220.5

Go further

1Where do you list modules that must load at every boot?

In a .conf file in /etc/modules-load.d/, one module name per line.

2Why add install MODULE /bin/false besides blacklist?

blacklist only stops automatic loading; the install line also blocks loading by hand or as a dependency.

Alle commando's in dit hoofdstuk