Fast clean chroot creation with LVM snapshots
Now that I've got a bit more disk space, I decided to fully script chroot creation with LVM snapshots.
This requires dchroot, LVM, and as as many logical volumes as you want chroots for, with a logical volume naming scheme like this:
apollock@caesar:~$ sudo lvs | grep pristine stable-pristine base -wi-a- 320.00M testing-pristine base -wi-a- 320.00M unstable-pristine base -wi-a- 320.00M
sudo makes life a bit easier as well.
Next, you need a directory structure like this:
apollock@caesar:~$ tree /chroots /chroots |-- pristine | |-- stable | |-- testing | `-- unstable |-- stable |-- testing `-- unstable
Finally, you need some /etc/fstab entries to mount the chroots (and a /proc):
/dev/base/stable-pristine /chroots/pristine/stable ext3 defaults,noauto 0 0 stable-proc /chroots/pristine/stable/proc proc defaults,noauto 0 0 /dev/base/testing-pristine /chroots/pristine/testing ext3 defaults,noauto 0 0 testing-proc /chroots/pristine/testing/proc proc defaults,noauto 0 0 /dev/base/unstable-pristine /chroots/pristine/unstable ext3 defaults,noauto 0 0 unstable-proc /chroots/pristine/unstable/proc proc defaults,noauto 0 0 /dev/base/stable /chroots/stable ext3 defaults,noauto 0 0 /dev/base/home /chroots/stable/home jfs defaults,noauto 0 0 /dev/base/tmp /chroots/stable/tmp jfs defaults,noauto 0 0 stable-proc /chroots/stable/proc proc defaults,noauto 0 0 /dev/base/testing /chroots/testing ext3 defaults,noauto 0 0 /dev/base/home /chroots/testing/home ext3 defaults,noauto 0 0 /dev/base/tmp /chroots/testing/tmp ext3 defaults,noauto 0 0 testing-proc /chroots/testing/proc proc defaults,noauto 0 0 /dev/base/unstable /chroots/unstable ext3 defaults,noauto 0 0 /dev/base/home /chroots/unstable/home ext3 defaults,noauto 0 0 /dev/base/tmp /chroots/unstable/tmp ext3 defaults,noauto 0 0 unstable-proc /chroots/unstable/proc proc defaults,noauto 0 0
Note that you don't need to bother double-mounting /home and /tmp in the "pristine" chroots, because generally speaking, only root will be logging into them, for the purposes of installing packages or upgrading what's already installed.
So firstly, create the logical volumes that are going to hold the "pristine" chroots. Put your favourite filesystem on them, and mount them. Then use debootstrap to install a base installation. I found I had more success doing an installation of sarge into the stable chroot's logical volume, and then dd'ing that across to the testing and unstable logical volumes, and doing a dist-upgrade afterwards.
Once you've got your base chroots installed, add entries to /etc/dchroot.conf for them, as well as the subsequent snapshot ones:
unstable /chroots/unstable testing /chroots/testing stable /chroots/stable unstable-pristine /chroots/pristine/unstable testing-pristine /chroots/pristine/testing stable-pristine /chroots/pristine/stable
Then use dchroot (as root) to log into each "pristine" chroot in turn and install build-essential, fakeroot, and whatever else you want to have consistently installed in each instance of the chroot.
Once you're done with this, you can use the couple of scripts I've knocked up for easily creating an instance of one of these pristine chroots. You can then install whatever packages you like into these instances, build your packages, and then when you're finished, just throw away the logical volume. You can rinse and repeat this process as much as you like, and it's as quick as creating a snapshot logical volume, giving you a clean chroot to start with every time.