This tutorial explains Linux “chroot” command, options and its usage with examples.
A chroot command on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children.When you change root to another directory you cannot access files and commands outside that directory.This directory is called a chroot jail. Changing root is commonly done for system maintenance, such as reinstalling the bootloader or resetting a forgotten password.
chroot NEWROOT [COMMAND [ARGS]…]
The root partition of the Linux system that you’re trying to chroot into needs to be mounted first using mount command. After that create a directory where you would like to mount the root partition and mount it and also mount all the separate partitions of the system.
While it’s possible to mount filesystems after you’ve chrooted, it is more convenient to do so beforehand. The reasoning for this is that you’ll have to unmount the temporary filesystems after you exit the chroot, so this lets you umount all the filesystems with a single command.
$ chroot /mnt/arch /usr/bin/bash
Using this command we change the root to /mnt/arch and we have defined the shell.
Note: If you see the error chroot: cannot run command ‘/usr/bin/bash’: Exec format error, it is likely that the two architectures do not match.(one on which the linux distribution is running and other one where we are changing root to)
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.