Installing a chrooted Ubuntu installation (i.e. creating one from scratch) is quite easy. All it takes is a lot of bandwidth, because each chroot installation needs to download about 200MB from the internet. You can save bandwidth by setting up an apt proxy (I use approx, available in the Ubuntu repositories) on your computer or server first, but that’s another story.
When you manually install Ubuntu with debootstrap, the initial setup of the environment is quite different from when you install Ubuntu off the normal installer CDs. There are a few tweaks you have to make to get it out of its default state of insanity for most cases.
First of all, it’s quite easy to make a chroot. Syntax is like this:
sudo debootstrap --arch=i386 hardy \
/wherever/you/want/to/put/the/chroot \
http://your.isp.mirror/pub/ubuntu
When chrooting into the environment for the first time (and upon subsequent reboots of your computer, as well), you should run the following commands first outside the chroot, otherwise you can get quite strange errors. (Source: Ubuntu 6.06 Live CD customisation guide)
mount -t proc none path_to_chroot/proc/
mount -t sysfs none path_to_chroot/sys/
mount -o bind /dev path_to_chroot/dev/
Also, to get X apps working, type this outside your chroot:
xhost +
mount -o bind /tmp wherever_your_chroot_is/tmp/
I once had a problem with installing the dbus package. For some reason, the dbus-daemon process just bombed out. Eventually, I found the problem was related to forgetting to mount the /proc and /sys directories, so don’t forget to run the above lines.
If Perl complains while being invoked (for example, when installing packages), run the following commands:
export LC_ALL=C
sudo dpkg-reconfigure locales
Your chroot environment may or may not be able to access the internet. In order for it to translate host names (www.google.com) to IP addresses (66.102.7.104) it needs to know about your DNS server.
From outside your chroot environment, run the following:
sudo cp /etc/resolv.conf wherever_your_chroot_is/etc/
resolv.conf is a configuration that simply contains the IP addresses of the DNS servers that the computer knows about. Normally, whenever you connect to a Local Area Network and use DHCP to get an IP address, the resolv.conf file is automatically updated. Because the chroot uses the already-existing network, it doesn’t have to use DHCP, but that means the resolv.conf doesn’t get updated automatically.
If you’re using approx to cache your packages, or your ISP mirrors Ubuntu, copy your local sources.list file into the chroot (be careful if your distro version is different to the distro inside the chroot) so as to download from the same location:
sudo cp /etc/apt/sources.list wherever_your_chroot_is/etc/apt/
Now, if you want to boot into the chroot later on, you’ll find that you have no way to log on. That’s because there is no root password set by default. You’ll want to set it from inside the chroot:
passwd root
That’s all I have for now. If anybody has any improvements they want to suggest, please tell me in the comments, so I can add it to the article!
Soon to come: a script I wrote which automates most of this!