How to Repair Broken Linux OS Using chroot
When a Linux operating system fails to boot due to a corrupted
kernel, broken package updates, or bootloader issues, the
chroot (change root) command provides a reliable recovery
method. By booting into a live Linux USB environment, you can access the
storage drives of the damaged installation and temporarily reassign the
root directory (/). This article explains how
chroot works, why it is essential for system rescue, and
the exact steps to enter and repair a broken Linux installation from a
live session.
What Does chroot Do?
The chroot command changes the apparent root directory
for the current running process and its children. Normally, a live
environment runs entirely in RAM with its own independent file system.
By using chroot, you redirect the live environment's shell
into the file system located on your computer's storage drive.
Once inside, any command you execute—such as package managers, bootloader installers, or configuration scripts—acts directly upon the installed, broken system rather than the temporary live environment.
Why chroot Is Necessary for Repairs
Certain recovery tasks cannot be performed by simply mounting a drive and editing configuration files:
- Reinstalling the Bootloader: Tools like
grub-installandupdate-grubneed to detect installed kernels and write directly to system directories and NVRAM. - Package Management: Updating or removing broken
packages with
apt,dnf, orpacmanrequires running the target system's package database and dependencies. - Kernel Image Generation: Rebuilding an initramfs
(using
mkinitcpioorupdate-initramfs) requires direct interaction with the system's installed modules and kernel versions. - Account Recovery: Resetting user or root passwords
using the
passwdcommand requires write access to the host authentication system.
How to Use chroot from a Live Environment
1. Identify and Mount the Partitions
Boot your machine into a live Linux distribution that shares the same architecture (e.g., 64-bit x86) as the installed OS. Open a terminal and locate your drives:
lsblkMount the root partition of your damaged operating system to
/mnt:
sudo mount /dev/sdXn /mnt(Replace /dev/sdXn with your actual root partition,
such as /dev/nvme0n1p2 or /dev/sda2).
If your system uses a separate boot or EFI system partition (ESP), mount it as well:
sudo mount /dev/sdX1 /mnt/boot/efi2. Bind Essential Virtual File Systems
For commands inside the chrooted environment to interact with the
system hardware, the running kernel must share its pseudo-filesystems
(/dev, /proc, /sys, and
/run) with the target directory:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /run /mnt/runIf internet access is required to download packages, copy your live environment's DNS configuration:
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf3. Enter the chroot Environment
Execute the chroot command targeting the mount
directory:
sudo chroot /mnt /bin/bashYour prompt will change to reflect that you are now the root user inside your installed, previously unbootable operating system.
Performing the Repair
Now inside the target system, run the necessary repair commands depending on the failure:
- Reinstall GRUB (UEFI):
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB update-grub - Fix Broken Packages (Debian/Ubuntu):
dpkg --configure -a apt install -f - Rebuild the Initial Ramdisk:
update-initramfs -u -k all
Exiting and Unmounting
Once the repairs are complete, exit the chroot environment:
exitUnmount all bound filesystems cleanly before rebooting to prevent disk corruption:
sudo umount -R /mnt
sudo rebootThe system will reboot directly into the repaired Linux installation.