Differences between revisions 29 and 30
Revision 29 as of 2011-05-11 21:52:21
Size: 4186
Revision 30 as of 2011-05-28 11:12:33
Size: 4300
Deletions are marked like this. Additions are marked like this.
Line 74: Line 74:
  * Bring your cowbuilder chroot up to date by running
sudo DIST=sid ARCH=amd64 cowbuilder --update


This is the tutorial for cowbuilder. See also qemubuilder.



Create the base image:

sudo cowbuilder --create

And a new and shiny build image is created in /var/cache/pbuilder/base.cow/

Every day usage

Update the base image

sudo cowbuilder --update

Build a package:

sudo cowbuilder --build somepackage.dsc


Bash and SVN tips

Setup your .bashrc according to: http://upsilon.cc/~zack/blog/posts/2007/09/svn-cowbuilder/

Building your package for many distributions at once

cowbuilder is really handy to build your pet project for many distributions at once. If you have got an amd64 system, you can easily build a package for i386 and amd64 architectures and for say stable, sid and lucid.

  • The first step involves creating as many basepaths as you need. I chose to put them in /var/cache/pbuilder/$DIST-$ARCH/base.cow.

sudo mkdir  /var/cache/pbuilder/squeeze-i386/
  • Then create the base image :

sudo cowbuilder \
--create \
--basepath /var/cache/pbuilder/squeeze-i386/base.cow\
 --distribution squeeze\
 --debootstrapopts --arch --debootstrapopts i386

Creating an ubuntu base path is trickier because one must :

  1. import ubuntu signing keys
  2. exclude packages of priority important in /usr/share/cdebootstrap/generic-ubuntu/packages

  3. add universe to complete creation of chroot because the cowdancer package is in universe.

$ DIST=gutsy sudo cowbuilder --create \
--distribution gutsy \
--components "main universe" \
--basepath /var/cache/pbuilder/gutsy-amd64.cow \
--mirror http://apt:9999/ubuntu \
--debootstrapopts --exclude=udev,pcmciautils,initramfs-tools
  • Create a ~/.pbuilderrc file, taking the one from Ubuntu pbuilder howto, in the Multiple pbuilderssection, uncommenting the line


At the end you should add:

  • Bring your cowbuilder chroot up to date by running

sudo DIST=sid ARCH=amd64 cowbuilder --update
  • You can now build up a package. For instance a backport of nano for squeeze:

dget http://ftp.de.debian.org/debian/pool/main/n/nano/nano_2.2.6-1.dsc
cd nano-2.2.6
# For a Debian Squeeze on i386 target
sudo DIST=squeeze ARCH=i386 pdebuild
# Ubuntu a Hardy on amd64 target
sudo DIST=hardy ARCH=amd64 pdebuild

The result will be available in: /var/cache/pbuilder/squeeze-i386/result

  • Once everything is set up, you can use a script in a debian source package directory to build it for every distribution.

set -e

[ -d $RESULTDIR ] || mkdir $RESULTDIR

DISTLIST=$(ls -d /var/cache/pbuilder/*.cow)

for chrootdir in $DISTLIST
    sudo cowbuilder --update --basepath $chrootdir
    DIST=$(basename $chrootdir | cut -d'-' -f1)
    [ -d $RESULTDIR/$DIST ] || mkdir $RESULTDIR/$DIST
    DIST=$DIST pdebuild --pbuilder cowbuilder\
                        --buildresult $RESULTDIR/$DIST\
                        -- --basepath $chrootdir
  • You can use an apt cache to reduce the downloads on mirrors, so if the mirror is http://apt:9999/debian or http://apt:9999/ubuntu.

( you shoud then add --mirror http://apt:9999/debian 

  • You can use eatmydata inside the cowbuilder chroot to speed up dpkg

DIST=sid cowbuilder --login --save
apt-get install eatmydata
  • And add this /etc/pbuilderrc

if [ -z "$LD_PRELOAD" ]; then



Slow copying and removing of the COW directory

What cowbuilder does is:

cp -al /var/cache/pbuilder/base.cow /tmp/new
rm -rf /tmp/new

Of course cowbuilder uses a different location than /tmp/new. You need to optimize those 2 commands on your computer. They should take around 0.2s each. If not, try to use the ext3 filesystem, for more details, see our benchmarks.