arch-chroot
Enter a chroot environment for package management
TLDR
Start an interactive shell (Bash, by default) in a new root directory
Specify the user (other than the current user) to run the shell as
Run a custom command (instead of the default Bash) in the new root directory
Specify the shell, other than the default Bash (in this case, the zsh package should have been installed in the target system)
SYNOPSIS
arch-chroot <newroot> [command...]
PARAMETERS
newroot
The absolute path to the directory that will serve as the new root environment (e.g., /mnt).
command...
Optional. A command to execute within the chroot environment. If omitted, arch-chroot will launch the default shell (usually Bash) in the new root.
DESCRIPTION
arch-chroot is a utility script provided by Arch Linux to simplify the process of chrooting into an Arch Linux installation. Unlike the standard chroot command, arch-chroot automates several critical steps required for a functional chroot environment, particularly useful during system installation, maintenance, or recovery. It automatically mounts essential pseudo-filesystems such as /proc, /sys, and /dev (including /dev/pts and /dev/shm) within the target root directory. Furthermore, it handles network connectivity by copying /etc/resolv.conf from the host system into the chroot, ensuring that package managers like pacman can access repositories. This automation significantly reduces common pitfalls and manual steps, making it much more robust and user-friendly for Arch Linux users. When invoked, it changes the root directory to the specified newroot and either drops the user into a shell or executes a given command. It attempts to clean up the bind mounts upon exiting the chroot.
CAVEATS
Requires root privileges to execute.
The main root directory (e.g., /mnt) must be mounted before running arch-chroot.
The host system's kernel is always used within the chroot environment, not the kernel installed in the newroot.
While arch-chroot attempts to unmount pseudo-filesystems on exit, the main newroot partition must be manually unmounted (e.g., using umount /mnt) after exiting the chroot.
AUTOMATED MOUNT POINTS
Automatically bind-mounts essential directories like /proc, /sys, /dev, /dev/pts, and /dev/shm from the host into the new root environment, ensuring a functional chroot.
NETWORK CONNECTIVITY
Copies the host system's /etc/resolv.conf into the chroot's /etc/resolv.conf, allowing applications within the chroot (like pacman) to resolve domain names and access network resources.
CLEAN EXIT
Upon exiting the chroot, the script attempts to automatically unmount the bind-mounted pseudo-filesystems, reducing the risk of busy mount points.
HISTORY
arch-chroot is a specific utility developed for Arch Linux as part of the arch-install-scripts package. Its development aimed to streamline and simplify the traditional chroot process, which, for a complete system, requires multiple bind mounts and configuration file adjustments (like resolv.conf). It abstracts these complexities, providing a more robust and user-friendly experience for Arch Linux users during initial installation, system recovery, or maintenance tasks, such as updating bootloaders or fixing broken packages. Its origins lie in addressing common challenges faced by users trying to set up a functional chroot manually.