7.2. Managing GRUB and Firmware Boot Entries

GRUB's job is to turn a set of configuration files into a menu and to load the selected kernel with the correct command line. On BIOS systems it is the first-stage boot loader; on UEFI systems it is a signed EFI application started by the firmware or by shim. The configuration model is the same: settings and script fragments are rendered into /boot/grub/grub.cfg, and a small environment block can override the next menu choice. This section changes kernel parameters persistently, selects a one-time boot entry, and then covers the UEFI and Secure Boot layers that sit before GRUB on modern machines. Figure 7.2 shows how the inputs become the generated menu.

How GRUB configuration is assembled

Figure 7.2. Configuration fragments under /etc/default and /etc/grub.d are rendered into /boot/grub/grub.cfg; /boot/grub/grubenv carries the one-time next_entry override used by grub-reboot.

7.2.1. Persistent GRUB Configuration and Kernel Parameters

The main configuration file is /etc/default/grub. Comments and blank lines can be ignored when reading the effective settings:

$ grep -vE "^[[:space:]]*(#|$)" /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`( . /etc/os-release && echo ${NAME} )`
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0"
GRUB_CMDLINE_LINUX="consoleblank=0"

GRUB_DEFAULT=0 selects the first menu entry when no one-time choice is pending. GRUB_TIMEOUT=5 would show the menu for five seconds. GRUB_CMDLINE_LINUX_DEFAULT is appended to normal entries; the GRUB_CMDLINE_LINUX value is appended to both normal and recovery entries. The recovery entry also gets single dis_ucode_ldr from the generator, which is why recovery mode is not simply "the same kernel with a different timeout."

Debian also reads drop-in files from /etc/default/grub.d/*.cfg after the main file. They are sourced as shell fragments, and a later assignment wins:

$ grep -H . /etc/default/grub.d/*.cfg
/etc/default/grub.d/10_cloud_disk_scheduler.cfg:# Set disk scheduler to noop and request block multiqueue usage
/etc/default/grub.d/10_cloud_disk_scheduler.cfg:GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX elevator=noop scsi_mod.use_blk_mq=Y"
/etc/default/grub.d/15_timeout.cfg:GRUB_TIMEOUT=0

Two consequences follow. First, the effective timeout on this machine is not the 5 in /etc/default/grub; the 15_timeout.cfg drop-in sets it to 0, so the menu is hidden unless a key is held or GRUB records a failed boot. Second, the disk scheduler settings are appended to GRUB_CMDLINE_LINUX, not to the default line, so they appear in both normal and recovery entries. The scsi_mod.use_blk_mq=Y parameter is obsolete on this kernel; Section 7.6.1 shows the warning it produces and how to trace it back to this file.

To add a kernel parameter persistently, use a new drop-in rather than editing the generated grub.cfg. The drop-in must preserve the existing values when it replaces a variable, because assignment does not append automatically. This example adds a harmless demonstration parameter and a target override while keeping the network naming parameters that the image needs:

$ sudo tee /etc/default/grub.d/99-handbook-test.cfg <<"EOF"
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target"
EOF
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target"

tee writes the file and also echoes the content to the terminal; the line below the command is the command's output, not a second command. The handbook.lab=1 parameter is deliberately unknown to the kernel; it proves that the parameter reached the kernel without changing behavior. systemd.unit=multi-user.target is a real systemd parameter that overrides the default target while it is present; it does not change the default.target symlink. Regenerate the GRUB configuration:

$ sudo update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-6.12.117+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.117+deb13-amd64
Found linux image: /boot/vmlinuz-6.12.86+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.86+deb13-amd64
Adding boot menu entry for UEFI Firmware Settings ...
done

update-grub is a small wrapper around grub-mkconfig; it reads /etc/default/grub, the drop-ins, and the scripts in /etc/grub.d, then writes /boot/grub/grub.cfg. Its progress messages go to standard error. The UEFI Firmware Settings line comes from a generator script and is not used on this BIOS boot. The result can be checked without rebooting:

$ sudo grep -E "handbook.lab=1|systemd.unit=multi-user.target" /boot/grub/grub.cfg | head -n 4
    linux   /boot/vmlinuz-6.12.117+deb13-amd64 root=UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0 ro consoleblank=0 elevator=noop scsi_mod.use_blk_mq=Y net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target
        linux   /boot/vmlinuz-6.12.117+deb13-amd64 root=UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0 ro consoleblank=0 elevator=noop scsi_mod.use_blk_mq=Y net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target
        linux   /boot/vmlinuz-6.12.86+deb13-amd64 root=UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0 ro consoleblank=0 elevator=noop scsi_mod.use_blk_mq=Y net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target

The first line belongs to the top-level menu entry; the indented lines belong to the advanced submenu entries. The parameter is present for both installed kernels, which is what a persistent setting should do. Reboot to apply it:

$ sudo systemctl reboot

The SSH session closes as the machine shuts down, so the command may return a nonzero status or no visible output. After the machine comes back, the kernel command line confirms the change:

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.12.117+deb13-amd64 root=UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0 ro consoleblank=0 elevator=noop scsi_mod.use_blk_mq=Y net.ifnames=0 biosdevname=0 handbook.lab=1 systemd.unit=multi-user.target

The target override is visible in the running system, even though the persistent default did not change:

$ systemctl is-active graphical.target
inactive
$ systemctl get-default
graphical.target
Note: found "systemd.unit" on the kernel command line, which overrides the default unit.

get-default still reports the symlink's value, and systemd adds a note to standard error explaining that the kernel command line takes precedence. This separation is useful: the target symlink remains the persistent default, while the kernel parameter applies to every boot until it is removed. For a genuinely one-boot change, edit the entry in the GRUB menu instead. Remove the drop-in now to restore the normal boot:

$ sudo rm -f /etc/default/grub.d/99-handbook-test.cfg

The command is silent. Then:

$ sudo update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-6.12.117+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.117+deb13-amd64
Found linux image: /boot/vmlinuz-6.12.86+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.86+deb13-amd64
Adding boot menu entry for UEFI Firmware Settings ...
done

A search for the removed parameter now finds nothing:

$ sudo grep -c "handbook.lab=1" /boot/grub/grub.cfg
0

grep -c prints the count and exits 1 when the count is zero; the 0 is the useful result, and the nonzero status only says that no line matched. The next reboot uses the restored command line.

Kernel parameters are appended to the linux line of a menu entry. The most common ones are listed in Table 7.2. Parameters that name a unit or a module are parsed by systemd or kmod rather than by the kernel itself, which is why their spelling differs from kernel subsystem options.

Parameter Effect
root=UUID=... Selects the root filesystem for the initramfs.
ro / rw Mount the root read-only first (the normal choice) or read-write immediately.
quiet / splash Reduce kernel messages or enable the graphical boot splash; both hide diagnostics.
systemd.unit=multi-user.target Boot to a different target for this boot without changing default.target.
systemd.mask=unit Mask a unit for this boot.
nomodeset Ask the kernel not to load a kernel mode-setting driver; a graphics workaround.
modprobe.blacklist=module Prevent kmod from loading the named module automatically on this boot.
panic=10 Reboot ten seconds after a kernel panic instead of waiting indefinitely.
console=ttyS0,115200 Send the console to a serial port; useful when there is no local display.

A one-time change can also be made directly in the GRUB menu. At the menu, highlight an entry and press e to edit it; the linux line can be changed, and Ctrl-X or F10 boots the edited entry. The change is not saved unless you edit the configuration and run update-grub. With GRUB_TIMEOUT=0 the menu may be hidden; holding Shift or pressing Esc during the early boot usually reveals it. This is the normal way to test a parameter once without committing it to the configuration.

7.2.2. UEFI System Partitions and Boot Entry Selection

On a UEFI system, the firmware does not execute the first sector of a disk. It reads boot entries from NVRAM, each naming an EFI application on a FAT EFI System Partition (ESP). efibootmgr reads and changes those entries. On this BIOS machine the tool cannot work because the kernel has no EFI variables:

# efibootmgr
EFI variables are not supported on this system.

The same absence is visible in sysfs:

# ls /sys/firmware/efi
ls: cannot access '/sys/firmware/efi': No such file or directory

These two checks are the quickest way to determine which boot path a machine uses. On a UEFI machine, efibootmgr prints BootCurrent, BootOrder, and one Boot#### line per entry; ls /sys/firmware/efi succeeds. The ESP is normally mounted at /boot/efi and must be FAT32. It holds the boot loader and, on Debian, the shim first stage:

/boot/efi/EFI/debian/shimx64.efi
/boot/efi/EFI/debian/grubx64.efi
/boot/efi/EFI/debian/mmx64.efi
/boot/efi/EFI/debian/grub.cfg

The grub.cfg on the ESP is a small stub that points at /boot/grub on the root filesystem; the real menu and configuration stay in /boot/grub. This split lets the ESP remain small and lets GRUB read the kernels from /boot without a separate copy.

On a UEFI system, efibootmgr -v lists the entries and includes the device path and loader file for each one, which is the only reliable way to see which entry is which. efibootmgr -o 0001,0002 rewrites BootOrder permanently; efibootmgr -n 0003 sets entry 0003 for the next boot only, similar to grub-reboot; and efibootmgr -b 0003 -B deletes entry 0003. Table 7.3 summarizes the options. Run efibootmgr without arguments first and record the output before deleting or reordering anything; the entry numbers are specific to the machine.

Option Description
-v / --verbose Show the device path and loader for each boot entry.
-o 0001,0002 / --bootorder Set the permanent boot order.
-n 0003 / --bootnext Use entry 0003 for the next boot only.
-b 0003 / --bootnum Select an entry for a modification.
-B / --delete-bootnum Delete the selected entry.
-c / --create Create a new entry; requires a loader path and disk.
-a / --activate Mark the selected entry active.

If the firmware entry is missing or points at the wrong file, reinstall the UEFI loader rather than guessing at NVRAM by hand. The command on a Debian UEFI system is:

# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --uefi-secure-boot

Run this on the UEFI machine; it reports the files it installs and should exit 0 on success. --efi-directory must be the mounted ESP, and --bootloader-id controls the directory name and the NVRAM entry. With shim-signed and grub-efi-amd64-signed installed, the --uefi-secure-boot option installs the signed chain (shim and signed GRUB); omit it only when Secure Boot is disabled and an unsigned loader is intended. grub-install also refreshes the stub grub.cfg on the ESP. Verify the mount with findmnt /boot/efi; it should show a vfat filesystem. Then list /boot/efi/EFI/debian, which should contain shimx64.efi, grubx64.efi, and mmx64.efi on a Secure Boot installation.

The ESP is usually mounted with umask=0077 or fmask=0077,dmask=0077 in /etc/fstab so that ordinary users cannot modify boot code. The exact options depend on the installer; do not replace the ESP's mount options with a generic defaults line without checking the result.

The BIOS and UEFI paths differ in where the boot code lives and which tools inspect it, as Table 7.4 shows. The /boot directory exists in both cases; the difference is whether the firmware loads the first stage from the disk's boot area or from a FAT filesystem.

Aspect Legacy BIOS UEFI
First stage location Boot code in the disk's MBR or BIOS boot partition. EFI application on a FAT32 EFI System Partition.
Firmware configuration Boot device order in firmware setup. NVRAM boot entries, inspected with efibootmgr.
Debian packages grub-pc for BIOS. grub-efi-amd64, shim-signed, grub-efi-amd64-signed for Secure Boot.
Boot loader path Disk boot area and /boot/grub. /boot/efi/EFI/debian and /boot/grub.
Secure Boot Not available in the same form. Firmware verifies shim, which verifies GRUB and the kernel.

7.2.3. Secure Boot and Signed Components

Secure Boot is a UEFI feature: the firmware verifies the signature of the first EFI application it starts, and each stage verifies the next. On Debian the chain is normally firmware → shim → GRUB → kernel. shim is signed by Microsoft's UEFI CA and carries Debian's certificate; GRUB is the grub-efi-amd64-signed package; the Debian kernel packages are signed with Debian's build key. The signed packages are available even on a BIOS machine, where they are simply not used:

$ apt-cache policy grub-efi-amd64-signed shim-signed | grep -E "^(grub-efi|shim|  Candidate:)"
grub-efi-amd64-signed:
  Candidate: 1+2.12+9+deb13u2
shim-signed:
  Candidate: 1.51~1+deb13u1+16.1-2~deb13u1

The state of Secure Boot is read with mokutil. The package is in main; install it first if it is not present (sudo apt install mokutil). On this BIOS machine the tool reports the same missing EFI variable support:

$ mokutil --sb-state
EFI variables are not supported on this system

On a UEFI machine the output is SecureBoot enabled or SecureBoot disabled; the exit status is nonzero when the state cannot be read. Run it before deciding whether a module-signing step is needed. If Secure Boot is enabled, an unsigned kernel module will not load. Debian's own modules are signed at build time; out-of-tree modules built by DKMS are not signed by Debian, so DKMS signs them with a local Machine Owner Key (MOK). The key is created when DKMS first builds a module and is stored under /var/lib/dkms; Section 7.3.3 shows the files after a build. The private key is readable only by root; the public certificate is what the firmware must trust. Enrolling it requires a reboot and the MokManager screen, which is a firmware console interaction. After the DKMS key exists, run:

# mokutil --import /var/lib/dkms/mok.pub

--import asks for a password, then requests a reboot; at the blue MokManager screen choose "Enroll MOK", select the key, and enter the password. After the reboot, mokutil --list-enrolled should show the DKMS certificate, and mokutil --delete /var/lib/dkms/mok.pub removes it again. This step cannot be completed over SSH alone because MokManager runs before the operating system and needs the local console. Plan for physical or virtual-console access before enrolling or removing a key. Table 7.5 lists the operations used here.

Option Description
--sb-state Report whether Secure Boot is enabled or disabled.
--import FILE Queue a certificate for enrollment at the next boot.
--list-enrolled List the MOK certificates currently enrolled.
--delete FILE Queue a certificate for deletion.

Secure Boot problems are best diagnosed from the outside in. Check the firmware state with mokutil --sb-state; check that the signed packages are installed with dpkg-query -W shim-signed grub-efi-amd64-signed; check the kernel log for signature messages with journalctl -k | grep -i -E 'secure boot|signature'; and check a specific module with modinfo -F signer. A module can be signed and still fail verification if its key is not enrolled, which is exactly what the DKMS example in Section 7.3.3 shows. Do not disable Secure Boot as a first response; enroll the key or use a signed module instead.