This document describes the steps to setup a chroot with schroot on an LVM LV, so that you can build packages on an LVM LV snapshot. It tries to provide an alternative to PbuilderHowto. It assumes a passing understanding of LVM, and having an available VG to work with.

The script mk-sbuild is used to initialize each schroot. It was written based on the original implementation of this How-To, and incorporates additional recommendations from sbuild-setup(7). It is part of the ubuntu-dev-tools package.

The following assume you want to install hardy. If you need a dapper, edgy, feisty or gutsy chroot, then exchange hardy with the appropriate distribution.

LVM requirements

For the schroots to be useful, you will need a good bit of free space in your VG. By default, each schroot takes 5G, and each time you run an sbuild, it will temporarily allocate 4G for filesystem change in the LVM snapshot until the sbuild finishes. To see available VG space:

sudo vgs

Getting started

The first time you run mk-sbuild, it will attempt to get everything set up for first-time use:


It performs the following steps:

  • installs the required packages (you will be prompted for your password for the sudo)
  • starts an editor on your ~/.sbuildrc (you need to fill in $mailto and $maintainer_name)
  • adds your current user id to the "sbuild" group (so you can run sbuild/schroot correctly)

After this finishes, you must re-log-in!

Adding a schroot

To create a schroot, run the script with two arguments, the VG you want to allocate the LV into, and the release to install:

$ mk-sbuild --vg=storagevg hardy

Alternatively, without passing --vg, aufs support will be used creating the chroot in /var/lib/schroot/chroots.

$ mk-sbuild hardy

If you have an amd64 host and you want to have i386 schroots, you can add the optional --arch and --personality options:

mk-sbuild --arch i386 --personality=linux32 --vg=storagevg hardy

This will do the following steps:

  • allocates a LV named "$RELEASE_chroot" (with "-$ARCH" appended if not the native arch)
  • makes an ext3 on the LV
  • runs debootstrap on the LV for the specified release

  • installs a default source.lists
  • installs a default schroot.conf entry
  • updates packages, installs build-essential and keyring, drops debconf to Noninteractive, and builds some needed symlinks

There are other options available:

man mk-sbuild

Alternate sources.list

If you want to use a different sources.list, you can create ~/.mk-sbuild-lv.sources where RELEASE will be automatically replaced by the release being installed:

deb RELEASE main restricted universe multiverse
deb-src RELEASE main restricted universe multiverse
deb RELEASE-updates main restricted universe multiverse
deb-src RELEASE-updates main restricted universe multiverse
deb RELEASE-security main restricted universe multiverse
deb-src RELEASE-security main restricted universe multiverse

This can be combined with an apt proxy (such as apt-cacher, apt-proxy, apt-cacher-ng) or even a local ubuntu mirror (managed with debmirror or apt-mirror, but requires a lot of disk space). It will greatly speed up the build process as packages will only be fetched once from the network and then served from the local cache.

The alternate sources.list file can also be specified on the command line using --source-template.

Another useful option is --debootstrap-mirror: it can be used to specify which mirror debootstrap should use when creating the initial chroot.

Alternate schroot.conf entry

If you want to use a different schroot.conf entry template, you can create ~/.mk-sbuild-lv.schroot.conf where CHROOT_NAME, CHROOT_PATH will be automatically replaced by the configured items:

mount-options=-o noatime
lvm-snapshot-options=--size 4G

More information about the available options can be found in the schroot.conf man page:

man schroot.conf

Using sbuild

Once the schroot is built, you can enter a snapshot with:

schroot -c hardy -u root

To make modifications to the snapshot origin LV you can append "-source" to the name of the schroot. Any changes made will appear in all subsequence schroot snapshots:

schroot -c hardy-source -u root

To build a package in your schroot, use sbuild:

sbuild -d hardy PACKAGE_*.dsc

Keeping your chroots up-to-date

You can use the following shell script to update all your chroots:

for d in `schroot -l | grep -- '-source$'`
        schroot -q -c $d -u root -- sh -c \
           'apt-get -qq update && apt-get -qy dist-upgrade && apt-get clean'

Drop it in /etc/cron.daily/ and you'll always have up-to-date chroots !

Managing build log files

sbuild keeps a log of each package build. The directory where the logs are stored is defined in sbuild configuration file (.sbuildrc). sbuild will also email the logs to a specified address.

If sending an email is not necessary, a local alias can be setup in /etc/aliases on the build machine that points to /dev/null:

buildlogs: /dev/null

Don't forget to run newaliases to update the database:

sudo newaliases

sbuild can then be modified to send build logs to the alias in .sbuildrc:

$mailto = 'buildlogs';

Managing old build log files is also advisable. The following script will compress log files older than 2 days, move them into an archive/ sub-directory and delete compressed log files older than 90 days:


find ${SBUILD_LOG_DIR} -atime +2 -a -type f -exec gzip '-q' '{}' ';' 
if ls  ${SBUILD_LOG_DIR} | grep -q gz$
find  ${SBUILD_LOG_ARCHIVE} -atime +90 -exec rm -f '{}' ';'

Adjust the location of the build log directory and drop it in /etc/cron.daily.

Instructions for Dapper

Installing required packages on dapper

You need a very recent version of schroot. I used version 0.2.8-1ubuntu1 for this Howto.

Just install the following packages on a dapper system:

apt-get install schroot sbuild

creating lvm volumes

in order to create an lvm volume, you first need to prepare one or more partitions (or other block devices) for use as physical volume:

pvcreate /dev/md1

Then you add these physical volumes to a new volume group:

vgcreate data00 /dev/md1

Once this is done, you can now create a new logical volume. The following commands creates a new logical volume 'dapper_chroot' with the size of 5GB in a volumegroup called 'data00':

lvcreate -n dapper_chroot -L 5g data00

you can now create a filesystem on it and mount it:

mkfs -t ext3 /dev/data00/dapper_chroot
mount /dev/data00/dapper_chroot /mnt

bootstrapping a base system

Now you can bootstrap your favorite distribution on that:

debootstrap dapper /mnt

Perhaps you want your /etc/sudoers and sources.list copied into that chroot, so that you can easily become root inside:

sudo cp /etc/sudoers /mnt/etc
sudo cp /etc/apt/sources.list /mnt/etc/apt

Unmount this temporary mountpoint now, schroot will mount it itself:

umount /mnt

configuring schroot

edit '/etc/schroot/schroot.conf' to contain this stanza:

description=Ubuntu Dapper
mount-options=-o noatime
lvm-snapshot-options=--size 1G

Entering the chroot

If you want to change the 'original' chroot, you can chroot into that with the following command:

schroot -c dapper-source

All changes you make there are persistent. So if you want to upgrade that chroot, use the following commands:

schroot -c dapper-source -u root -- apt-get update
schroot -c dapper-source -u root -- apt-get -y dist-upgrade 
schroot -c dapper-source -u root -- apt-get install build-essential ubuntu-minimal fakeroot devscripts

To enter the chroot on an lvm snapshot, use this command:

schroot -c dapper

Thanks to the session scripts, some directories, like /home, /proc, /sys and /tmp are mounted for you. You can modify/add session scripts in /etc/schroot/setup.d/*


For proper support for schroot, make sure you are in the system group 'sbuild'.

Create a file called '~/.sbuildrc' with the following contents:

# Mail address where logs are sent to (mandatory, no default!)
$mailto = "root";

# Name to use as override in .changes files for the Maintainer: field
# (mandatory, no default!).
$maintainer_name='Reinhard Tartler <>';

# Chroot behaviour; possible values are "split" (apt and dpkg are run
# from the host system) and "schroot" (all package operations are done in
# the chroot with schroot, but the chroot must allow networking)
$chroot_mode = "schroot";

# don't remove this, Perl needs it:

building packages

You can build now packages with the following command on lvm snapshots:

sbuild -d dapper package_1.2.3-4.dsc

If anything goes wrong, use parameters '-v -D' to debug.

Good Luck!


Is it possible to have something like "when the build fails drop to a shell", allowing you to inspect the build (failure)? PBuilder supports this via hooks, for example.

SbuildLVMHowto (last edited 2013-01-17 18:28:21 by brian-murray)