Info
Content

How To Chroot


Chroot is a command in Linux which my be used to change your active root directory.
Doing so will allow you to mount an operating system and act as if you were logged into it.

This operation is most commonly used from a live environment to fix a broken operating system (not booting for example), or make changes to a system you do not have access to. (no login credentials).

Before we may start the chroot, we'll have to make sure the correct mount points are set.
In the example I will use the mountpoint /mnt, as it already exists on most systems.
The location does not matter however, and can be changed to your wishes, as long as you're consistent with your syntax.

With our determined mountpoint in mind, we'll have to start mounting the filesystems of the system we will want to chroot to.
In the example below, the disk in question has three partitions, a /boot, swap and / partition.

Example disk:
/dev/sda1 = /boot
/dev/sda2 = swap
/dev/sda3 = /

We should now have all information required to be able to start the process.

mount /dev/sda3 /mnt
mount /dev/sda1 /mnt/boot

If any other partitions are present the system depends on/you will need access to, make sure they are mounted here as well. An example would be a seperate /home partition.

Next, some system dependencies will need to be mounted as well to ensure full functionality in the chroot.

mount -t proc none /mnt/proc
mount --rbind /dev /mnt/dev
mount --rbind /sys /mnt/sys

All mounts should be ready to start the chroot now.

chroot /mnt /bin/bash

You now have access to the 'chrooted' environment as if you were logged into it, with full functionality of the operating system.

No Comments
Back to top