A Gentoo chroot is the handoff point between a live environment and the installed root filesystem. If /proc, /sys, /dev, /run, or DNS resolution are missing, Portage and bootloader commands can fail inside a shell that otherwise looks like the target system.
The examples assume the Gentoo root filesystem is available at /mnt/gentoo. The host kernel still runs the process, while chroot changes the path view for the shell and its child processes. Bind mounts expose the kernel interfaces, device nodes, and runtime files that Gentoo tools expect during installation or repair work.
Use the sequence when resuming an interrupted install, repairing a bootloader, or entering a stage3 root from another Linux environment. Run the host-side commands as root or with sudo, load /etc/profile after entry, and keep the prompt marker until leaving the chroot so commands are not mistaken for host-side changes.
Related: How to build a Gentoo chroot environment
Related: How to install GRUB on Gentoo
Steps to enter a Gentoo chroot:
- Create the Gentoo mount point if it is missing.
$ sudo mkdir -p /mnt/gentoo
- Mount the Gentoo root filesystem.
$ sudo mount /dev/nvme0n1p3 /mnt/gentoo
Replace /dev/nvme0n1p3 with the real Gentoo root partition. Skip this step when the target root is already mounted at /mnt/gentoo.
- Copy the current resolver configuration into the target root.
$ sudo cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
–dereference copies the target of a symbolic link, which avoids leaving /mnt/gentoo/etc/resolv.conf pointing at a host path that does not exist inside the chroot.
- Mount /proc inside the Gentoo root.
$ sudo mount --types proc /proc /mnt/gentoo/proc
- Bind mount /sys into the Gentoo root.
$ sudo mount --rbind /sys /mnt/gentoo/sys
- Mark the /sys bind mount as recursive slave.
$ sudo mount --make-rslave /mnt/gentoo/sys
The recursive slave setting keeps later mount changes from propagating back into the host mount tree while still exposing submounts needed inside the chroot.
- Bind mount /dev into the Gentoo root.
$ sudo mount --rbind /dev /mnt/gentoo/dev
- Mark the /dev bind mount as recursive slave.
$ sudo mount --make-rslave /mnt/gentoo/dev
- Bind mount /run into the Gentoo root.
$ sudo mount --bind /run /mnt/gentoo/run
- Mark the /run bind mount as slave.
$ sudo mount --make-slave /mnt/gentoo/run
- Enter the Gentoo chroot.
$ sudo chroot /mnt/gentoo /bin/bash
- Load the Gentoo shell environment.
# source /etc/profile
- Mark the shell prompt as a chroot session.
# export PS1="(chroot) ${PS1}" - Confirm that the shell is reading Gentoo release data.
# cat /etc/gentoo-release Gentoo Base System release 2.18
- Confirm that the chroot shell sees /mnt/gentoo as its root.
# pwd /
- Confirm that /proc is available inside the chroot.
# ls /proc/self/mounts /proc/self/mounts
- Leave the chroot after the Gentoo work is complete.
# exit
- Unmount the Gentoo tree after no process is using it.
$ sudo umount -R /mnt/gentoo
Do not unmount /mnt/gentoo while another shell, package build, editor, or service still has files open inside the chroot.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.