Monday, September 07, 2009

setting up an Ubuntu chroot for development testing using schroot and debootstrap

If you have, for instance, an Ubuntu machine running Jaunty and you want to test a bug that only occurs under Karmic, you can use a chroot jail. This is cheaper and faster than setting up a whole vm, assuming you're not interested in kernel-level differences and you can tolerate a bit less isolation.

1- sudo apt-get install debootstrap schroot

2- Use debootstrap to make a minimal install of karmic into a directory:

sudo mkdir /home/chroot

sudo debootstrap karmic /home/chroot/karmic http://mirror.internode.on.net/pub/ubuntu/ubuntu/

Supply the name of your nearest Ubuntu mirror as the last parameter.

3- Put something like this at the end of /etc/schroot/schroot.conf:


[karmic]
description=Ubuntu 9.10 Karmic Koala
users=mbp
root-users=mbp
location=/home/chroot/karmic
type=directory
run-setup-scripts=true
run-exec-scripts=true


4- Voila:

schroot -c karmic

should give you a shell, running as yourself, in the karmic environment. schroot with these settings automatically arranges for your home directory to be shared, so you can get at the same source code from both places. (See /etc/schroot/mount-defaults.)

You won't, by default, have sudo access in that chroot, so you can either edit /home/chroot/karmic/etc/sudoers to allow it, or you can run commands like this from outside of the jail:

schroot -c karmic -u root apt-get install zlib1g-dev

To avoid confusion I like to show the OS version in my zsh prompt, with a line like this in my ~/.zshrc:


RPS1='%B%~ ('"`lsb_release -cs`"')%b'

No comments: