Change root (chroot) in Linux


How to use Change root (chroot) in Linux?

The chroot command on the Linux / UNIX system changes the root directory. Each process/command system, such as systems, has a root directory known as the root directory. This changes the root directory for currently running processes and child processes.

A process that runs in a modified environment cannot access files outside the root directory. This modified environment is called "chroot prison" or "jail directory." Some root users can use the chroot command to use the privileges.

The "chroot" command will be handy:

  • To create a test environment.
  • To recover the system or password.
  • To reinstall the boot loader.

The Options are:

  • userspec=USER: GROUP –This option describes the user and the group to be tested. Either the user can be used to specify the user and numeric ID user and group.
  • -groups=G_LIST – This describes the supplementary groups as g1, g2,..gN.
  • -help - showing the help message and exit.
  • -version - Education information and exits.

What are the reasons to use chroot?

Changing root is usually done to make system maintenance on booting and logging systems impossible.

The typical examples are:

  • Reinstalling the bootloader.
  • Rebuilding the initramfs image.
  • Upgrading or downgrading packages.
  • Resetting a forgotten password.
  • Building software in a clean root environment.