Proper CHROOT in rescue mode using arch-chroot

Insider Blog

Author

Bernd Helm

Characteristics

released:

April 17, 2020

categories:

What moves us

Most Sysadmins know how to set up a basic chroot on a mounted filesystem (mount-binding dev, proc and sys) but this does not work in any case; for a complete chroot setup you would aso need dev/pts dev/shm, run, tmp, a working resolve.conf and more. After you have set it up, and you want to bring it down, you have to do a lot of typing again. But wait! There is a better solution.

There is a script called arch-chroot shipped with the Archlinux distribution, but it is not limited to be run with Archlinux. It works on any linux distri!

For your convenience, I have created a gist for you. You can also use the Direct download link for wget.

you can install it like this:

wget https://gist.githubusercontent.com/bhelm/65283c37a0cb585089041214002df4f7/raw/536099a5f969a6888c85e48a487ec19870c596a2/arch-chroot.sh
chmod +x arch-chroot.sh
./arch-chroot.sh -h

Using this script, I was able to install grub without getting errors like:

grub-install: error: cannot find a device for /boot/grub (is /dev mounted?).
grub-probe: error: cannot find a device for / (is /dev mounted?).

If you are looking for a perfect rescue system, i recommend the archlinux install image; it contains the arch-chroot script, all low level tools needed to format hard drives and even supports mounting of ntfs read-write and accessing samba shares.

previous article
For developers, for store operators - We don't work with arbitrary frameworks, libraries, plugins and programming languages. We love it professionally. Software created at Helm & Walter should be powerful and lean. Here are our favorites: PHP (recursive acronym for PHP: hypertext preprocessor) is a widely used programming language for ...
June 27, 2017
Bernd Helm
next article
Most of the best BTRFS features are powered by the copy-on-write technology. If an application wants to rewrite a part of a file, like the first MB, the Data is not written in-place but in an so-called extend. This enables BTRFS to keep multiple versions of partially rewritten files with only claiming ...
October 21, 2020
Bernd Helm