Tech Study Guide
Linux Package and Boot Recovery
Debian and Ubuntu recovery runbooks for broken packages, bad kernels, initramfs failures, GRUB rescue, emergency mode, and rollback.
Linux Package and Boot Recovery
Package and boot failures are high-pressure because the normal management path may be broken. Recovery work needs conservative sequencing: preserve evidence, identify the last change, boot a known-good path, restore package consistency, and only then clean up.
Examples here assume Debian-family systems with Ubuntu Server as the default operational target.
Command Examples
cat /etc/os-release
uname -a
systemctl --failed
journalctl -xb
dpkg --audit
apt-mark showhold
Example output and meaning:
| Command | Example output | What it does |
|---|---|---|
cat /etc/os-release |
PRETTY_NAME="Ubuntu 24.04.2 LTS". |
Identifies the distro baseline before applying package or service commands. |
uname -a |
Linux host 6.8.0-xx-generic x86_64. |
Shows kernel version and architecture for driver, eBPF, and tuning checks. |
systemctl --failed |
Unit state, link state, DNS servers, time sync, or host identity fields. |
Shows systemd-managed state instead of inferred configuration. |
When the host cannot boot normally, collect the same facts from emergency mode, rescue media, serial console, or a mounted root filesystem.
Broken Packages
Package transactions can fail because maintainer scripts fail, dependencies conflict, disk fills, dpkg locks remain, or repositories changed.
Recovery sequence:
sudo dpkg --audit
sudo apt -f install
sudo dpkg --configure -a
sudo apt update
sudo apt install --reinstall <package>
Check logs:
less /var/log/apt/history.log
less /var/log/apt/term.log
less /var/log/dpkg.log
Do not remove packages blindly. A forced remove of core packages can turn a package issue into a boot issue.
Bad Kernel or Initramfs
Kernel updates can fail because the new kernel, module, DKMS build, firmware, storage driver, root UUID, or initramfs is wrong.
Useful commands from a working boot or chroot:
ls -lh /boot
dpkg -l 'linux-image*' 'linux-modules*'
lsinitramfs /boot/initrd.img-$(uname -r) | head
sudo update-initramfs -u -k all
sudo update-grub
If the latest kernel fails, boot the previous kernel from GRUB advanced options, then inspect /var/log/apt/history.log, DKMS logs, and kernel logs.
GRUB Rescue and Emergency Mode
Common entry points:
| State | Meaning |
|---|---|
| GRUB menu | Bootloader works; choose older kernel or edit kernel command line. |
| GRUB rescue | Bootloader cannot find modules, config, or root path. |
| initramfs shell | Kernel booted but cannot mount real root or find required device. |
| emergency mode | systemd booted far enough to isolate into repair target. |
Useful emergency commands:
mount -o remount,rw /
findmnt /
blkid
lsblk -f
journalctl -xb
systemctl default
For filesystem or /etc/fstab problems, findmnt --verify and commenting a bad mount can restore boot while preserving a follow-up fix.
Chroot Repair
From rescue media:
sudo mount /dev/<root-volume> /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
dpkg --configure -a
update-initramfs -u -k all
update-grub
If /boot or EFI System Partition is separate, mount it before chrooting.
Rollback Strategy
- Keep at least one known-good kernel installed.
- Snapshot before risky package, kernel, driver, or bootloader changes.
- Avoid unattended upgrades for kernel-sensitive fleets without staged rollout.
- Keep console access tested.
- Record package holds intentionally.
- Test restore and chroot procedures before incidents.
Runbook
- Preserve console output and package logs.
- Identify last package, kernel, driver, or bootloader change.
- Boot previous kernel or rescue mode if possible.
- Repair package state with
dpkg --audit,apt -f install, anddpkg --configure -a. - Rebuild initramfs and GRUB only after confirming
/boot, root UUIDs, and drivers. - Reboot once into the intended kernel and verify services, mounts, and networking.
- Add a postmortem note with rollback and prevention changes.
Study Cards
Why keep an older kernel installed?
It provides a known-good boot path when a new kernel, module, firmware, or initramfs fails.
What does dpkg --configure -a do?
It resumes configuration for unpacked packages whose maintainer scripts have not completed.
Why mount /boot before chroot repair?
Kernel, initramfs, and bootloader updates must write to the actual boot filesystem.
Why is console access important for boot recovery?
Network and SSH may be unavailable before the system reaches normal multi-user boot.