This page has not been updated since its creation in 2011. The mk-sbuild tool is a Ubuntu-specific script from the ubuntu-dev-tools package. If you want an easy way to set up sbuild with good defaults, consider installing the sbuild-debian-developer-setup package. For more information, see the wiki entry for sbuild.

using mk-sbuild, schroot, and sbuild

The mk-sbuild tool is designed to create a full sbuild-with-schroot environment to do builds. One benefit of this is that you also end up with functional chroot environments as well.

Initial Setup

The first time you run mk-sbuild (found in the ubuntu-dev-tools package), it will add your user to the sbuild group, and install various needed packages. After that, you just need to request the release you want to create a chroot for. If you want to have "debuild" available in the chroot, include "devscripts" as an explicit additional package to install, otherwise the chroot will be as minimal as possible:

mk-sbuild --debootstrap-include=devscripts unstable

Note: at this time (2020/12) including devscripts throws an error because of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=878961:

If you want to create a chroot for Ubuntu, you'll need to install the ubuntu-archive-keyring package first, as that contains the archive key used to sign packages in Ubuntu.

The chroot would be configured in schroot (see /etc/schroot), and debootstrap will be run. One successful completion, it will report:

 To CHANGE the golden image: sudo schroot -c CHROOT_NAME-source -u root"
 To ENTER an image snapshot: schroot -c CHROOT_NAME
 To BUILD within a snapshot: sbuild -A -d CHROOT_NAME PACKAGE*.dsc"

Where CHROOT_NAME is the release you gave, with the default architecture appended. For example, on an amd64 system, installing unstable, it would be named unstable-amd64. The name and architecture are selectable with command-line options. See man mk-sbuild for details.

To avoid needing sudo, you can adjust /etc/schroot/chroot.d/CHROOT_NAME.conf and uncomment the following line:

source-root-groups=root,sbuild,admin

This will let you enter the chroot as the root user. Use wisely, as root in a chroot is just as powerful as root outside a chroot.

Using schroot to build packages

To see the list of available chroots, run:

schroot -l

To enter a copy of the chroot, run:

schroot -u root -c CHROOT_NAME

where CHROOT_NAME is the chroot you created earlier (e.g. unstable-amd64, unstable-i386, etc). From here, you can install deps:

apt-get build-dep PACKAGE

where PACKAGE is the package you want to work on. When you're ready to build packages, switch to a non-root user, and do what you need to do outside the chroot:

apt-get source PACKAGE
cd PACKAGE-*
dch -i
edit!

And do the build inside the chroot:

su builder
debuild -uc -us

When you're ready for a source build, inside the chroot:

debuild -S -uc -us

This will generate a .dsc file, which you give to sbuild (see next section).

Using sbuild

To use sbuild, you'll need a source package (with a .dsc file -- see above). Outside your chroots, you can build using sbuild via:

sbuild --arch-all -c CHROOT_NAME PACKAGE*.dsc

And everything will happen automatically.