Differences between revisions 30 and 51 (spanning 21 versions)
Revision 30 as of 2011-05-28 11:12:33
Size: 4300
Comment:
Revision 51 as of 2020-04-02 14:18:18
Size: 5429
Editor: RhondaDVine
Comment: small updates
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== cowbuilder == This is a tutorial for cowbuilder. See also [[qemubuilder]], [[sbuild]].
Line 3: Line 3:
This is the tutorial for cowbuilder. See also [[qemubuilder]]. <<TableOfContents>>
Line 29: Line 29:
=== Bash and SVN tips === == Bash and SVN tips ==
Line 33: Line 33:
=== Building your package for many distributions at once === == Building your package for many distributions at once ==
Line 37: Line 37:
  * 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/
  * The first step involves choosing as many basepaths as you need. I chose to put them in `/var/cache/pbuilder/$DIST-$ARCH/base.cow`. Create the base directory, example:
    {{{
mkdir /var/cache/pbuilder/squeeze-i386
Line 43: Line 43:
{{{
sudo cowbuilder \
--create \
--basepath /var/cache/pbuilder/squeeze-i386/base.cow\
--distribution squeeze\
--debootstrapopts --arch --debootstrapopts i386

    
{{{
sudo cowbuilder --create --basepath /var/cache/pbuilder/squeeze-i386/base.cow --distribution squeeze --debootstrapopts --arch --debootstrapopts i386
Line 51: Line 48:
Creating an ubuntu base path  is trickier because one must :
  1. import ubuntu signing keys
  1. exclude packages of priority `important` in `/usr/share/cdebootstrap/generic-ubuntu/packages`
    {{{{#!wiki note
Creating an ubuntu base path is trickier because one must :
  1. Obtain ubuntu signing keys
  1. Use --keyring option to specific ubuntu signing keys
Line 55: Line 53:
    {{{
apt install ubuntu-archive-keyring
DIST=gutsy sudo cowbuilder --create --distribution gutsy --components "main universe" --basepath /var/cache/pbuilder/gutsy-amd64.cow --mirror http://apt:9999/ubuntu --debootstrapopts --keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg
}}}
}}}}
Line 56: Line 59:
{{{
$ 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 [[https://wiki.ubuntu.com/PbuilderHowto|Ubuntu pbuilder howto]], in the `Multiple pbuilders`section, uncommenting the line
{{{
  * Create a `~/.pbuilderrc` file, taking the one from [[https://wiki.ubuntu.com/PbuilderHowto|Ubuntu pbuilder howto]], in the `Multiple pbuilders` section, uncommenting the line
    {{{
Line 68: Line 62:
}}}
At the end you should add:
{{{
PDEBUILD_PBUILDER="cowbuilder"
Line 75: Line 65:
{{{
sudo DIST=sid ARCH=amd64 cowbuilder --update
   {{{
sudo HOME=$HOME DIST=sid cowbuilder --update
}}}
  Setting HOME is necessary as sudo strips environment variables for security reasons (see [[https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=567995|Debian bug]]) - otherwise cowbuilder will not find the .pbuilderrc you have just created.

  * You can now build up a package. For instance a backport of nano for squeeze:
   {{{
dget -x http://ftp.de.debian.org/debian/pool/main/n/nano/nano_2.2.6-1.dsc
# For a Debian Squeeze on i386 target
sudo DIST=squeeze ARCH=i386
# Ubuntu a Hardy on amd64 target
sudo DIST=hardy ARCH=amd64 cowbuilder --build nano_2.2.6-1.dsc
Line 79: Line 79:
  * 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`.
Line 89: Line 81:
The result will be available in:
/var/cache/pbuilder/squeeze-i386/result

===== Optionnal =====
=== Optional ===
Line 114: Line 103:
  * 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 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`. A good and simple proxy to use is [[approx]].
Line 117: Line 105:
  * You can use eatmydata inside the cowbuilder chroot to speed up dpkg   * You can use eatmydata inside and outside of the cowbuilder chroot to speed up dpkg
Line 122: Line 110:
  * And add this /etc/pbuilderrc   * If you have pbuilder >= 0.225, just add this to your pbuilderrc:
Line 124: Line 112:
if [ -z "$LD_PRELOAD" ]; then
  LD_PRELOAD=/usr/lib/libeatmydata/libeatmydata.so
else
  LD_PRELOAD="$LD_PRELOAD":/usr/lib/libeatmydata/libeatmydata.so
fi
EXTRAPACKAGES=eatmydata
EATMYDATA=yes
}}}
  * For eatmydata (<=26-2.1), add this /etc/pbuilderrc for :
{{{
export LD_PRELOAD=${LD_PRELOAD:+$LDPRELOAD:}/usr/lib/libeatmydata/libeatmydata.so
}}}
  * For eatmydata (>=82-2), add this /etc/pbuilderrc
{{{
export LD_PRELOAD=${LD_PRELOAD:+$LDPRELOAD:}libeatmydata.so
}}}
Line 130: Line 124:
export LD_PRELOAD Please note eatmydata inside and outside of the cowbuilder chroot should be the same type.

== Using with git-buildpackage ==

The above config can be adapted to work with the defaults of git-buildpackage:

{{{
-BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
+BASEPATH="/var/cache/pbuilder/base-$NAME.cow/"
Line 132: Line 134:

Then the images can be created with:

{{{
DIST=sid ARCH=amd64 git-pbuilder create
}}}

And packages be built with:

{{{
DIST=sid ARCH=amd64 git-buildpackage --git-pbuilder
}}}

A bug was opened to make sure the ARCH argument is coherent with the pbuilder way (ie. that it's optional), see: [[DebianBug:646882|#646882]]

This is a tutorial for cowbuilder. See also qemubuilder, sbuild.

Usage

Initialization

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

Tips

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 choosing as many basepaths as you need. I chose to put them in /var/cache/pbuilder/$DIST-$ARCH/base.cow. Create the base directory, example:

    • 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. Obtain ubuntu signing keys
      2. Use --keyring option to specific ubuntu signing keys
      3. add universe to complete creation of chroot because the cowdancer package is in universe.

        • apt install ubuntu-archive-keyring
          DIST=gutsy sudo cowbuilder --create --distribution gutsy --components "main universe" --basepath /var/cache/pbuilder/gutsy-amd64.cow --mirror http://apt:9999/ubuntu --debootstrapopts --keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg
  • Create a ~/.pbuilderrc file, taking the one from Ubuntu pbuilder howto, in the Multiple pbuilders section, uncommenting the line

    • BASEPATH="/var/cache/pbuilder/$NAME/base.cow/
  • Bring your cowbuilder chroot up to date by running
    • sudo HOME=$HOME DIST=sid cowbuilder --update

    Setting HOME is necessary as sudo strips environment variables for security reasons (see Debian bug) - otherwise cowbuilder will not find the .pbuilderrc you have just created.

  • You can now build up a package. For instance a backport of nano for squeeze:
    • dget -x http://ftp.de.debian.org/debian/pool/main/n/nano/nano_2.2.6-1.dsc
      # For a Debian Squeeze on i386 target
      sudo DIST=squeeze ARCH=i386 
      # Ubuntu a Hardy on amd64 target
      sudo DIST=hardy ARCH=amd64 cowbuilder --build nano_2.2.6-1.dsc

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

Optional

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

set -e

RESULTDIR=$1
[ -d $RESULTDIR ] || mkdir $RESULTDIR

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

for chrootdir in $DISTLIST
do
    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
done
  • 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. A good and simple proxy to use is ?approx.

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

DIST=sid cowbuilder --login --save
apt-get install eatmydata
  • If you have pbuilder >= 0.225, just add this to your pbuilderrc:

EXTRAPACKAGES=eatmydata
EATMYDATA=yes
  • For eatmydata (<=26-2.1), add this /etc/pbuilderrc for :

export LD_PRELOAD=${LD_PRELOAD:+$LDPRELOAD:}/usr/lib/libeatmydata/libeatmydata.so
  • For eatmydata (>=82-2), add this /etc/pbuilderrc

export LD_PRELOAD=${LD_PRELOAD:+$LDPRELOAD:}libeatmydata.so

Please note eatmydata inside and outside of the cowbuilder chroot should be the same type.

Using with git-buildpackage

The above config can be adapted to work with the defaults of git-buildpackage:

-BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
+BASEPATH="/var/cache/pbuilder/base-$NAME.cow/"

Then the images can be created with:

DIST=sid ARCH=amd64 git-pbuilder create

And packages be built with:

DIST=sid ARCH=amd64 git-buildpackage --git-pbuilder

A bug was opened to make sure the ARCH argument is coherent with the pbuilder way (ie. that it's optional), see: #646882

Troubleshooting

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.