sbuild
sbuild is used on the official buildd network to build binary packages for all supported architectures. It can also be used by individuals to prepare packages. Alternatives to sbuild are cowbuilder and pbuilder.
This page is intended as a short guide to sbuild. It documents how to set up sbuild and build packages with it, but intentionally does not document all possible options to keep it short and simple.
Setup
As root run
apt-get install sbuild user=$LOGNAME distribution=sid # default to host architecture. you can also use i386 on amd64 or vice versa architecture=$(dpkg --print-architecture) mirror=http://cdn.debian.net/debian sbuild-adduser $user sbuild-update --keygen # optional, but recommended if not using a local mirror: echo /var/cache/apt/archives /var/cache/apt/archives none rw,bind 0 0 >>/etc/schroot/sbuild/fstab mkdir -p /srv/chroot sbuild-createchroot --keyring=/etc/apt/trusted.gpg --arch=$architecture $distribution /srv/chroot/$distribution-$architecture-sbuild $mirror
IMPORTANT: until the bug 673676 will be solved, use this command (instead of the previous one):
sbuild-createchroot --keyring="" --arch=$architecture $distribution /srv/chroot/$distribution-$architecture-sbuild $mirror
# optional, but recommended: cd /; schroot -c $distribution-$architecture-sbuild apt-get install eatmydata # or, when using btrfs-snapshots (see below): # cd /; schroot -c source:$distribution-$architecture-sbuild apt-get install eatmydata echo command-prefix=eatmydata >> `ls /etc/schroot/chroot.d/$distribution-$architecture-sbuild*`
You can create additional chroots for different suites and architectures by starting from sbuild-createchroot with appropriate values for distribution and architecture.
Setup, with using btrfs snapshots
Using snapshots for the chroot environment allows to skip removing installed build dependencies and cleaning the build directory. One filesystem supporting this is btrfs, but it is also possible to use LVM snapshots or aufs/unionfs (see schroot.conf(5) for these).
To use btrfs snapshots with the above setup, make sure /srv/chroot is located on a btrfs filesystem and run
btrfs subvolume create /srv/chroot/$distribution-$architecture-sbuild
before sbuild-createchroot. After sbuild-createchroot run
mkdir -p /srv/chroot/snapshots sed -i "s,type=directory,type=btrfs-snapshot,; /directory=/ d" /etc/schroot/chroot.d/$distribution-$architecture-sbuild* cat >>/etc/schroot/chroot.d/$distribution-$architecture-sbuild* <<EOT btrfs-source-subvolume=/srv/chroot/$distribution-$architecture-sbuild btrfs-snapshot-directory=/srv/chroot/snapshots EOT
Usage
To build a package just run
sbuild -A -d sid
in the source directory. You can also specify a different architecture with --arch=$architecture or pass a .dsc file.
The chroot environment should be updated from time to time. Just run
sbuild-update -ugd sid
Again, use --arch=$architecture for a chroot environment for a architecture that differs from the host architecture.