Linux Boot Rescue with Chroot from Live USB: Fix GRUB, fstab, and Kernels

Linux tutorial - IT technology blog
Linux tutorial - IT technology blog

Approach Comparison: Handling Broken Linux Boot Sequences

Few things derail a workday faster than a server that refuses to boot after routine maintenance. A botched kernel update, an unexpected power cut, or a transposed character in your storage config can leave hardware hanging at a black screen or stranded at the grub rescue> prompt.

When an operating system stalls at startup, you generally have three paths forward:

Approach Typical Workflow Recovery Speed Failure Risk
Automated Repair Disks (e.g., Boot-Repair) Boot a desktop ISO, click an automated repair button, and let scripts guess the configuration. 5–10 minutes High on mdadm RAID, LVM volumes, LUKS encryption, or non-standard EFI layouts.
Full Backup Restore (Snapshots/Images) Re-flash root partition images or roll back hypervisor/ZFS snapshots. 30–90 minutes Guaranteed data loss for all transactions committed since the last backup window.
Manual Chroot via Live USB Mount host partitions, bind virtual filesystems, and enter the root shell directly. 5–15 minutes Low. Every command executes under full administrator control with zero guesswork.

Automated GUI utilities routinely fail when they encounter multi-disk arrays or complex volume groups. Rolling back snapshots works, but it destroys recent database writes and runtime logs created after that snapshot ran. A chroot (change root) session bypasses both headaches. By entering the broken disk’s environment from a Live USB, you run the server’s own native package managers and tools against its real configuration files.

Pros and Cons of the Chroot Recovery Workflow

While chrooting is an indispensable skill for any sysadmin, it requires careful execution. Weigh these practical trade-offs before opening a rescue shell:

Pros

  • Native Binary Execution: You run the installed distribution’s native package manager (such as apt, dnf, or pacman) directly. There are no library mismatches or alien tool chains.
  • Zero Proprietary Dependencies: Any lightweight ISO—even a 700MB Debian netinst or Ubuntu Server image—works out of the box.
  • Targeted Repairs: Fix the exact damaged component without risking untouched filesystems. If only /etc/fstab has an invalid UUID, edit that single line and leave the remaining 500GB of application data intact.
  • Full Operational Visibility: Inspect raw partition tables, UUID mappings, and EFI boot variables before committing persistent writes to disk.

Cons

  • Strict Mount Prerequisites: Forgetting to bind pseudo-filesystems like /dev, /proc, or /sys will break grub scripts and kernel post-install hooks without clear error traces.
  • No Guardrails: You operate as unrestricted root. A typo inside dd, fdisk, or rm -rf can permanently destroy healthy partitions.
  • Architecture Lock: The Live environment must match the CPU architecture of the target installation. You cannot chroot into an arm64 installation from an x86_64 Live image without configuring QEMU user emulation.

Recommended Setup

Do not wait for an emergency to build your rescue media. Keep a dedicated 32GB or 64GB flash drive configured with Ventoy. Drop current ISOs directly onto the drive: Ubuntu 24.04/22.04 LTS, Debian 12, and AlmaLinux 9. Having bootable ISOs ready turns a potential multi-hour outage into a 10-minute fix.

This approach saves substantial time over slow out-of-band networks. Pulling a 60GB raw image through an IPMI virtual media session over a 15 Mbps connection can take over an hour. Booting a 1.5GB ISO directly into RAM lets you diagnose and repair the server in less than 10 minutes.

Run through this quick sanity check before typing any repair commands:

  • Confirm whether the machine boots via Legacy BIOS (MBR) or UEFI. Look for an active /sys/firmware/efi directory in the Live environment.
  • Identify your partition layout: locate the root (/), boot (/boot), and EFI System Partition (ESP), accounting for LVM or LUKS wrappers.
  • Check your network connection. If you need to reinstall damaged kernel packages, ensure DNS and default gateways are reachable from the Live host.

Implementation Guide: Rescuing the Broken System

Step 1: Boot into the Live Environment and Locate Partitions

Insert your rescue media, boot into the live console, and map all attached block storage using lsblk:

# Display device tree with filesystems, sizes, and UUIDs
lsblk -o NAME,FSTYPE,SIZE,FSAVAIL,FSUSE%,MOUNTPOINTS,UUID

# Verify partition table types (GPT vs DOS/MBR)
sudo parted -l

Locate the target partitions. For this guide, assume an NVMe installation on /dev/nvme0n1 (or /dev/sda on SATA systems):

  • /dev/nvme0n1p1: EFI System Partition (vfat, 512MB)
  • /dev/nvme0n1p2: Boot Partition (ext4, 1GB; present on separate boot setups)
  • /dev/nvme0n1p3: Root Filesystem (ext4 or xfs, ~100GB)

Step 2: Mount Target Partitions and Virtual Filesystems

Mount the root partition under /mnt. Then bind the kernel’s virtual runtime filesystems so system utilities inside the jail can read hardware tables, process trees, and device nodes:

# 1. Mount the main root filesystem
sudo mount /dev/nvme0n1p3 /mnt

# 2. Mount /boot if located on a separate partition
sudo mount /dev/nvme0n1p2 /mnt/boot

# 3. Mount the EFI System Partition (UEFI systems only)
sudo mount /dev/nvme0n1p1 /mnt/boot/efi

# 4. Bind virtual kernel filesystems
for dir in /dev /dev/pts /proc /sys /run; do
    sudo mount --bind "$dir" "/mnt$dir"
done

# 5. Copy host DNS configuration to ensure network access inside the jail
sudo cp -L /etc/resolv.conf /mnt/etc/resolv.conf

Step 3: Enter the Chroot Environment

Shift your root execution context to the mounted disk:

sudo chroot /mnt /bin/bash

# Populate standard executable paths and load environment variables
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
source /etc/profile 2>/dev/null

You are now working directly inside your target operating system. All modifications apply directly to the persistent storage.

Step 4: Repair Scenario 1 — Fixing fstab UUID Mismatches

When storage volumes are reformatted or migrated to new virtual disks, their UUIDs change. If /etc/fstab still references the old IDs, systemd halts the boot with an emergency maintenance prompt: Timed out waiting for device /dev/disk/by-uuid/....

Verify your live device UUIDs against what fstab expects:

# List active partition UUIDs
blkid

# Inspect current static mount definitions
cat /etc/fstab

If an entry is wrong, open the file and update the UUID string to match the current output of blkid:

nano /etc/fstab

For non-essential secondary mounts (such as secondary data disks or NFS shares), append the nofail mount option in the fourth column. That way, missing auxiliary drives will not block the operating system from booting into multi-user target.

Step 5: Repair Scenario 2 — Reinstalling and Updating GRUB

If a dual-boot installer, an interrupted update, or disk cloning corrupted the bootloader stage, reinstall GRUB cleanly.

For UEFI Systems:

Verify that /sys/firmware/efi exists before proceeding. Then reinstall the EFI binary and register it with the motherboard’s NVRAM boot entries:

# Reinstall GRUB EFI binaries to the mounted ESP
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck

# Generate a clean /boot/grub/grub.cfg
update-grub

For Legacy BIOS (MBR) Systems:

Target the base disk device (like /dev/sda or /dev/vda). Never target an individual partition number such as /dev/sda1:

# Write boot code directly into the Master Boot Record and post-MBR gap
grub-install --target=i386-pc /dev/sda

# Rebuild the bootloader menu
update-grub

Step 6: Repair Scenario 3 — Rebuilding Broken Kernels & Initramfs

If a package transaction was cut short during a kernel update, the ramdisk image may be corrupt or missing. This triggers an early boot error: kernel panic - not syncing: VFS: Unable to mount root fs. Rebuild the ramdisk and clean up unfinished dpkg transactions inside the chroot:

# 1. Complete interrupted package configurations
dpkg --configure -a

# 2. Inspect currently installed kernel images
dpkg -l | grep -E 'linux-image|linux-headers'

# 3. Reinstall the production kernel metapackage (Debian/Ubuntu)
apt-get update
apt-get install --reinstall -y linux-image-generic

# 4. Regenerate initramfs for all detected kernel versions
update-initramfs -c -k all

# 5. Refresh the GRUB configuration to catch the rebuilt initrd
update-grub

Step 7: Clean Exit and Reboot

Never reboot while raw partitions and kernel virtual filesystems are bound to /mnt. Abrupt resets can leave filesystems marked dirty or damage write buffers. Exit the jail and unmount your partitions cleanly:

# Terminate the chroot shell
exit

# Recursively unmount all bound mounts starting from the leaf mounts
sudo umount -R /mnt

# Safely reboot the system
sudo reboot

Remove the USB drive as the hardware initializes. The server will hand off execution cleanly to the restored bootloader, read the validated /etc/fstab, and boot into the freshly compiled initramfs.

Share: