man sbuild-setup (Conventions) - sbuild setup procedure


sbuild-setup - sbuild setup procedure


sbuild uses chroots to build packages within, to provide a minimal and consistent build environment. This man page describes the procedure to create a chroot by hand using debootstrap. These are only guidelines; depending upon the setup required, several of the steps may be omitted entirely.

A number of the steps below are automatically run by the buildd.chroot script. See the section [lq]buildd.chroot[rq] below.


This guide sets up a sarge chroot on a powerpc machine. Adjust the names for other suites and architectures.

1. Run debootstrap to create the chroot

CR]# CB]mkdir -p /srv/chroot/sarge

The author has each chroot as a separate LVM logical volume (LV). Create and mount an LV here if required:

CR]# CB]lvcreate -L 4G -n sarge_chroot -Z y hda_vg

Add to /etc/fstab and mount (see next section for full fstab example). Finally, run debootstrap to create the chroot:

CR]# CB]debootstrap --variant=buildd /srv/chroot/sarge

2. Set up additional mounts

An example /etc/fstab:

lfCR s s s s s. /dev//hda_vg/sarge_chroot [rs] lfCR lfCR lfCR lfCR lfCR lfCR. /srv/chroot/sarge ext3 defaults 0 2 /dev/pts /srv/chroot/sarge/dev/pts none rw,bind 0 0 tmpfs /srv/chroot/sarge/dev/shm tmpfs defaults 0 0 proc /srv/chroot/sarge/proc proc defaults 0 0 lfCR s s s s s. /dev/hda_vg/home [rs] lfCR lfCR lfCR lfCR lfCR lfCR. /srv/chroot/sarge/home ext3 quota 0 0 /tmp /srv/chroot/sarge/tmp none rw,bind 0 0 /etc/passwd /srv/chroot/sarge/etc/passwd none ro,bind 0 0 /etc/shadow /srv/chroot/sarge/etc/shadow none ro,bind 0 0 /etc/group /srv/chroot/sarge/etc/group none ro,bind 0 0 lfCR s s s s s. /etc/resolv.conf [rs] lfCR lfCR s s s s. /srv/chroot/sarge/etc/resolv.conf [rs] lfCR lfCR lfCR lfCR lfCR lfCR. none ro,bind 0 0

If the bind mountpoints don't exist in the chroot, touch them:

CR]# CB]touch /srv/chroot/sarge/etc/resolv.conf

Next, mount them all.

Depending on your kernel version and security considerations, you may wish to do this part slightly differently. With a Linux kernel, at least version 2.6 is required for bind mounts, and devpts (CONFIG_UNIX98_PTYS) for /dev/pts. Other guides recommend copying the files, but this method keeps them up-to-date at no cost.

If using sbuild with schroot, passwd, shadow, group and resolv.conf can be updated automatically at the start of each build, so no action is required here. schroot can also automatically mount all of the extra filesystems, so all the other mounts may be omitted.

To disable networking, don't bind mount /etc/resolv.conf. This will prevent APT from working inside the chroot, but prevents package building from having working network access (no nameservers).

3. Edit BI]sources.list

Create or edit /srv/chroot/sarge/etc/apt/sources.list, and add all the APT sources required to obtain binary and source packages for your chosen distribution:

CR]deb sarge/updates main

CR]deb-src sarge/updates main


CR]deb sarge main

CR]deb-src sarge main

4. Configure dchroot or schroot

This is entirely optional, but will make the chroot environment easier to access and administer.

For dchroot, add the following line to /etc/dchroot.conf:

CR]sarge /srv/chroot/sarge

For schroot, add the a group to /etc/schroot/schroot.conf, for example:



CR]description=Debian sarge (stable)








5. Log into chroot

CR]# CB]dchroot -c sarge


CR]$ CB]schroot -c sarge -u root

6. Set up packages for sbuild

While running as root inside the chroot:

CR]# CB]apt-get update

CR]# CB]apt-get dist-upgrade

CR]# CB]apt-get install debconf

CR]# CB]dpkg-reconfigure -plow debconf

Answer the debconf questions as follows:

choose 6/Noninteractive
choose 1/Critical

You only need to run dpkg-reconfigure if you weren't asked the questions during the debconf install. Next, install the packages required for building packages:

CR]# CB]apt-get install sudo debfoster fakeroot build-essential

CR]# CB]apt-get install makedev

CR]# CB]cd /dev/

CR]# CB]/sbin/MAKEDEV generic

CR]# CB]touch /etc/mtab

For some security, we don't bind mount /dev, so it can't access e.g. USB devices

7. sbuild setup

While running as root inside the chroot:

CR]# CB]mkdir /build

CR]# CB]chown root:sbuild /build

CR]# CB]mkdir -p /var/lib/sbuild/srcdep-lock

CR]# CB]chown -R root:sbuild /var/lib/sbuild

CR]# CB]chmod -R 02775 /var/lib/sbuild

Note that when using sbuild with schroot, this setup is done at the start of each build, so is not required here.

8. Finished

Congratulations! You should now have a fully configured and operational chroot.


This script, located in /usr/share/sbuild will automatically do a number of the steps described above, including:

Running debootstrap.
Setting up APT sources in /etc/apt/sources.list.
Setting up a minimal /etc/passwd
Setting up /build and /var/lib/sbuild with appropriate ownership and permissions.

After it has done this, you do still need to do some manual setup, completing the steps it missed out above, for example.


1. BI]~/.sbuildrc

Configure the user's ~.sbuildrc:

CR]$ CB]cp /usr/share/doc/sbuild/examples/example.sbuildrc ~/.sbuildrc

Edit to set the correct mail address to send log files to, and the correct maintainer name and/or uploader name.

2. Build directories

Create the required build directories (The .sbuildrc may have configured different locations; these are the defaults):

CR]$ CB]mkdir ~/build ~/logs

3. Chroot setup

As root, run:

CR]# CB]/usr/share/sbuild/add_sbuild_user /srv/chroot/sarge stable <username>

Follow the instructions displayed, and update ~/build etc. as shown.

4. sudo setup

If using sbuild with sudo (chroot_mode [lq]split[rq]), sudo needs configuring to give the user permission to install and remove packages in the chroot, which requires root priveleges. Add the following lines to /etc/sudoers


CR]Defaults:CI]username env_keep+="APT_CONFIG DEBIAN_FRONTEND"

where username is the name of the user who will run sbuild. /etc/sudoers inside the chroot also needs the same modifications.

5. Finished

You should now be able to run sbuild.

CR]$ CB]cd ~/build

CR]$ CB]sbuild ...


A script to automatically create and configure a chroot using debootstrap.


Roger Leigh.


Copyright © 2005-2006 Roger Leigh <>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.