debian_chroot - acis-acheron/acheron GitHub Wiki

Chroots on Debian

Debian develops a tool called debootstrap, which makes setting up a Debian-on-Debian chroot rather trivial. These chroots are a pretty nice and often-overlooked feature of the system, which can potentially be used to test and hack on various packages as root, with (minimal) harm to your normal system. It takes only around 5-10 minutes to get up-and-running with a new chroot, so they're easy to burn through. The only catch is, naturally, you're still using the same kernel, so some of our networking stuff will obviously not work.

Installing Debian Squeeze as a Chroot

All these commands should be executed as root:

aptitude install debootstrap
mkdir /squeeze_chroot # or whatever you want to call it
debootstrap squeeze ./squeeze_chroot http://ftp.us.debian.org/debian
# wait a few minutes (no intervention needed)
chroot /squeeze_chroot /bin/bash
aptitude install locales # keeps software from complaining about the locale
dpkg-reconfigure locales # I picked en_US.UTF-8

Now you can feel free to install packages to your heart's content. You may wish to write scripts to do some of this, in case you decide to make a new chroot later with a similar configuration.

Making the Actual Filesystem Accessible

The kernel will allow you to remount part of the filesystem elsewhere. This can be done (from outside the chroot, as root) with:

mkdir /squeeze_chroot/parent
mount --bind / /squeeze_chroot/parent

You can alternatively add an entry to /etc/fstab or /etc/fstab.d:

mkdir /squeeze_chroot/parent
echo "/ /squeeze_chroot/parent none bind" > /etc/fstab.d/squeeze_chroot

which will mount the filesystem on boot. (Although it's another thing to remember when you decide to remove the chroot)

warning

If you mount the actual filesystem, and then decide to remove the chroot with rm -rf, make sure you unmount your actual root filesystem first.