Page MenuHomePhorge

Chroot
Updated 1,431 Days AgoPublic

I often want to mount a system in a chroot; I often forget all the specifics, and just end up Googling them to try and make sure I don't forget anything.


# First, mount the system as, say
sudo mount /dev/sda4 /mnt

# Then these are the bits from your running Linux system you need to mount into the chroot
mount -t proc proc /mnt/proc/
mount -t sysfs sys /mnt/sys/ 
mount -o bind /tmp /mnt/tmp/ 
mount -o bind /dev /mnt/dev/

Or a more complete approach:

# Mount the partition in question
sudo mount /dev/sda1 /mnt
# Mount the main shared system stuff
for name in proc sys dev; do sudo mount --bind /$name /mnt/$name; done
# Mount the resolv config for network resolution
sudo mount --bind /etc/resolv.conf /mnt/etc/resolv.conf
# Mount /dev/pts since it often complains if not
sudo mount --bind /dev/pts /mnt/dev/pts
# Explicitly chroot to a /bin/bash shell, because surely bash is there!
sudo chroot /mnt/ /bin/bash

External documentation:

Last Author
keithzg
Last Edited
Oct 7 2020, 12:19 AM