7.4. Configuring the Initramfs and Drivers

The initramfs is a small, self-contained environment that the boot loader loads next to the kernel. It must contain enough drivers and tools to find, decrypt, assemble, and mount the root filesystem, and it may contain firmware and microcode that must be applied before the root filesystem is available. The installed module tree and the initramfs share the same modules, but they are separate copies: adding a module to /lib/modules does not put it into the initramfs, and rebuilding the initramfs does not install a module into the running system. Figure 7.3 shows the runtime path from a device to a driver and the build path used by DKMS.

Module loading, firmware, and DKMS paths

Figure 7.3. Runtime loading goes from a device through udev and modprobe to a module in /lib/modules; DKMS builds and signs a module from a source directory under /usr/src. Firmware and microcode follow separate data paths into /lib/firmware and the initramfs.

7.4.1. Rebuilding Initramfs Images After Storage Changes

Each installed kernel has an initramfs under /boot. The files are large because they carry the module tree and the early userland:

$ ls -l /boot/initrd.img-*
-rw-r--r-- 1 root root 55503992 Nov 19 03:39 /boot/initrd.img-6.12.117+deb13-amd64
-rw-r--r-- 1 root root 55150107 Nov 19 03:35 /boot/initrd.img-6.12.86+deb13-amd64

The generator's policy is controlled by /etc/initramfs-tools/initramfs.conf. The effective settings, with comments removed, are:

$ grep -vE "^[[:space:]]*(#|$)" /etc/initramfs-tools/initramfs.conf
MODULES=most
BUSYBOX=auto
KEYMAP=n
COMPRESS=zstd
DEVICE=
NFSROOT=auto
RUNSIZE=10%
FSTYPE=auto

MODULES=most includes a broad set of storage, filesystem, and device drivers; MODULES=dep tries to include only what the running system needs, producing a smaller image; MODULES=list adds no extra modules beyond those named in /etc/initramfs-tools/modules. COMPRESS=zstd selects the compression algorithm. FSTYPE=auto detects the root filesystem type. DEVICE names the default network interface for an NFS boot, NFSROOT=auto obtains the NFS root from DHCP, and ROOT can hardcode a root= value when one cannot be passed on the kernel command line. Table 7.9 summarizes the choices. A machine with unusual storage (LVM, encrypted root, RAID, or a network root) should stay with most unless the smaller image has been tested.

Setting Effect
MODULES=most Include a broad set of filesystem, ATA/SATA/SCSI, and USB drivers; safest for unfamiliar or layered storage.
MODULES=dep Try to include only modules needed by the running system; smaller and less tolerant of hardware changes.
MODULES=list Add no extra modules beyond those listed in /etc/initramfs-tools/modules.
COMPRESS=zstd Compress the image with zstd; other supported compressors can be selected.
FSTYPE=auto Detect the root filesystem type, or name types explicitly for an unusual root.
DEVICE=eth0 Default network interface for an NFS boot; ip or BOOTIF can override it.
NFSROOT=auto Obtain the NFS root from DHCP, or specify HOST:MOUNT.
ROOT= Hardcode a root= value for boot when one cannot be passed; a kernel root= overrides it.

To add a module that is not already included, append its name to /etc/initramfs-tools/modules. The file is a list, one module per line; comments begin with #. This example adds the harmless dummy network driver so its presence can be verified:

# printf "dummy\n" | tee -a /etc/initramfs-tools/modules
dummy

tee -a appends and also prints the line. Rebuild the initramfs for every installed kernel:

# update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-6.12.117+deb13-amd64
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64

-u updates an existing image, and -k all selects every installed kernel rather than only the running one. Rebuilding all kernels is the right default after a storage change because the fallback kernel may be the one that has to boot. The new image now contains the module:

# lsinitramfs /boot/initrd.img-$(uname -r) | grep dummy.ko
usr/lib/modules/6.12.117+deb13-amd64/kernel/drivers/net/dummy.ko.xz

Remove the practice module and rebuild again to leave the image in its original state:

# sed -i "/^dummy$/d" /etc/initramfs-tools/modules

The command is silent. Then:

# update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-6.12.117+deb13-amd64
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64

A count confirms that the module is gone; grep -c exits 1 when the count is zero:

# lsinitramfs /boot/initrd.img-$(uname -r) | grep -c dummy.ko
0

Rebuild the initramfs after any of these changes: a new storage driver or filesystem, a change to /etc/crypttab, a new LVM or RAID configuration, a change to the root device's UUID, a firmware file needed before / is mounted, or an update to the microcode package. The package maintainer scripts for initramfs-tools, linux-image-*, mdadm, cryptsetup, and intel-microcode trigger a rebuild automatically, but a local configuration change that bypasses those triggers needs an explicit run. Table 7.10 lists the useful update-initramfs options.

Option Description
-u Update an existing initramfs.
-c Create a new initramfs.
-d Delete an existing initramfs; use with care.
-k VERSION Act on one kernel version; all selects every installed kernel that already has an image.
-b DIRECTORY Use a different boot directory.
-s TIMESTAMP Update only if the image is not newer than the given Unix timestamp.
-v Be verbose.

The initramfs is a single point of failure. Keep the previous image and a working kernel until the new one has booted. Do not delete files in /boot by hand; remove a kernel with the package manager so that GRUB, the module tree, and the initramfs are updated together. If a rebuild fails, fix the cause before rebooting, or boot the previous kernel and repair from there.

7.4.2. Module Loading, Module Options, and Blacklisting

Drivers are usually loaded on demand: the kernel exposes a device ID, udev matches it against the module aliases, and modprobe loads the right module. Administrators can also load a module explicitly to test it. Table 7.11 lists the modprobe options used in this section. The dummy network driver is a safe example because it creates only virtual interfaces and touches no hardware:

Option Description
-r / --remove Remove a module (and its unused dependencies).
-n / --dry-run Print what would be done without doing it.
-v / --verbose Show the commands being executed.
-b / --use-blacklist Apply blacklist entries to named modules (used by udev).
-c / --showconfig Print the effective configuration and exit.
--show-depends Print the module and its dependencies without loading.
module option=value Load a module with a temporary parameter.
# modprobe dummy numdummies=2

The command is silent. The option numdummies=2 asks the module to create two interfaces at load time:

$ ip -br link show type dummy
dummy0           DOWN           72:17:a8:64:cf:e3 <BROADCAST,NOARP> 
dummy1           DOWN           d6:68:e6:a4:01:d1 <BROADCAST,NOARP> 

ip -br link prints one line per interface; type dummy filters the list to the virtual devices created by the module. Unload the module to start the next part from a clean state:

# modprobe -r dummy

The command is silent. Module options can be made persistent by writing a file under /etc/modprobe.d. The filename matters because the files are read in lexical order and a later matching line wins. This image's /usr/lib/modprobe.d/systemd.conf sets dummy to numdummies=0, so the practice file uses a zz- prefix to sort after it:

# printf "%s\n" "options dummy numdummies=2" | tee /etc/modprobe.d/zz-handbook-dummy.conf
options dummy numdummies=2

The next load uses the option without a command-line argument:

# modprobe dummy

The command is silent, and the interfaces are present again:

$ ip -br link show type dummy
dummy0           DOWN           72:17:a8:64:cf:e3 <BROADCAST,NOARP> 
dummy1           DOWN           d6:68:e6:a4:01:d1 <BROADCAST,NOARP> 

A module can be prevented from loading automatically in two different ways. A blacklist line suppresses alias-based automatic loading, but it does not prevent an explicit modprobe; this is a common source of confusion. Write the line:

# printf "%s\n" "blacklist dummy" | tee /etc/modprobe.d/zz-handbook-dummy.conf
blacklist dummy

A dry run still shows the module being inserted, because the request named it explicitly:

# modprobe -n -v dummy
insmod /lib/modules/6.12.117+deb13-amd64/kernel/drivers/net/dummy.ko.xz numdummies=0 

The numdummies=0 in the dry run comes from the earlier systemd configuration file, not from the blacklist; the -n option prints the command instead of running it, and -v makes the resolution visible. To block the module outright, replace the blacklist entry with an install rule that runs a command instead of loading it:

# printf "%s\n" "install dummy /bin/false" | tee /etc/modprobe.d/zz-handbook-dummy.conf
install dummy /bin/false

Now the load fails:

# modprobe dummy
modprobe: ERROR: Error running install command '/bin/false' for module dummy: retcode 1
modprobe: ERROR: could not insert 'dummy': Invalid argument

The exit status is 1 and the module is not loaded. Remove the practice file:

# rm -f /etc/modprobe.d/zz-handbook-dummy.conf

The command is silent. Table 7.12 compares the ways to keep a module out of the running system. The right choice depends on whether the goal is to stop automatic probing, to prevent all loads, or to test a boot without a driver.

Method Scope and effect
blacklist module Stops alias-based automatic loading; an explicit modprobe can still load it.
install module /bin/false Blocks all loads of that module; the load command fails.
modprobe.blacklist=module on the kernel command line Blacklists the module for one boot; does not edit the installed configuration.
Removing the module package Removes the module file; other packages may depend on it.
Booting a kernel without the driver A fallback kernel or a kernel built without the driver; the most disruptive choice.

The modprobe.d directory is also where soft dependencies and install-time commands belong. softdep orders modules that need each other without a hard dependency; install is a general hook and should be used carefully because it runs for every load. A malformed file in /etc/modprobe.d can make a storage module fail to load at boot, so test changes in a running system before rebooting and keep a fallback kernel.

7.4.3. Firmware Packages and CPU Microcode

Firmware is data that a driver loads into a device; it is not a kernel module. Many Wi-Fi adapters, GPUs, and storage controllers need a firmware file before they can operate. Debian separates firmware that is free software from firmware that is not, and the package component reflects that:

$ apt-cache policy firmware-linux-free firmware-iwlwifi intel-microcode
firmware-linux-free:
  Installed: (none)
  Candidate: 20241210-2
  Version table:
     20241210-2 500
        500 https://deb.debian.org/debian trixie/main amd64 Packages
firmware-iwlwifi:
  Installed: (none)
  Candidate: (none)
  Version table:
intel-microcode:
  Installed: (none)
  Candidate: (none)
  Version table:

firmware-linux-free is in main and has a candidate. firmware-iwlwifi and intel-microcode have no candidate because the non-free-firmware component is not enabled in the current sources. If the sources already include that component, no change is needed. Otherwise add a deb822 source file for it; this example keeps the existing main entry untouched and adds only the missing component:

$ sudo tee /etc/apt/sources.list.d/handbook-nonfree.sources <<"EOF"
Types: deb
URIs: https://deb.debian.org/debian
Suites: trixie
Components: non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
Types: deb
URIs: https://deb.debian.org/debian
Suites: trixie
Components: non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Refresh the indexes and check the candidates again:

# apt-get update
Hit:1 https://deb.debian.org/debian trixie InRelease
Hit:2 https://deb.debian.org/debian trixie-updates InRelease
Hit:3 https://security.debian.org/debian-security trixie-security InRelease
Hit:4 https://deb.debian.org/debian trixie-backports InRelease
Get:5 https://deb.debian.org/debian trixie/non-free-firmware amd64 Packages [6884 B]
Get:6 https://deb.debian.org/debian trixie/non-free-firmware Translation-en [4704 B]
Fetched 11.6 kB in 1s (19.1 kB/s)
Reading package lists...

The component is now available:

$ apt-cache policy firmware-iwlwifi intel-microcode
firmware-iwlwifi:
  Installed: (none)
  Candidate: 20250410-2
  Version table:
     20250410-2 500
        500 https://deb.debian.org/debian trixie/non-free-firmware amd64 Packages
intel-microcode:
  Installed: (none)
  Candidate: 3.20251111.1~deb13u1
  Version table:
     3.20251111.1~deb13u1 500
        500 https://deb.debian.org/debian trixie/non-free-firmware amd64 Packages

Install the free firmware package and inspect where its files land:

# apt-get install firmware-linux-free
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  firmware-ath9k-htc firmware-carl9170
The following NEW packages will be installed:
  firmware-ath9k-htc firmware-carl9170 firmware-linux-free
0 upgraded, 3 newly installed, 0 to remove and 29 not upgraded.
Need to get 0 B/78.2 kB of archives.
After this operation, 300 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

The output after the confirmation prompt is omitted; the package installs its files under /usr/lib/firmware, which is the same directory as /lib/firmware on this system:

$ dpkg -L firmware-linux-free | sed -n "1,12p"
/.
/usr
/usr/lib
/usr/lib/firmware
/usr/lib/firmware/av7110
/usr/lib/firmware/av7110/bootcode.bin
/usr/lib/firmware/cis
/usr/lib/firmware/cis/3CCFEM556.cis
/usr/lib/firmware/cis/3CXEM556.cis
/usr/lib/firmware/cis/COMpad2.cis
/usr/lib/firmware/cis/COMpad4.cis
/usr/lib/firmware/cis/DP83903.cis

A driver looks for its firmware by name under /lib/firmware (or the /usr/lib/firmware path it resolves to). If the file is missing, the kernel log names the file the driver requested. Reading that log needs root on a default installation: Debian's kernel sets kernel.dmesg_restrict to 1, so an ordinary dmesg fails with Operation not permitted, and an ordinary journalctl -k prints a hint about the adm and systemd-journal groups rather than any kernel message. Run journalctl -k | grep -i firmware or dmesg | grep -i firmware from the root shell. Installing a firmware package is not the same as loading it: the device must bind its driver and the driver must request the file. A virtual machine with no emulated Wi-Fi card will install firmware-iwlwifi successfully and still have nothing to load it into.

CPU microcode is a special firmware update applied by the kernel very early, before most drivers start. The package for Intel CPUs is intel-microcode; AMD CPUs use amd64-microcode. Installing it reports the deferred update:

# apt-get install intel-microcode
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  intel-microcode
0 upgraded, 1 newly installed, 0 to remove and 29 not upgraded.
Need to get 0 B/12.8 MB of archives.
After this operation, 21.4 MB of additional disk space will be used.
Selecting previously unselected package intel-microcode.
Setting up intel-microcode (3.20251111.1~deb13u1) ...
intel-microcode: microcode will be updated at next boot
Processing triggers for initramfs-tools (0.148.4) ...
update-initramfs: Generating /boot/initrd.img-6.12.117+deb13-amd64

The unpacking lines between the selection and Setting up, and the needrestart summary after the initramfs rebuild, were omitted from this selected output. The package places the microcode blobs in /usr/lib/firmware/intel-ucode, one file per CPU signature:

$ ls /usr/lib/firmware/intel-ucode | head -n 8
06-0f-02
06-0f-06
06-0f-07
06-0f-0a
06-0f-0b
06-0f-0d
06-16-01
06-17-06

It also triggers an initramfs rebuild that includes the early-load file:

# lsinitramfs /boot/initrd.img-$(uname -r) | grep -i microcode
kernel/x86/microcode
kernel/x86/microcode/.enuineIntel.align.0123456789abc
kernel/x86/microcode/GenuineIntel.bin
etc/modprobe.d/intel-microcode-blacklist.conf

The kernel applies the matching revision on the next boot and logs a message; the running CPU still reports its current revision until then:

$ grep -m1 microcode /proc/cpuinfo
microcode   : 0x1

Whether a new revision is actually applied depends on the CPU and the virtualization layer. After the reboot, compare grep microcode /proc/cpuinfo with the previous value and check journalctl -k | grep -i microcode for the early-load message.

Do not install both intel-microcode and amd64-microcode: only the package matching the CPU vendor is useful, and the other may fail or be harmless depending on the package's checks.

Table 7.13 summarizes the firmware packages. The component column is part of the repository configuration, not a property of the hardware.

Package Component Purpose
firmware-linux-free main Free firmware files for various devices.
firmware-linux non-free-firmware Metapackage pulling the free and non-free firmware collections.
firmware-iwlwifi non-free-firmware Intel Wi-Fi adapter firmware.
firmware-misc-nonfree non-free-firmware Miscellaneous non-free firmware.
intel-microcode non-free-firmware Intel CPU microcode updates.
amd64-microcode non-free-firmware AMD CPU microcode updates.

The source stanza must match the suite and archive the machine already uses; if the system also uses a security suite, add the component there as well rather than pointing a second entry at a different release. Enabling non-free-firmware changes the repository trust and update surface. Keep the Signed-By line, do not mix suites, and remove the extra source file if the machine does not need it. On a machine that needs non-free firmware to boot or to use its network, the installer normally enables the component during installation; check the effective sources rather than assuming. If the handbook-nonfree.sources file was added only for this exercise, remove it and run apt-get update; keep the firmware packages only if the hardware actually needs them.