by richard on Fri, 12/09/2011 - 08:59

A Chroot environment is usually a folder on your filesystem that contains the entire base system for an operating system.

This tutorial will assume you are installing debian squeeze into a folder /chroot/squeeze

You can create a chroot environment itself using debootstrap.

richard@vpceh:~$ debootstrap squeeze /chroot/squeeze http://ftp.uk.debian.org/debian

That sets up the base packages, and then you need to mount the extra filesystems, and create the list of mounted systems.

The /dev filesystem contains all the device nodes for your system. I find it easiest to bind-mount this from the host operating system.

richard@vpceh:~$ sudo mount -o bind /dev /chroot/squeeze/dev

The /proc filesystem contains information about current running processes. This is mounted using the following command

richard@vpceh:~$ sudo mount -t proc none /chroot/squeeze/proc

you can then chroot into the system using the command

richard@vpceh:~$ sudo chroot /chroot/squeeze /bin/bash

Finally, just read the mounted filesystems into /etc/mtab by running

root@vpceh:/# cat /proc/mounts > /etc/mtab

and then you can perform operations as if you were on your own base system :)