16.3. Repairing Boot and Startup
Boot repair has an order. The boot loader loads a kernel and initramfs; the
kernel and initramfs find the root; systemd mounts the remaining filesystems
and starts units until the default target is reached. A mistake in fstab or
crypttab can stop the process after the kernel has started; a missing
initramfs can stop it before the root is found; a damaged GRUB installation
can stop it before the kernel is loaded; a broken service or target can leave
the machine running but not usable. Repair the lowest layer that the evidence
implicates, then validate the next layer before moving up.
16.3.1. Correcting fstab and crypttab Failures
A bad /etc/fstab entry produces a failed mount unit, a boot that waits for a
device that never appears, or an emergency shell after systemd gives up. The
first check is the one that reads the file without mounting anything:
$ sudo systemctl daemon-reload
The command is silent. It asks systemd to regenerate the mount and automount
units from the current fstab; without it, systemd may continue to use an
older generated view and report that the file has been modified but not
reloaded. Then verify the table:
$ sudo findmnt --verify
Success, no errors or warnings detected
findmnt --verify parses /etc/fstab and checks whether the sources and
target directories are usable. It does not mount anything and does not prove
that the filesystem is healthy; it proves that the entries are syntactically
valid and that the devices or UUIDs can be found. A clean result is the normal
baseline before an edit.
The exercise introduces a wrong UUID in the application volume entry. The
changed line in /etc/fstab reads:
UUID=deadbeef-0000-0000-0000-000000000000 /srv/appdata ext4 defaults 0 2
Verify the result:
$ sudo findmnt --verify
/srv/appdata
[E] unreachable on boot required source: UUID=deadbeef-0000-0000-0000-000000000000
[W] your fstab has been modified, but systemd still uses the old version;
use 'systemctl daemon-reload' to reload
0 parse errors, 1 error, 1 warning
The [E] line is the fatal problem: the source named by the entry does not
exist. The warning repeats that systemd has not been told about the edit. A
parse error would be reported as a syntax problem instead; a missing target
directory appears as "unreachable on boot required target: No such file or
directory." The 0 parse errors, 1 error summary counts this one entry; the
warning says systemd has not reloaded the table yet. Fix the UUID with the real
value:
$ sudo blkid -s UUID -o value /dev/datavg/appdata
ebee9a29-b855-4af5-a623-e9b4010ac3ee
The command prints only the UUID, which is convenient for copying into the
file. Edit /etc/fstab so the line uses that value, then reload and verify:
$ sudo systemctl daemon-reload
$ sudo findmnt --verify
Success, no errors or warnings detected
The order matters: edit, daemon-reload, verify. If the filesystem is mounted
and you edit its entry, systemd does not retroactively change the active
mount; it uses the new entry on the next mount or boot. findmnt --verify
checks the file, not the running mount table. To confirm the active mount, use
findmnt /srv/appdata, which reports the source and options actually in use.
/etc/crypttab failures have a similar shape but a different tool. The file
has one line per encrypted mapping: target name, source device or UUID, key
file or none, and options. Add this line to /etc/crypttab for the practice
container:
recoverycrypt UUID=78f570f6-b31e-4d57-a6df-c942bc125f37 /etc/luks/recovery.key luks
The target name becomes /dev/mapper/recoverycrypt; the source is the LUKS
container; the key file is read before the passphrase prompt; luks selects
the LUKS handler. Debian's cryptdisks_start wrapper reads this file for a
manual test:
$ sudo cryptdisks_start recoverycrypt
Starting crypto disk...recoverycrypt (starting)...Warning: keyslot operation could fail as it requires more than available memory.
recoverycrypt (started)...done.
When it appears, the warning is from Argon2 key derivation on a small machine;
it does not mean the passphrase failed. The command is successful when the
mapping is active and the script prints done.; the exact progress text is
not a stable interface, so check cryptsetup status recoverycrypt afterward. On a systemd boot, the
systemd-cryptsetup-generator reads /etc/crypttab and creates a
systemd-cryptsetup@.service unit for each entry; the cryptdisks init
scripts are Debian's compatibility path. Chapter
13 explains the difference and the options that change
the generator's behavior.
A UUID that does not exist fails before the key is tried:
$ sudo cryptdisks_start recoverycrypt
Starting crypto disk...recoverycrypt (skipped, device UUID=deadbeef-0000-0000-0000-000000000000 does not exist)...failed.
The exit status is nonzero and no mapping is created. Get the real UUID with
cryptsetup luksUUID /dev/vdd and correct the line. A correct UUID but a wrong
key file fails later, with No key available with this passphrase or a
key-file error; a correct UUID and key but a missing initramfs hook leaves the
boot unable to unlock the root before systemd starts. After changing
crypttab for a root or /usr volume, rebuild the initramfs as shown in
Section 16.3.2; a non-root data volume does not need an initramfs rebuild for
its mapping to work at boot, but the generator still needs the entry to be
present when the boot transaction is assembled.
Stop the test mapping before moving on:
$ sudo cryptdisks_stop recoverycrypt
Stopping crypto disk...recoverycrypt (stopping)...done.
A mapping that is still mounted cannot be stopped; unmount the filesystem
above it first. The cryptdisks_stop message is again descriptive rather than
stable. If the volume is needed by a running service, stop the service before
the mapping, and start the mapping before the service. Finally, remove the
practice recoverycrypt line from /etc/crypttab, so the next boot does not
try to unlock the disposable container.
16.3.2. Rebuilding Initramfs Images
The initramfs is the small userland that the boot loader loads with the kernel. It contains the storage drivers, the crypto and LVM helpers, and the scripts that find and mount the real root. A missing or stale image can leave the kernel without the driver for the root disk, without the cryptsetup hook for an encrypted root, or with an initramfs that does not match the installed kernel's modules. Chapter 7 explains how the image is assembled; this section rebuilds it and proves what went into it.
Update the image for every installed kernel that already has one:
$ sudo update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64
W: No zstd in /usr/bin:/sbin:/bin, using gzip
The command prints one Generating line per kernel. The W: line is a
warning, not a failure: /etc/initramfs-tools/initramfs.conf selects zstd
compression, the zstd program is not installed on this machine, and
initramfs-tools falls back to gzip. The image is still usable; installing the
zstd package restores the configured compression, and the warning is not a
reason to abort a repair in an emergency. -u updates existing images; -k
all selects every installed kernel with an image. If an image is missing
entirely, -u has nothing to update and the kernel cannot be repaired that
way; create it with -c:
$ sudo update-initramfs -c -k all
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64
W: No zstd in /usr/bin:/sbin:/bin, using gzip
The -c mode creates a new image even when none exists, replacing any image
that is already present; -k names the kernel version, and all covers all
installed versions. The command writes the image named in the output; the
kernel package's postinst normally calls this for you, but a manual repair
after deleting or corrupting the image must run it explicitly.
Check the size and the contents that matter for recovery:
$ ls -lh /boot/initrd.img-6.12.86+deb13-amd64
-rw-r--r-- 1 root root 42M Nov 21 03:19 /boot/initrd.img-6.12.86+deb13-amd64
A zero-byte or unexpectedly tiny image is a failed rebuild. A normal image is tens of megabytes and changes size with the kernel and the included firmware. The exact size is not a health check; the file must be large enough to contain the kernel modules and scripts. List the crypto helpers inside it:
$ sudo lsinitramfs /boot/initrd.img-6.12.86+deb13-amd64 | grep -E "cryptsetup|etc/crypttab" | head -6
usr/lib/cryptsetup
usr/lib/cryptsetup/askpass
usr/lib/cryptsetup/functions
usr/lib/x86_64-linux-gnu/libcryptsetup.so.12
usr/lib/x86_64-linux-gnu/libcryptsetup.so.12.10.0
usr/sbin/cryptsetup
lsinitramfs lists the archive without unpacking it. The presence of
cryptsetup and libcryptsetup shows that the cryptsetup initramfs hook ran;
without them, an encrypted root cannot be unlocked before the real root is
mounted. The same check for LVM looks for lvm and dmsetup; for a root on a
RAID array, look for mdadm. The hook files themselves live under
/etc/initramfs-tools/hooks and /usr/share/initramfs-tools/hooks; a custom
hook that fails silently can omit the required module even though the package
is installed. update-initramfs -v adds detail when a rebuild succeeds but the
content is still wrong.
The same operation works inside a mounted recovery root. To practice the missing-image case, move the copy's healthy image aside first:
$ sudo mv /mnt/recovery/boot/initrd.img-6.12.86+deb13-amd64 /mnt/recovery/boot/initrd.img-6.12.86+deb13-amd64.missing
The command is silent. Then, with the /proc, /sys, /dev, and /dev/pts
bind mounts in place, let the chroot create the image with the installed
system's kernel and modules:
$ sudo chroot /mnt/recovery update-initramfs -c -k all
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64
W: No zstd in /usr/bin:/sbin:/bin, using gzip
The output path is relative to the chroot, so the image is written inside the
mounted root at /mnt/recovery/boot, not on the rescue system's /boot.
Verify it from outside:
$ sudo test -s /mnt/recovery/boot/initrd.img-6.12.86+deb13-amd64
test -s is silent and exits 0 when the file exists and is non-empty. This is
a better check than ls in a script, but for a reader ls -lh shows the size
and timestamp as well. Rebuild the GRUB menu after the image is restored if
the menu entry refers to a path that changed; normally the kernel and initrd
names are stable, so update-grub is not required for an image rebuild alone.
16.3.3. Reinstalling GRUB for UEFI and Legacy Boot
GRUB reinstalling is required when the boot code is missing, when the disk was
replaced, when the firmware entry points at a file that no longer exists, or
when a failed upgrade left the GRUB modules inconsistent. The command differs
between legacy BIOS and UEFI, and the wrong command writes boot code to the
wrong place. First determine which firmware mode the machine is using. On a
UEFI system the kernel exposes EFI runtime services and /sys/firmware/efi
exists:
$ test -d /sys/firmware/efi
The command is silent. An exit status of 0 means the system booted in UEFI mode; a nonzero status means legacy BIOS (or a kernel that did not expose EFI variables). On the practice machine the command exits nonzero, so the current boot is legacy. That does not prevent installing a UEFI loader onto a secondary disk for validation, which is what the recovery copy exercise does.
On the legacy machine, install GRUB to the disk that the firmware boots:
$ sudo grub-install /dev/vda
Installing for i386-pc platform.
Installation finished. No error reported.
The messages are written to standard error; a successful install still exits
0. /dev/vda is the whole disk, not a partition. On a GPT disk with legacy
boot, GRUB needs a BIOS boot partition (the 1 MiB partition in the recovery
copy); without it, grub-install refuses to embed the core image and warns
that blocklists are unreliable. The recovery copy has that partition, which is
why the same command works inside its chroot:
$ sudo chroot /mnt/recovery grub-install --target=i386-pc --boot-directory=/boot /dev/vdc
Installing for i386-pc platform.
Installation finished. No error reported.
The --target=i386-pc selects the legacy platform explicitly; the default on
a BIOS system is already i386-pc, but the explicit form is clearer in a
rescue script. --boot-directory=/boot is relative to the chroot, so the GRUB
modules and grub.cfg go into the mounted root's /boot/grub. Writing to
/dev/vdc does not touch the running system's /dev/vda; confirm the device
with lsblk and the disk's size and model before running the command on a
real machine.
Regenerate the menu after the loader is installed:
$ sudo update-grub
Generating grub configuration file ...
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 Debian's wrapper around grub-mkconfig -o /boot/grub/grub.cfg.
It finds the installed kernels and initramfs images and writes the menu. The
"UEFI Firmware Settings" message comes from Debian's 30_uefi-firmware
fragment, which prints it on every machine while generating the menu; the
generated entry is wrapped in a grub_platform check and appears only on a
UEFI boot, so the message is not proof of the current firmware mode. On the
recovery copy the same command runs inside the chroot and finds the copy's
kernel:
$ sudo chroot /mnt/recovery update-grub
Generating grub configuration file ...
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
The menu is only usable if its root= and search commands point at the
filesystems that will exist at boot. Check the generated script syntax:
$ sudo grub-script-check /boot/grub/grub.cfg
The command is silent on success. It parses the generated file but does not
execute it, so it cannot prove that the kernel will boot; it catches syntax
errors introduced by a broken fragment or a bad hand edit. A failed check
usually names the line; fix the fragment under /etc/grub.d or
/etc/default/grub and regenerate, rather than editing grub.cfg directly.
The copy's generated script can be checked the same way:
$ sudo chroot /mnt/recovery grub-script-check /boot/grub/grub.cfg
For UEFI, the loader must be written to the mounted ESP and the firmware entry
must point at it. The normal command on the installed system is the one from
Chapter 7, grub-install --target=x86_64-efi
--efi-directory=/boot/efi --bootloader-id=debian --uefi-secure-boot. It
requires the ESP to be mounted at /boot/efi, the grub-efi-amd64-bin and
signed packages to be installed, and the firmware variables to be writable.
The recovery copy is not the machine's firmware and has no EFI variables, so
the exercise installs the removable fallback path instead:
$ sudo chroot /mnt/recovery grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --no-nvram --removable
Installing for x86_64-efi platform.
Installation finished. No error reported.
--no-nvram prevents the command from trying to update firmware variables
that do not exist in the chroot; --removable writes
EFI/BOOT/BOOTX64.EFI, the fallback path that firmware uses when no NVRAM
entry is present. On a real UEFI machine, omit both options and keep
--bootloader-id=debian and --uefi-secure-boot; that creates or updates the
Debian NVRAM entry. If the machine no longer boots and the firmware menu has
no Debian entry, the removable fallback is a deliberate recovery path: it
makes the disk bootable even when NVRAM is lost, at the cost of bypassing the
named entry. Verify the files:
$ find /mnt/recovery/boot/efi/EFI -type f
/mnt/recovery/boot/efi/EFI/BOOT/BOOTX64.EFI
/mnt/recovery/boot/efi/EFI/BOOT/grubx64.efi
/mnt/recovery/boot/efi/EFI/BOOT/mmx64.efi
/mnt/recovery/boot/efi/EFI/BOOT/BOOTX64.CSV
/mnt/recovery/boot/efi/EFI/BOOT/grub.cfg
The presence of BOOTX64.EFI confirms the removable path. A normal
--bootloader-id=debian installation writes EFI/debian/shimx64.efi,
EFI/debian/grubx64.efi, and EFI/debian/mmx64.efi on a Secure Boot system.
Check the ESP is still mounted with findmnt /boot/efi before trusting the
paths; writing to an unmounted /boot/efi populates the root filesystem
instead. The GRUB modules and the menu on the root filesystem are installed by
the same command; the --boot-directory option keeps them with the root's
/boot.
The two boot paths and their recovery implications are compared in Table 16.2.
| Aspect | Legacy BIOS | UEFI |
|---|---|---|
| Write target | Disk boot area, plus a BIOS boot partition on GPT | Files on the FAT32 ESP, plus NVRAM entry |
| Install command | grub-install /dev/vda |
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --uefi-secure-boot |
| Fallback path | Disk boot order | EFI/BOOT/BOOTX64.EFI when no NVRAM entry exists |
| Firmware inspection | Firmware boot order | efibootmgr -v |
| Main recovery risk | Wrong disk or missing BIOS boot partition | ESP not mounted, wrong ESP, or lost NVRAM entry |
On a UEFI machine, efibootmgr -v shows the entries and the loader paths.
efibootmgr -o changes the permanent order, -n sets the next boot only, and
-b with -B deletes an entry. Record the output before changing it; entry
numbers are machine-specific. The full option set and Secure Boot chain are in
Chapter 7.
16.3.4. Recovering from Broken Service and Target Configuration
A boot that reaches a login prompt but starts the wrong services is a
different failure from a boot that never reaches systemd. The tools are the
same ones used in Chapter 8, applied in a recovery
order: find the failed unit, read its status and journal, correct the unit or
its environment, reload systemd, and start it again. The practice service is a
one-shot unit with a deliberately failing ExecStart:
[Unit]
Description=Chapter 16 recovery demonstration
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/false
The file belongs at /etc/systemd/system/recovery-demo.service. After writing
it, reload the manager so the new unit is visible:
$ sudo systemctl daemon-reload
The command is silent. Starting the service produces a failure:
$ sudo systemctl start recovery-demo.service
Job for recovery-demo.service failed because the control process exited with error code.
See "systemctl status recovery-demo.service" and "journalctl -xeu recovery-demo.service" for details.
The start command exits nonzero; the message points at the two commands that
explain why. systemctl status summarizes the unit's state, and
journalctl -u shows the unit's log lines. The status output is long enough to
include the process exit code:
$ sudo systemctl status recovery-demo.service --no-pager
× recovery-demo.service - Chapter 16 recovery demonstration
Loaded: loaded (/etc/systemd/system/recovery-demo.service; static)
Active: failed (Result: exit-code) since Sat 2026-11-21 03:22:42 UTC; 1s ago
Invocation: b2c93fd7c7f24c399dde09a2571bc2c4
Process: 18033 ExecStart=/bin/false (code=exited, status=1/FAILURE)
Main PID: 18033 (code=exited, status=1/FAILURE)
Mem peak: 1.7M
CPU: 7ms
Nov 21 03:22:42 recovery1 systemd[1]: Starting recovery-demo.service - Chapter 16 recovery demonstration...
Nov 21 03:22:42 recovery1 systemd[1]: recovery-demo.service: Main process exited, code=exited, status=1/FAILURE
Nov 21 03:22:42 recovery1 systemd[1]: recovery-demo.service: Failed with result 'exit-code'.
Nov 21 03:22:42 recovery1 systemd[1]: Failed to start recovery-demo.service - Chapter 16 recovery demonstration.
The Process line names the exact command and exit status; the journal shows
the same event without the resource counters. systemctl --failed gives the
short list of units that need attention:
$ sudo systemctl --failed --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
● recovery-demo.service loaded failed failed Chapter 16 recovery demonstration
Legend: LOAD → Reflects whether the unit definition was properly loaded.
ACTIVE → The high-level unit activation state, i.e. generalization of SUB.
SUB → The low-level unit activation state, values depend on unit type.
1 loaded units listed.
The list names the unit with the ● marker and the loaded failed failed
state; the legend explains the three columns. A successful start clears the
entry, so the list is empty again after the fix below and in the final
validation in Section 16.5.1. Do not assume that a clean --failed list
means the boot is healthy: a service that is not enabled at all never
becomes failed, and a target can be reached without the service you
expected. Check the dependencies with systemctl list-dependencies and the
unit's WantedBy/RequiredBy links.
journalctl -u shows the unit's messages, including the failing command:
$ sudo journalctl -u recovery-demo.service --no-pager -n 6
Nov 21 03:22:42 recovery1 systemd[1]: Starting recovery-demo.service - Chapter 16 recovery demonstration...
Nov 21 03:22:42 recovery1 systemd[1]: recovery-demo.service: Main process exited, code=exited, status=1/FAILURE
Nov 21 03:22:42 recovery1 systemd[1]: recovery-demo.service: Failed with result 'exit-code'.
Nov 21 03:22:42 recovery1 systemd[1]: Failed to start recovery-demo.service - Chapter 16 recovery demonstration.
The log does not include the program's own error message because the program
was /bin/false, which prints nothing. A real service's stderr appears in the
journal unless it is redirected elsewhere; check the service's StandardError=
setting if the log stops at "Starting". Fix the command:
ExecStart=/bin/true
Then reload and start it again:
$ sudo systemctl daemon-reload
$ sudo systemctl start recovery-demo.service
Both commands are silent on success. RemainAfterExit=yes keeps the unit
active after its command exits, so the state is observable:
$ systemctl is-active recovery-demo.service
active
Without RemainAfterExit, a successful Type=oneshot service becomes
inactive again after it finishes; is-active would print inactive even
though the command succeeded. Use systemctl show -p Result --value or the
exit status of systemctl start when the unit is not meant to stay active. If
the unit still fails, read the journal again; daemon-reload does not restart
an already running unit, and systemctl start on an active unit is a no-op.
Use systemctl restart after changing the environment of a long-running
service.
A broken default target produces a machine that boots to a rescue shell or
stops at a text login. The default is a symlink under /etc/systemd/system;
get-default prints it:
$ systemctl get-default
graphical.target
Set the text target for a server or a recovery boot:
$ sudo systemctl set-default multi-user.target
Created symlink '/etc/systemd/system/default.target' → '/usr/lib/systemd/system/multi-user.target'.
The message is written to standard error; get-default confirms the change:
$ systemctl get-default
multi-user.target
Restore the graphical default when the desktop is working again:
$ sudo systemctl set-default graphical.target
Removed '/etc/systemd/system/default.target'.
Created symlink '/etc/systemd/system/default.target' → '/usr/lib/systemd/system/graphical.target'.
set-default changes the next boot, not the current one. systemctl isolate
multi-user.target changes the current target immediately, but on a remote
system it can stop ssh.service and the session with it; do not use it as a
remote repair tool. If the current boot is already stuck, use the GRUB editor
to add systemd.unit=multi-user.target for one boot, then make the change
persistent after the system is reachable. A target with a Requires= on a
missing or failed unit fails as a whole; systemd-analyze verify on the unit
file catches syntax and dependency errors before the next boot:
$ sudo systemd-analyze verify /etc/systemd/system/recovery-demo.service
The command is silent on success. It checks the unit's syntax and its
dependencies but does not execute the service; a bad ExecStart path is
reported, while a command that exists but exits nonzero is only discovered at
start time. The unit files from packages should not be edited in
/usr/lib/systemd/system; put overrides in /etc/systemd/system or a
.d drop-in, as described in Chapter 8.