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:

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:

lsblk

Mount 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/efi

2. 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/run

If internet access is required to download packages, copy your live environment's DNS configuration:

sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

3. Enter the chroot Environment

Execute the chroot command targeting the mount directory:

sudo chroot /mnt /bin/bash

Your 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:

Exiting and Unmounting

Once the repairs are complete, exit the chroot environment:

exit

Unmount all bound filesystems cleanly before rebooting to prevent disk corruption:

sudo umount -R /mnt
sudo reboot

The system will reboot directly into the repaired Linux installation.