linux/doc/Chroot.md

32 lines
842 B
Markdown
Raw Permalink Normal View History

2015-10-03 22:00:24 +02:00
# Setup a Chroot Environment
A `chroot` environment can be used to modify a system installed to a different location.
2015-12-14 03:13:59 +01:00
Combined with `aufs`, the technique can be used, for example, to modify a mounted ISO image.
2015-10-03 22:00:24 +02:00
## Setup
2015-12-14 03:13:59 +01:00
MNT=/mnt
2015-10-03 22:00:24 +02:00
mount -o bind /dev $MNT/dev
mount -o bind /dev/pts $MNT/dev/pts
mount -t proc none $MNT/proc
mount -t sysfs none $MNT/sys
cp /proc/mounts $MNT/etc/mtab
cp /etc/resolv.conf $MNT/etc/resolv.conf
chroot $MNT
2015-12-14 03:13:59 +01:00
`$MNT/etc/mtab` should be edited manually to correctly point to the root file system.
2015-10-03 22:00:24 +02:00
Umount the chroot environment:
umount $MNT/{sys,proc,dev/pts,dev}
echo > $MNT/etc/resolv.conf
rm $MNT/etc/mtab
## AUFS Overlay
2015-12-14 03:13:59 +01:00
Mount a writeable version of `/tmp/mnt/root` to `/tmp/mnt/rootrw`
2015-10-03 22:00:24 +02:00
2015-12-14 03:13:59 +01:00
mkdir -p /tmp/mnt/{root,rootrw,aufs}
mount -t aufs -o br:/tmp/mnt/aufs:/tmp/mnt/root none /tmp/mnt/rootrw