Other pbuilder documentation include:
Contents
How to include local packages in the build
First you need to do some setup once:
- Create a base directory for dependencies (say /var/cache/pbuilder/deps)
Add this to your pbuilder configuration: (the configuration file is usually in /etc/pbuilderrc; If you are using ~/.pbuilderrc instead, then you need to use pdebuild or sudo -E pbuilder ...)
# the hook dir may already be set/populated! HOOKDIR="$HOME/.pbuilder/hooks/" if [ -n "$DEPS" ] ; then export DEPSBASE=/var/cache/pbuilder/deps BINDMOUNTS=$DEPSBASE fi
- Put a file like D05deps in your $HOOKDIR, make it executable and have this content:
DEPSPATH="$DEPSBASE/$DEPS" if [ -n "$DEPS" ] && [ -d "$DEPSPATH" ] ; then apt-get install --assume-yes apt-utils ( cd "$DEPSPATH"; apt-ftparchive packages . > Packages ) echo "deb [trusted=yes] file://$DEPSPATH ./" >> /etc/apt/sources.list apt-get update fi
Whenever you have a new project to get a package and one or more dependencies into Debian, you can go through these steps.
- Create a subdirectory within your deps base dir for the dependencies of a particular project (say myproject).
- Build the dependency.
- Copy the resulting debs into /var/cache/pbuilder/deps/myproject.
- Build the package depending on it with the DEPS variable:
DEPS=myproject pdebuild
- Upload the packages to Debian.
- Delete the /var/cache/pbuilder/deps/myproject directory.
Use the build results dir as a repo
A simpler version of the local repo makes the BUILDRESULT directory, where the resulting packages are put, into an apt repo. This might cause unexpected package version conflicts, depending on what packages are present in BUILDRESULT. Do the above ~/.pbuilderrc config then include this in /etc/pbuilder/hook.d/D10apt-ftparchive
# #https://web.archive.org/web/20110908010042/http://blog.edseek.com/~jasonb/articles/pbuilder_backports/pbuilderbuild.\ html # May be necessary if base image does not have apt-utils already. #apt-get install apt-utils # We want this to be up to date for _every_ run for magic to happen! apt-get install --assume-yes apt-utils ( cd "$LOCAL_REPO"; apt-ftparchive packages . > Packages ) echo "deb [trusted=yes] file://$LOCAL_REPO ./" >> /etc/apt/sources.list cd $LOCAL_REPO rm -f InRelease Packages Packages.gz Release Release.gpg Sources Sources.gz apt-ftparchive packages . > $LOCAL_REPO/Packages cat<<EOF >Release Components: main Origin: pbuilder Label: pbuilder Architectures: i386 amd64 EOF apt-ftparchive release . >> Release apt-ftparchive sources . > Sources 2>/dev/null cat<<EOF >/etc/apt/sources.list.d/apt-ftparchive.list deb [trusted=yes] file://$LOCAL_REPO ./ EOF cat<<EOF >/etc/apt/preferences Package: * Pin: release o=pbuilder Pin-Priority: 701 EOF apt-get -qy update
How to build for different distributions
This is workable through the --basetgz parameter of pbuilder. You can pbuilder create --basetgz /var/cache/pbuilder/unstable.tgz --distribution unstable (and so on) to create the base tarballs. When using pdebuild, use pdebuild -- --basetgz /var/cache/pbuilder/<dist>.tgz instead, depending on which distribution you want. It is probably useful to make the default one sid (create without --basetgz and pdebuild without --basetgz).
The following is taken from https://wiki.ubuntu.com/PbuilderHowto
The only thing required to use pbuilder with multiple distributions is an alternate location to store the gzipped tarball that contains the pbuilder environment. On the command line, this can be specified with the 'basetgz' option. However, it is tedious to specify the full path every time pbuilder is run, so it is convenient to place a snippet in ~/.pbuilderrc to automate this:
# Codenames for Debian suites according to their alias. UNSTABLE_CODENAME="$(distro-info --devel)" TESTING_CODENAME="$(distro-info --testing)" STABLE_CODENAME="$(distro-info --stable)" STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports" # List of Debian suites. DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME $STABLE_BACKPORTS_SUITE "experimental" "unstable" "testing" "stable") # List of Ubuntu suites. Update these when needed. UBUNTU_SUITES=($(ubuntu-distro-info --all)) # Mirrors to use. Update these to your preferred mirror. DEBIAN_MIRROR="deb.debian.org" UBUNTU_MIRROR="mirrors.kernel.org" # Optionally use the changelog of a package to determine the suite to use if # none set. if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then DIST=$(dpkg-parsechangelog --show-field=Distribution) fi # Optionally set a default distribution if none is used. Note that you can set # your own default (i.e. ${DIST:="unstable"}). : ${DIST:="$(lsb_release --short --codename)"} # Optionally change Debian codenames in $DIST to their aliases. case "$DIST" in $UNSTABLE_CODENAME) DIST="unstable" ;; $TESTING_CODENAME) DIST="testing" ;; $STABLE_CODENAME) DIST="stable" ;; esac # Optionally set the architecture to the host architecture if none set. Note # that you can set your own default (i.e. ${ARCH:="i386"}). : ${ARCH:="$(dpkg --print-architecture)"} NAME="$DIST" if [ -n "${ARCH}" ]; then NAME="$NAME-$ARCH" DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}") fi BASETGZ="/var/cache/pbuilder/$NAME-base.tgz" DISTRIBUTION="$DIST" BUILDRESULT="/var/cache/pbuilder/$NAME/result/" APTCACHE="/var/cache/pbuilder/$NAME/aptcache/" BUILDPLACE="/var/cache/pbuilder/build/" if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then # Debian configuration MIRRORSITE="http://$DEBIAN_MIRROR/debian/" COMPONENTS="main contrib non-free" if $(echo "$STABLE_CODENAME stable" | grep -q $DIST); then OTHERMIRROR="$OTHERMIRROR | deb $MIRRORSITE $STABLE_BACKPORTS_SUITE $COMPONENTS" fi elif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then # Ubuntu configuration MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/" COMPONENTS="main restricted universe multiverse" else echo "Unknown distribution: $DIST" exit 1 fi
Now, if the user sets DIST to another distribution such as hardy when running pbuilder, the tarball location will be changed. The line that sets the DISTRIBUTION only takes effect during the creation of a new base tarball, or if the --override-config option is given, where it specifies the distribution to use for the new base tarball. Setting BUILDRESULT or APTCACHE is optional, but possibly helpful.
Note that there are some optional lines in this snippet that appear after comments that start with "Optionally". These lines can be commented out.
If ARCH is set to a different architecture when running pbuilder, pbuilder will be set to create an environment to build packages for the architecture specified in ARCH.
To make the following example work you have to configure sudo this way :
Cmnd_Alias PBUILDER = /usr/sbin/pbuilder, /usr/bin/pdebuild, /usr/bin/debuild-pbuilder, /usr/sbin/cowbuilder Defaults!PBUILDER env_keep+="DIST ARCH HOME" <your user> ALL=(ALL) SETENV: PBUILDER
We can now create and use alternate tarballs, as in the following examples:
# Create a base environment for Ubuntu gutsy sudo DIST=gutsy pbuilder create # Create a base environment for Debian sid sudo DIST=sid pbuilder create # Create a base environment for Ubuntu gutsy under # the i386 architecture sudo DIST=gutsy ARCH=i386 pbuilder create # Update a base environment for Ubuntu gutsy sudo DIST=gutsy pbuilder update # Build a package using Ubuntu gutsy as the base # environment DIST=gutsy pdebuild # Build a package using Ubuntu gutsy as the base # environment under the i386 architecture DIST=gutsy ARCH=i386 pdebuild
Backports
With the above pbuilderrc example, the backports repository for Debian will be enabled for chroots of the Debian stable suite. No packages are installed automatically however until the /etc/apt/preferences file is configured accordingly in the chroot. To enable certain packages from the backports, do the following.
First, create and then specify a hooks directory that pbuilder will use. For example, if you create a hooks directory in /var/cache/pbuilder/hook.d, add this line to your ~/.pbuilderrc file.
HOOKDIR="/var/cache/pbuilder/hook.d/"
Afterwards, create a script of the form 'E<digit><digit><whatever else you want>' in the hooks directory.
Here's an example script named /var/cache/pbuilder/hook.d/E01apt-preferences that enables the packages 'debhelper' and 'lintian' from the backports repository.
#!/bin/sh set -e STABLE_VERSION_REGEX='^9\.[0-9]+$' if $(egrep -q "$STABLE_VERSION_REGEX" "/etc/debian_version"); then cat > "/etc/apt/preferences" << EOF Package: debhelper Pin: release a=stretch-backports Pin-Priority: 999 Package: lintian Pin: release a=stretch-backports Pin-Priority: 999 EOF fi
How to use pbuilder to test build with gcc-snapshot
While there are several ways to achieve this, an easy way is to use a hook to remove the existing gcc symlinks and replace them with a wrapper which uses gcc-snapshot. The following hook will do this for gcc, g++ and gfortran (extend it as needed):
#!/bin/bash aptitude -R -y install gcc-snapshot cat > /usr/local/bin/gcc-snapshot << EOF #!/bin/sh LD_LIBRARY_PATH=/usr/lib/gcc-snapshot/lib:$LD_LIBRARY_PATH PATH=/usr/lib/gcc-snapshot/bin:$PATH gcc "\$@" EOF chmod 755 /usr/local/bin/gcc-snapshot cat > /usr/local/bin/g++-snapshot << EOF #!/bin/sh LD_LIBRARY_PATH=/usr/lib/gcc-snapshot/lib:$LD_LIBRARY_PATH PATH=/usr/lib/gcc-snapshot/bin:$PATH g++ "\$@" EOF chmod 755 /usr/local/bin/g++-snapshot cat > /usr/local/bin/gfortran-snapshot << EOF #!/bin/sh LD_LIBRARY_PATH=/usr/lib/gcc-snapshot/lib:$LD_LIBRARY_PATH PATH=/usr/lib/gcc-snapshot/bin:$PATH g++ "\$@" EOF chmod 755 /usr/local/bin/gfortran-snapshot rm -f /usr/bin/gcc /usr/bin/g++ /usr/bin/gfortran ln -s /usr/local/bin/gcc-snapshot /usr/bin/gcc ln -s /usr/local/bin/g++-snapshot /usr/bin/g++ ln -s /usr/local/bin/gfortran-snapshot /usr/bin/gfortran #/bin/bash < /dev/tty > /dev/tty
Then, ensure that the environment variable LD_LIBRARY_PATH is set to prefer the libraries belonging to gcc-snapshot by adding the following to your .pbuilderrc:
export LD_LIBRARY_PATH=/usr/lib/gcc-snapshot/lib:$LD_LIBRARY_PATH
Save the file as D20_gcc43 (or something) in your hook directory, and make it executable to use gcc 4.3. Of course, care has to be taken that the build system also uses the gcc, gfortran, g++ etc. found in /usr/bin; otherwise, some extra work needs to be done.
Also, remember to NEVER upload packages produced by gcc-snapshot!
How to satisfy experimental dependencies
Pbuilder before version 0.224 (present since stretch onward) used to configure APT with APT::Default-Release = "experimental" for experimental chroots; this caused unappropriated behavior where it would download everything from experimental even when the unstable version was enough.
If you're using pbuilder >= 0.224 you can just create a chroot for experimental with:
# pbuilder create --distribution experimental
For older versions you can workaround its buggy behavior by:
Login from root into the base pbuilder environment to add experimental to the sources.list:
# pbuilder login --save-after-login (chroot) # echo "deb http://deb.debian.org/debian experimental main" >> /etc/apt/sources.list # exit
- Update your pbuilder environment:
# pbuilder --update
Now you are done, using pdebuild will download packages from experimental when needed.
Unknown OpenPGP keys
If pbuilder fails with "E: Release signed by unknown key (key id <...>)", pass the keyring path as:
sudo DIST=jessie pbuilder create --debootstrapopts --keyring=/usr/share/keyrings/debian-archive-keyring.gpg