Groot Simplifies Entering Chroot On Any Linux Distribution

Groot simplified chroot utility

Groot is a helper tool which simplifies the chroot operation. It is based on the arch-chroot script available for Arch Linux, and it can be used on any Linux distribution.

Chroot is an operation that changes the apparent root directory for the current running process and its children. It's especially useful for installing and updating packages on systems that cannot boot, for example reinstalling the GRUB bootloader (or some other bootloader), removing, downgrading or upgrading some package that breaks the boot process, and so on. Chroot is also useful for testing and development, and more.

As an example, let's say you have a Linux system that no longer boots. You can boot a live USB of some Linux distribution like Ubuntu on that computer, then use chroot to fix the bootloader of the original Linux distribution that's installed on that system. Both systems need to be using the same architecture.

This is what Groot does:

  • it automatically mounts and unmounts /dev, /run, /proc, /sys and other system directories
  • it enables Internet connection sharing, so you can run commands that require Internet access from the chroot session
  • it enables display sharing so you can run graphical applications that are installed on the chrooted system

Groot is only for chrooting into a Linux system right now, but the plan is to add some extra features, like repairing boot issues on BIOS and EFI systems, reinstall GRUB, rebuild initramfs, update the GRUB boot menu, etc.

Update. The latest Groot includes 3 new options:

  • --fixboot for fixing boot issues. This command will chroot into the specified directory, mount devices from fstab/crypttab files, rebuild initramfs, and update GRUB menu. It works on Linux distributions based on Ubuntu / Debian, Fedora and Arch Linux.
  • --update for installing package updates. This command will chroot into the specified directory, mount devices from fstab/crypttab files, and use the package manager to install available updates. It works on Linux distributions based on Ubuntu / Debian, Fedora and Arch Linux.
  • --guestinfo for showing guest system information.

To use Groot to chroot into a system, cd to the path where the root filesystem is mounted and then run Groot as root:

sudo groot

You can also specify the root filesystem path as an argument.

The tool can also chroot using the fstab file (which defines how disk partitions, remote filesystems and various block devices are mounted), mounting devices for /, /home, /boot, /boot/efi and so on, useful for fixing boot-related issues and reinstalling GRUB.

You can see exactly what Groot does when it runs by using the --verbose option. When you want to close Groot and exit chroot (and unmount all system directories it mounted), type exit.

Available Groot options:

$ groot --help

Groot v18.1 by Tony George (teejeetech@gmail.com)

Usage: groot [command] [basepath] [options]

Commands:
  --chroot             Change root to basepath (default if no command specified)
  --chroot-fstab       Change root after mounting devices from fstab and cryptab
  --list-devices       List current devices
  --sysinfo            Show current system information

Options:
  --no-display         Do not share display (default: sharing enabled)
  --no-internet        Do not share internet connection (default: sharing enabled)
  --verbose, -v        Show executed commands
  --debug              Show debug messages

To be able to run a graphical application from the chroot session, you need to run export DISPLAY=:0, or at least that was the case on my system (I was expecting Groot to do this, but it looks like it only runs xhost +local: automatically). So to run graphical applications using Groot, type this in the chroot:

export DISPLAY=:0

In some cases the $DISPLAY environment variable may not be :0. Type this on the current system (in the current system, not in the chroot):

echo $DISPLAY

And use the output from this instead of :0 in the export command above.

Then type the executable (like gedit, etc.) you want to run and it should work.

Download Groot



To be able to install the Groot DEB in an Ubuntu live session, you'll need to enable the universe repository from Software & Updates (second checkbox). Without this, some Groot dependencies will not be available for installation. Or you could simply use the Groot distro-agnostic (should work on any Linux distribution) one-liner from its GitHub page to install it.