pbuilder User's Manual

Usage and operations

Junichi Uekawa

documentation in progress


Table of Contents

1. Introducing pbuilder
1. Aims of pbuilder
2. Using pbuilder
1. Creating a base chroot image tar-ball
2. Updating the base.tgz
3. Building a package using the base.tgz
4. Facilitating Debian Developers' typing, pdebuild
5. Configuration Files
6. Building packages as non-root inside the chroot
7. Using pbuilder for back-porting
8. Mass-building packages
9. Auto-backporting scripts
10. Using pbuilder for automated testing of packages
11. Using pbuilder for testing builds with alternate compilers
3. Using User-mode-linux with pbuilder
1. Configuring user-mode-linux
2. Configuring rootstrap
3. Configuring pbuilder-uml
4. Considerations for running pbuilder-user-mode-linux
5. Parallel running of pbuilder-user-mode-linux
6. Using pbuilder-user-mode-linux as a wrapper script to start up a virtual machine
4. Frequently asked questions
1. pbuilder create fails
2. Directories that cannot be bind-mounted
3. Logging in to pbuilder to investigate build failure
4. Logging in to pbuilder to modify the environment
5. Setting BUILDRESULTUID for sudo sessions
6. Notes on usage of $TMPDIR
7. Creating a shortcut for running pbuilder with a specific distribution
8. Using environmental variables for running pbuilder for specific distribution
9. Using special apt sources lists, and local packages
10. How to get pbuilder to run apt-get update before trying to satisfy build-dependency
11. Different bash prompts inside pbuilder login
12. Creating a chroot reminder
13. Using /var/cache/apt/archives for the package cache
14. pbuilder back ported to stable Debian releases
15. Warning about LOGNAME not being defined
16. Cannot Build-conflict against an essential package
17. Avoiding the "ln: Invalid cross-device link" message
18. Using fakechroot
19. Using debconf inside pbuilder sessions
20. nodev mount options hinder pbuilder activity
21. pbuilder is slow
22. Using pdebuild to sponsor package
23. Why is there a source.changes file in ../?
24. amd64 and i386-mode
25. Using tmpfs for buildplace
26. Using svn-buildpackage together with pbuilder
5. Troubleshooting and development
1. Reporting bugs
2. Mailing list
3. IRC Channel
4. Information for pbuilder developers
6. Other uses of pbuilder
1. Using pbuilder for small experiments
2. Running little programs inside the chroot
7. Experimental or wish-list features of pbuilder
1. Using LVM
2. Using cowdancer
3. Using pbuilder without tar.gz
4. Using pbuilder in a vserver
5. Usage of ccache
8. Reference materials
1. Directory structure outside the chroot
2. Directory structure inside the chroot
9. Minor archaeological details
1. Documentation history
2. Possibly inaccurate Background History of pbuilder
2.1. The Time Before pbuilder
2.2. Birth of pbuilder
2.3. And the second year of its life
2.4. Fifth year of pbuilder

List of Tables

5.1. Directory structure of the testsuite
8.1. Directory Structure outside the chroot
8.2. Directory Structure inside the chroot

Chapter 1. Introducing pbuilder

Table of Contents

1. Aims of pbuilder

1. Aims of pbuilder

pbuilder stands for Personal Builder, and it is an automatic Debian Package Building system for personal development workstation environments. pbuilder aims to be an easy-to-setup system for auto-building Debian packages inside a clean-room environment, so that it is possible to verify that a package can be built on most Debian installations. The clean-room environment is achieved through the use of a base chroot image, so that only minimal packages will be installed inside the chroot.

The Debian distribution consists of free software accompanied with source. The source code within Debian's "main" section must build within Debian "main", with only the explicitly specified build-dependencies installed.

The primary aim of pbuilder is different from other auto-building systems in Debian in that its aim is not to try to build as many packages as possible. It does not try to guess what a package needs, and in most cases it tries the worst choice of all if there is a choice to be made.

In this way, pbuilder tries to ensure that packages tested against pbuilder will build properly in most Debian installations, hopefully resulting in a good overall Debian source-buildability.

The goal of making Debian buildable from source is somewhat accomplished, and has seen good progress. In the past age of Debian 3.0, there were many problems when building from source. More recent versions of Debian is much better.

Chapter 2. Using pbuilder

There are several simple commands for operation. pbuilder create, pbuilder update, and pbuilder build commands are the typical commands used. Let us look at the commands one by one.

1. Creating a base chroot image tar-ball

pbuilder create will create a base chroot image tar-ball (base.tgz). All other commands will operate on the resulting base.tgz If the Debian release to be created within chroot is not going to be "sid" (which is the default), the distribution code-name needs to be specified with the --distribution command-line option.

debootstrap [1] is used to create the bare minimum Debian installation, and then build-essential packages are installed on top of the minimum installation using apt-get inside the chroot.

For fuller documentation of command-line options, see the pbuilder.8 manual page. Some configuration will be required for /etc/pbuilderrc for the mirror site [2] to use, and proxy configuration may be required to allow access through HTTP. See the pbuilderrc.5 manual page for details.

2. Updating the base.tgz

pbuilder update will update the base.tgz. It will extract the chroot, invoke apt-get update and apt-get dist-upgrade inside the chroot, and then recreate the base.tgz (the base tar-ball.)

It is possible to switch the distribution which the base.tgz is targeted at at this point. Specify --distribution sid --override-config to change the distribution to sid. [3]

For fuller documentation of command-line options, see the pbuilder.8 manual page

3. Building a package using the base.tgz

To build a package inside the chroot, invoke pbuilder build whatever.dsc. pbuilder will extract the base.tgz to a temporary working directory, enter the directory with chroot, satisfy the build-dependencies inside chroot, and build the package. The built packages will be moved to a directory specified with the --buildresult command-line option.

The --basetgz option can be used to specify which base.tgz to use.

pbuilder will extract a fresh base chroot image from base.tgz. (base.tgz is created with pbuilder create, and updated with pbuilder update). The chroot is populated with build-dependencies by parsing debian/control and invoking apt-get.

For fuller documentation of command-line options, see the pbuilder.8 manual page

4. Facilitating Debian Developers' typing, pdebuild

pdebuild is a little wrapper script that does the most frequent of all tasks. A Debian Developer may try to do debuild, and build a package, inside a Debian source directory. pdebuild will allow similar control, and allow package to be built inside the chroot, to check that the current source tree will build happily inside the chroot.

pdebuild calls dpkg-source to build the source packages, and then invokes pbuilder on the resulting source package. However, unlike debuild, the resulting deb files will be found in the --buildresult directory.

See the pdebuild.1 manual page for more details.

There is a slightly different mode of operation available in pdebuild since version 0.97. pdebuild usually runs debian/rules clean outside of the chroot; however, it is possible to change the behavior to run it inside the chroot with the --use-pdebuild-internal. It will try to bind mount the working directory inside chroot, and run dpkg-buildpackage inside. It has the following characteristics, and is not yet the default mode of operation.

  • Satisfies build-dependency inside the chroot before creating source package. (which is a good point that default pdebuild could not do).

  • The working directory is modified from inside the chroot.

  • Building with pdebuild does not guarantee that it works with pbuilder.

  • If making the source package fails, the session using the chroot is wasted (chroot creation takes a bit of time, which should be improved with cowdancer).

  • Does not work in the same manner as it used to; for example, --buildresult does not have any effect.

  • The build inside chroot is ran with the current user outside chroot.

5. Configuration Files

It is possible to specify all settings by command-line options. However, for typing convenience, it is possible to use a configuration file.

/etc/pbuilderrc and ${HOME}/.pbuilderrc are read in when pbuilder is invoked. The possible options are documented in the pbuilderrc.5 manual page.

It is useful to use --configfile option to load up a preset configuration file when switching between configuration files for different distributions.

Please note ${HOME}/.pbuilderrc supersede system settings. Caveats is that if you have some configuration, you may need to tweak the configuration to work with new versions of pbuilder when upgrading.

6. Building packages as non-root inside the chroot

pbuilder requires full root privilege when it is satisfying the build-dependencies, but most packages do not need root privilege to build, or even refused to build when they are built as root. pbuilder can create a user which is only used inside pbuilder and use that user id when building, and use the fakeroot command when root privilege is required.

BUILDUSERID configuration option should be set to a value for a user id that does not already exist on the system, so that it is more difficult for packages that are being built with pbuilder to affect the environment outside the chroot. When BUILDUSERNAME configuration option is also set, pbuilder will use the specified user name and fakeroot for building packages, instead of running as root inside chroot.

Even when using the fakerooting method, pbuilder will run with root privilege when it is required. For example, when installing packages to the chroot, pbuilder will run under root privilege.

To be able to invoke pbuilder without being root, you need to use user-mode-linux, as explained in Chapter 3, Using User-mode-linux with pbuilder.

7. Using pbuilder for back-porting

pbuilder can be used for back-porting software from the latest Debian distribution to the older stable distribution, by using a chroot that contains an image of the older distribution, and building packages inside the chroot. There are several points to consider, and due to the following reasons, automatic back-porting is usually not possible, and manual interaction is required:

  • The package from the unstable distribution may depend on packages or versions of packages which are only available in unstable. Thus, it may not be possible to satisfy Build-Depends: on stable (without additional backporting work).

  • The stable distribution may have bugs that have been fixed in unstable which need to be worked around.

  • The package in the unstable distribution may have problems building even on unstable.

8. Mass-building packages

pbuilder can be automated, because its operations are non-interactive. It is possible to run pbuilder through multiple packages non-interactively. Several such scripts are known to exist. Junichi Uekawa has been running such a script since 2001, and has been filing bugs on packages that fail the test of pbuilder. There were several problems with auto-building:

  • Build-Dependencies need to install non-interactively, but some packages are so broken that they cannot install without interaction (like postgresql).

  • When a library package breaks, or gcc/gcj/g++ breaks, or even bison, a large number of build failures are reported. (gcj-3.0 which had no "javac", bison which got more strict, etc.)

  • Some people were quite hostile against build failure reports.

Most of the initial bugs have been resolved in the pbuilder sweep done around 2002, but these transitional problems which affect a large portion of Debian Archive do arise from time to time. Regression tests have their values.

A script that was used by Junichi Uekawa in the initial run is now included in the pbuilder distribution, as pbuildd.sh. It is available in /usr/share/doc/pbuilder/examples/pbuildd/ and its configuration is in /etc/pbuilder/pbuildd-config.sh. It should be easy enough to set up for people who are used to pbuilder. It has been running for quite a while, and it should be possible to set the application up on your system also. This version of the code is not the most tested, but should function as a starter.

To set up pbuildd, there are some points to be aware of.

  • A file ./avoidlist needs to be available with the list of packages to avoid building.

  • It will try building anything, even packages which are not aimed for your architecture.

  • Because you are running random build scripts, it is better to use the fakeroot option of pbuilder, to avoid running the build under root privilege.

  • Because not all builds are guaranteed to finish in a finite time, setting a timeout is probably necessary, or pbuildd may stall with a bad build.

  • Some packages require a lot of disk space, around 2GB seems to be sufficient for the largest packages for the time being. If you find otherwise, please inform the maintainer of this documentation.

9. Auto-backporting scripts

There are some people who use pbuilder to automatically back-port a subset of packages to the stable distribution.

I would like some information on how people are doing it, I would appreciate any feedback or information on how you are doing, or any examples.

10. Using pbuilder for automated testing of packages

pbuilder can be used for automated testing of packages. It has the feature of allowing hooks to be placed, and these hooks can try to install packages inside the chroot, or run them, or whatever else that can be done. Some known tests and ideas:

  • Automatic install-remove-upgrade-remove-install-purge-upgrade-purge test-suite (distributed as an example, B91dpkg-i), or just check that everything installs somewhat (execute_installtest.sh).

  • Automatically running lintian (distributed as an example in /usr/share/doc/pbuilder/examples/B90lintian).

  • Automatic debian-test of the package? The debian-test package has been removed from Debian. A pbuilder implementation can be found as debian/pbuilder-test directory, implemented through B92test-pkg script.

To use B92test-pkg script, first, add it to your hook directory. [4]. The test files are shell scripts placed in debian/pbuilder-test/NN_name (where NN is number) following run-parts standard[5] for file names. After a successful build, packages are first tested for installation and removal, and then each test is ran inside the chroot. The current directory is the top directory of the source-code. This means you can expect to be able to use ./debian/ directory from inside your scripts.

Example scripts for use with pbuilder-test can be found in /usr/share/doc/pbuilder/examples/pbuilder-test

11. Using pbuilder for testing builds with alternate compilers

Most packages are compiled with gcc or g++ and using the default compiler version, which was gcc 2.95 for Debian GNU/Linux 3.0 (i386). However, Debian 3.0 was distributed with other compilers, under package names such as gcc-3.2 for gcc compiler version 3.2. It was therefore possible to try compiling packages against different compiler versions. pentium-builder provides an infrastructure for using a different compiler for building packages than the default gcc, by providing a wrapper script called gcc which calls the real gcc. To use pentium-builder in pbuilder, it is possible to set up the following in the configuration:

EXTRAPACKAGES="pentium-builder gcc-3.2 g++-3.2"
export DEBIAN_BUILDARCH=athlon
export DEBIAN_BUILDGCCVER=3.2

It will instruct pbuilder to install the pentium-builder package and also the GCC 3.2 compiler packages inside the chroot, and set the environment variables required for pentium-builder to function.



[1] debootstrap or cdebootstrap can be chosen

[2] The mirror site should preferably be a local mirror or a cache server, so as not to overload the public mirrors with a lot of access. Use of tools such as apt-proxy would be advisable.

[3] Only upgrading is supported. Debian does not generally support downgrading (yet?).

[4] It is possible to specify --hookdir /usr/share/doc/pbuilder/examples command-line option to include all example hooks as well.

[5] See run-parts(8). For example, no '.' in file names!

Chapter 3. Using User-mode-linux with pbuilder

It is possible to use user-mode-linux by invoking pbuilder-user-mode-linux instead of pbuilder. pbuilder-user-mode-linux doesn't require root privileges, and it uses the copy-on-write (COW) disk access method of User-mode-linux which typically makes it much faster than the traditional pbuilder.

User-mode-linux is a somewhat less proven platform than the standard Unix tools which pbuilder relies on (chroot, tar, and gzip) but mature enough to support pbuilder-user-mode-linux since its version 0.59. And since then, pbuilder-user-mode-linux has seen a rapid evolution.

The configuration of pbuilder-user-mode-linux goes in three steps:

  • Configuration of user-mode-linux

  • Configuration of rootstrap

  • Configuration of pbuilder-uml

1. Configuring user-mode-linux

user-mode-linux isn't completely trivial to set up. It would probably be useful to acquaint yourself with it a bit before attempting to use rootstrap or pbuilder-user-mode-linux. For details, read /usr/share/doc/uml-utilities/README.Debian and the user-mode-linux documentation. (It's in a separate package, user-mode-linux-doc.)

user-mode-linux requires the user to be in the uml-net group in order to configure the network unless you are using slirp.

If you compile your own kernel, you may want to verify that you enable TUN/TAP support, and you might want to consider the SKAS patch.

2. Configuring rootstrap

rootstrap is a wrapper around debootstrap. It creates a Debian disk image for use with UML. To configure rootstrap, there are several requirements.

  • Install the rootstrap package.

  • TUN/TAP only: add the user to the uml-net group to allow access to the network

    adduser dancer uml-net

  • TUN/TAP only: Check that the kernel supports the TUN/TAP interface, or recompile the kernel if necessary.

  • Set up /etc/rootstrap/rootstrap.conf. For example, if the current host is 192.168.1.2, changing following entries to something like this seems to work.

    transport=tuntap
    interface=eth0
    gateway=192.168.1.1
    mirror=http://192.168.1.2:8081/debian
    host=192.168.1.198
    uml=192.168.1.199
    netmask=255.255.255.0

    Some experimentation with configuration and running rootstrap ~/test.uml to actually test it would be handy.

    Using slirp requires less configuration. The default configuration comes with a working example.

3. Configuring pbuilder-uml

The following needs to happen:

  • Install the pbuilder-uml package.

  • Set up the configuration file /etc/pbuilder/pbuilder-uml.conf in the following manner. It will be different for slirp.

    MY_ETH0=tuntap,,,192.168.1.198
    UML_IP=192.168.1.199
    UML_NETMASK=255.255.255.0
    UML_NETWORK=192.168.1.0
    UML_BROADCAST=255.255.255.255
    UML_GATEWAY=192.168.1.1
    PBUILDER_UML_IMAGE="/home/dancer/uml-image"

    Also, it needs to match the rootstrap configuration.

  • Make sure BUILDPLACE is writable by the user. Change BUILDPLACE in the configuration file to a place where the user has access.

  • Run pbuilder-user-mode-linux create --distribution sid to create the image.

  • Try running pbuilder-user-mode-linux build.

4. Considerations for running pbuilder-user-mode-linux

pbuilder-user-mode-linux emulates most of pbuilder, but there are some differences.

  • pbuilder-user-mode-linux does not support all options of pbuilder properly yet. This is a problem, and will be addressed as specific areas are discovered.

  • /tmp is handled differently inside pbuilder-user-mode-linux. In pbuilder-user-mode-linux, /tmp is mounted as tmpfs inside UML, so accessing files under /tmp from outside user-mode-linux does not work. It affects options like --configfile, and when trying to build packages placed under /tmp.

5. Parallel running of pbuilder-user-mode-linux

To run pbuilder-user-mode-linux in parallel on a system, there are a few things to bear in mind.

  • The create and update methods must not be run when a build is in progress, or the COW file will be invalidated.

  • If you are not using slirp, user-mode-linux processes which are running in parallel need to have different IP addresses. Just trying to run the pbuilder-user-mode-linux several times will result in failure to access the network. But something like the following will work:

    for IP in 102 103 104 105; do
      xterm -e pbuilder-user-mode-linux build --uml-ip 192.168.0.$IP \
        20030107/whizzytex_1.1.1-1.dsc &
    done

    When using slirp, this problem does not exist.

6. Using pbuilder-user-mode-linux as a wrapper script to start up a virtual machine

It is possible to use pbuilder-user-mode-linux for other uses than just building Debian packages. pbuilder-user-mode-linux login will let a user use a shell inside the user-mode-linux pbuilder base image, and pbuilder-user-mode-linux execute will allow the user to execute a script inside the image.

You can use the script to install ssh and add a new user, so that it is possible to access inside the user-mode-linux through ssh.

Note that it is not possible to use a script from /tmp due to the way pbuilder-user-mode-linux mounts a tmpfs at /tmp.

The following example script may be useful in starting a sshd inside user-mode-linux.

#!/bin/bash

apt-get install -y ssh xbase-clients xterm
echo "enter root password"
passwd
cp /etc/ssh/sshd_config{,-}
sed 's/X11Forwarding.*/X11Forwarding yes/' /etc/ssh/sshd_config- > /etc/ssh/sshd_config

/etc/init.d/ssh restart
ifconfig
echo "Hit enter to finish"
read

Chapter 4. Frequently asked questions

Here, known problems and frequently asked questions are documented. This portion was initially available in README.Debian file, but moved here.

1. pbuilder create fails

It often happens that pbuilder cannot create the latest chroot. Try upgrading pbuilder and debootstrap. It is currently only possible to create software that handles the past. Future prediction is a feature which may be added later after we have become comfortable with the past.

There are people who occasionally back port debootstrap to stable versions; hunt for them.

When there are errors with the debootstrap phase, the debootstrap script needs to be fixed. pbuilder does not provide a way to work around debootstrap.

2. Directories that cannot be bind-mounted

Because of the way pbuilder works, there are several directories which cannot be bind-mounted when running pbuilder. The directories include /tmp, /var/cache/pbuilder, and system directories such as /etc and /usr. The recommendation is to use directories under the user's home directory for bind-mounts.

3. Logging in to pbuilder to investigate build failure

It is possible to invoke a shell session after a build failure. Example hook script are provided as C10shell and C11screen scripts. C10shell script will start bash inside chroot, and C11screen script will start GNU screen inside the chroot.

4. Logging in to pbuilder to modify the environment

It is sometimes necessary to modify the chroot environment. login will remove the contents of the chroot after logout. It is possible to invoke a shell using hook scripts. pbuilder update executes 'E' scripts, and a sample for invoking a shell is provided as C10shell.

$ mkdir ~/loginhooks
$ cp C10shell ~/loginhooks/E10shell
$ sudo pbuilder update --hookdir ~/loginhooks/E10shell

It is also possible to add --save-after-exec and/or --save-after-login options to the pbuilder login session to accomplish the goal. It is possible to add the --uml-login-nocow option to pbuilder-user-mode-linux login session as well.

5. Setting BUILDRESULTUID for sudo sessions

It is possible to set

BUILDRESULTUID=$SUDO_UID

in pbuilderrc to set the proper BUILDRESULTUID when using sudo.

6. Notes on usage of $TMPDIR

If you are setting $TMPDIR to an unusual value, of other than /tmp, you will find that some errors may occur inside the chroot, such as dpkg-source failing.

There are two options, you may install a hook to create that directory, or set

export TMPDIR=/tmp

in pbuilderrc. Take your pick.

An example script is provided as examples/D10tmp with pbuilder.

7. Creating a shortcut for running pbuilder with a specific distribution

When working with multiple chroots, it would be nice to work with scripts that reduce the amount of typing. An example script pbuilder-distribution.sh is provided as an example. Invoking the script as pbuilder-squeeze will invoke pbuilder with a squeeze chroot.

8. Using environmental variables for running pbuilder for specific distribution

This section[6] describes briefly a way to setup and use multiple pbuilder setups by creating a pbuilderrc configuration in your home path ($HOME/.pbuilderrc) and using the variable "DIST" when running pbuilder or pdebuild.

First, setup $HOME/.pbuilderrc to look like:

if [ -n "${DIST}" ]; then
        BASETGZ="`dirname $BASETGZ`/$DIST-base.tgz"
        DISTRIBUTION="$DIST"
        BUILDRESULT="/var/cache/pbuilder/$DIST/result/"
        APTCACHE="/var/cache/pbuilder/$DIST/aptcache/"
fi

Then, whenever you wish to use pbuilder for a particular distro, assign a value to "DIST" that is one of the distros available for Debian or any Debian based distro you happen to be running (i.e. whatever is found under /usr/lib/debootstrap/scripts).

Here's some examples on running pbuilder or pdebuild:

DIST=gutsy sudo pbuilder create

DIST=sid sudo pbuilder create --mirror http://http.us.debian.org/debian

DIST=gutsy sudo pbuilder create \
        --othermirror "deb http://archive.ubuntu.com/ubuntu gutsy universe \
        multiverse"

DIST=gutsy sudo pbuilder update

DIST=sid sudo pbuilder update --override-config --mirror \
http://http.us.debian.org/debian \
--othermirror "deb http://http.us.debian.org/debian sid contrib non-free"

DIST=gutsy pdebuild

9. Using special apt sources lists, and local packages

If you have some very specialized requirements on your apt setup inside pbuilder, it is possible to specify that through the --othermirror option. Try something like: --othermirror "deb http://local/mirror stable main|deb-src http://local/source/repository ./"

To use the local file system instead of HTTP, it is necessary to do bind-mounting. --bindmounts is a command-line option useful for such cases.

It might be convenient to use your built packages from inside the chroot. It is possible to automate the task with the following configuration. First, set up pbuilderrc to bindmount your build results directory.

BINDMOUNTS="/var/cache/pbuilder/result"

Then, add the following hook

# cat /var/cache/pbuilder/hooks/D70results
#!/bin/sh
cd /var/cache/pbuilder/result/
/usr/bin/dpkg-scanpackages . /dev/null > /var/cache/pbuilder/result/Packages
/usr/bin/apt-get update

This way, you can use deb file:/var/cache/pbuilder/result

To add new apt-key inside chroot:

sudo pbuilder --login --save-after-login
# apt-key add - <<EOF
...public key goes here...
EOF
# logout