Chroot

From ArchWiki
Revision as of 01:29, 26 November 2009 by Gen2ly (talk | contribs)
Jump to: navigation, search

"[Changing Root] on Unix operating systems is an operation that changes the apparent disk root directory for the current running process and its children. A program that is re-rooted to another directory cannot access or name files outside that directory, and the directory is called a "chroot jail"..." [Wikipedia].

Changing root is at times necessary to perform various system operations. Examples would be to reinstall GRUB or to reset a forgotten password. Changing root is often done from from a LiveCD or LiveUSB to enter the installation root partition.

Mounting the device

First, the device or partition with the Linux system on it will need to be mounted. To discover the kernel name of the storage device name, type:

fdisk -l

Create a directory where you would like to mount the partition, then mount the device or partition:

mkdir /mnt/arch
mount /dev/<device-or-partition-name> /mnt/arch

Changing Root

Before you can chroot be sure that the environment architectures of both the current environment and install environment match. You can find the architecture of your current environment by:

uname -m

If you know they do, then you will need to mount the temporary filesystems:

mount -t proc none /mnt/arch/proc
mount -t sysfs none /mnt/arch/sys
mount -o bind /dev /mnt/arch/dev

Now chroot to your installed device or partition and define your shell:

chroot /mnt/arch /bin/bash

If this is a new install and you have yet to enter it, you will need to create an mtab file:

grep -v rootfs /proc/mounts > /etc/mtab

Exiting chroot

First the chroot shell must be exited:

exit

Then unmount the temporary filesystems and mounted devices then reboot:

umount /mnt/arch/{proc,sys,dev}
umount /mnt/arch
reboot