chroot Command in Linux with Examples

This tutorial explains Linux “chroot” command, options and its usage with examples.

chroot – change root directory


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.




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.

Example :

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ 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.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.