Introduction to Linux Rescue
I’ve been there - your Linux system won’t boot, and you’re left staring at a black screen. This can happen due to a variety of reasons, such as a faulty kernel update, a corrupted boot loader, or even a simple mistake during system configuration. That’s where a USB rescue shell comes in - it can be a lifesaver. In this article, I’ll walk you through the process of recovering a borked Linux boot using a USB rescue shell and chroot.
Preparing the USB Rescue Shell
To get started, you’ll need a USB drive with a Linux distribution installed on it. I like to use Arch Linux for this purpose. Download the latest Arch Linux ISO from the official website and create a bootable USB drive using a tool like dd or Rufus. Once you have your USB drive ready, boot from it and select the “Arch Linux” option from the boot menu. Don’t bother with the GUI - we’ll be working in the terminal.
Booting into the Rescue Shell
After booting into the Arch Linux live environment, you’ll be presented with a command-line interface. From here, you can use the fdisk command to identify the disk and partition that contains your broken Linux installation. For example:
fdisk -l
This will list all the disks and partitions on your system. Take your time to identify the disk and partition that contains your broken Linux installation, and note down the device name (e.g., /dev/sda1). I’ve seen this go wrong when people rush through this step, so be patient.
Mounting the Broken System
Next, you’ll need to mount the broken system’s root partition to a temporary location. Create a new directory to serve as the mount point:
mkdir /mnt/broken
Then, mount the root partition to this directory:
mount /dev/sda1 /mnt/broken
Replace /dev/sda1 with the actual device name of your broken system’s root partition. The real trick is to make sure you’ve got the right partition - if you’re unsure, try mounting a different partition and see if it contains the files you expect.
Chrooting into the Broken System
Now that the broken system’s root partition is mounted, you can use the chroot command to change the root directory to the mounted partition. This will allow you to run commands as if you were logged into the broken system:
chroot /mnt/broken /bin/bash
This will drop you into a bash shell, where you can run commands to repair your broken system. Be careful what you do here - you’re essentially running commands as if you were logged into the broken system.
Repairing the Broken System
From within the chroot environment, you can run commands to repair your broken system. For example, if your system won’t boot due to a faulty kernel update, you can try reinstalling the kernel:
pacman -S linux
Or, if your system’s boot loader is corrupted, you can try reinstalling the boot loader:
grub-install --recheck /dev/sda
Replace /dev/sda with the actual device name of your system’s boot disk. This is where people usually get burned - they forget to replace the device name, and end up installing the boot loader to the wrong disk.
Troubleshooting Tips
When working with a broken system, it’s essential to be prepared for unexpected issues. Here are a few troubleshooting tips to keep in mind:
- Make sure you’ve mounted the correct partition. If you’re unsure, try mounting a different partition and see if it contains the files you expect.
- If you’re using a USB rescue shell, make sure it’s properly configured and that you’ve booted into the correct environment.
- Be careful when running commands within the chroot environment. Since you’re running commands as if you were logged into the broken system, you can potentially cause further damage if you’re not careful.
Common Pitfalls
When recovering a broken Linux system, there are a few common pitfalls to watch out for:
- Forgetting to mount the broken system’s root partition before chrooting into it. This can cause the
chrootcommand to fail or produce unexpected results. - Failing to identify the correct device name for the broken system’s root partition. This can cause you to mount the wrong partition, leading to further problems.
- Not being careful when running commands within the chroot environment. This can cause further damage to the broken system, making it even harder to recover.
Additional Resources
For more information on recovering a broken Linux system, check out the official Arch Linux wiki and the Linux kernel documentation website. These resources have been invaluable to me over the years, and I’m sure you’ll find them helpful too.
See also
- Taming Background Tasks with nohup and systemd: My Homelab Workflow
- Taming fstab: My Journey to Reliable Mounts and Easier Disk Management on Linux
- Taming Resource-Intensive Background Jobs with nice and ionice
- Taming Removable Device Chaos: Automatically Mounting and Naming Disks on Desktop Linux
- Taming systemd Service Restarts: When RestartSec Isn't Enough