Utilizzare pbuilder per compilare pacchetti debian di architetture diverse

From RVM Wiki
Jump to navigation Jump to search

Su un host AMD64 si possono compilare pacchetti per i386 e amd64.

Installazione e configurazione di Pbuilder

  • Installare pbuilder
sudo aptitude install pbuilder debootstrap devscripts cdebootstrap
  • Configuralo in modo da supportare più architetture e distribuzioni settando delle variabili:
cat > ~/pbuilderrc <<'EOFile'
# Codenames for Debian suites according to their alias. Update these when
# needed.
UNSTABLE_CODENAME="sid"
TESTING_CODENAME="squeeze"
STABLE_CODENAME="lenny"
STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports"

# List of Debian suites.
DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME
    "unstable" "testing" "stable")

# List of Ubuntu suites. Update these when needed.
UBUNTU_SUITES=("natty" "maverick" "lucid" "karmic" "jaunty" "hardy")

# Mirrors to use. Update these to your preferred mirror.
DEBIAN_MIRROR="ftp.it.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 | awk '/^Distribution: / {print $2}')
    # Use the unstable suite for certain suite values.
    if $(echo "experimental UNRELEASED" | grep -q $DIST); then
        DIST="$UNSTABLE_CODENAME"
    fi
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 release states in $DIST to their names.
case "$DIST" in
    unstable)
        DIST="$UNSTABLE_CODENAME"
        ;;
    testing)
        DIST="$TESTING_CODENAME"
        ;;
    stable)
        DIST="$STABLE_CODENAME"
        ;;
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"
# Optionally, set BASEPATH (and not BASETGZ) if using cowbuilder
# BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
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"
    DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
    # This is for enabling backports for the Debian stable suite.
    if $(echo "$STABLE_CODENAME stable" | grep -q $DIST); then
        EXTRAPACKAGES="$EXTRAPACKAGES debian-backports-keyring"
        OTHERMIRROR="$OTHERMIRROR | deb http://www.backports.org/debian $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"
    DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
else
    echo "Unknown distribution: $DIST"
    exit 1
fi
EOFile
  • Creare le tarball per la chroot delle due architetture:
sudo DIST=lenny ARCH=i386 pbuilder create -debootstrapopts --variant=buildd
sudo DIST=lenny ARCH=amd64 pbuilder create -debootstrapopts --variant=buildd

Compliazione di un pacchetto con file .dsc

  • Ipotizzando di avere già un pacchetto da compilare con un file .dsc, invece di usare dpkg-buildpackage, usare:
sudo DIST=lenny ARCH=i386 pbuilder build iptables-initd_1.0.0-4.dsc
  • I pacchetti risultanti saranno in
/var/cache/pbuilder/lenny-i386/result/
  • Se si devono utilizzare delle opzioni da passare dpkg-buildpackage, usarle così:
export DEBFULLNAME="Gabriele Vivinetto"
export DEBEMAIL=gabriele.mailing@rvmgroup.it
sudo DIST=lenny ARCH=i386 pbuilder build --debbuildopts -kF6D289F6 -tc pigz_2.1.6-1.dsc


Compilazione di un pacchetto per backport

  • Prelevare i sorgenti con:
dget http://ftp.de.debian.org/debian/pool/main/a/amanda/amanda_3.2.1-1.1.dsc
  • A questo punto proseguire come al punto precedente

Compilazione di un pacchetto con sorgenti

  • Utilizzare pdebuild, che produce i .dsc, e poi proseguire
sudo DIST=squeeze ARCH=amd64 pdebuild
sudo DIST=squeeze ARCH=amd64 pbuilder build iptables-initd_1.0.0-5.dsc

Backport di un pacchetto con pbuilder

Vedi Backporting Debian packages with pbuilder | tolaris.com

I frequently need to package software for install on Ubuntu systems. If you manage only one server, don’t upgrade often, and don’t need to uninstall, then you may be happy with the ancient “untar, make, make install” method. But if you’re like me you prefer to create .deb packages and install those.

I run Ubuntu 8.04 “hardy” on my servers. Hardy is almost a year old now, and although it has up to date security fixes it no longer has the latest releases of software. This is fine for most purpose, but sometimes I want an updated version of some software and I’m willing to risk the slight chance that it has bugs.

The best traceroute tool around is <a href="http://www.bitwizard.nl/mtr/">mtr</a>. The version in Hardy is 0.72, but Jaunty now has a package for 0.75. So let’s backport it with <a href="http://www.netfort.gr.jp/%7Edancer/software/pbuilder.html.en">pbuilder</a>.

pBuilder is by far the easiest way to backport existing packages to older releases. The Ubuntu wiki provides an excellent <a href="https://wiki.ubuntu.com/PbuilderHowto">pbuilder HowTo</a>. If you want to know more about Debian packages, I also advise you to read the <a href="https://wiki.ubuntu.com/PackagingGuide/Complete">Ubuntu Packaging Guide</a>.

Install pbuilder:

apt-get install pbuilder

Now configure it to support multiple distributions. This means you can build packages for Dapper, Hardy, Debian Lenny, whatever; and you can build i386 packages on amd64. Here is my ~/.pbuilderrc:

# 2008-08-13 tyler
# support building multiple distributions and architectures
: ${DIST:=$(lsb_release --short --codename)}
: ${ARCH:=$(dpkg --print-architecture)}
NAME="$DIST-$ARCH"
DISTRIBUTION="$DIST"
DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
BASETGZ="`dirname $BASETGZ`/$NAME-base.tgz"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
# Don't rebuild source files (.diff.gz, .dsc), or list them in .changes
# See Ubuntu bug 118181
DEBBUILDOPTS="-b"
case "$DIST" in
karmic|jaunty|intrepid|hardy|dapper) # ubuntu specific
MIRRORSITE="http://archive.ubuntu.com/ubuntu/"
COMPONENTS="main restricted universe multiverse"
;;
sid|squeeze|lenny|etch) # debian specific
MIRRORSITE="http://mirrors.kernel.org/debian/"
COMPONENTS="main contrib non-free"
;;
*)
echo "Unknown distribution: $DIST"
exit 1
;;
esac
HOOKDIR=$HOME/.pbuilder-hooks

Now create your initial pbuilder root images. This will create a .tar.gz of a basic root image of that distribution, which pbuilder unpacks each time it builds packages. Do this once for each distribution and architecture for which you want to build. You select these with the DIST and ARCH environment variables.

The following builds environments for Hardy on amd64 and i386, and dapper on i386.

sudo DIST=hardy ARCH=amd64 pbuilder create

sudo DIST=hardy ARCH=i386 pbuilder create

sudo DIST=dapper ARCH=i386 pbuilder create

I run Hardy amd64 on my laptop, so I can run the first command without specifying DIST or ARCH.

sudo pbuilder create

You only need do the above once for each distribution/architecture combination you intend to support. You do not need to do it each time you build packages.

We are now ready to build mtr packages. Check the <a href="http://packages.ubuntu.com/search?searchon=names&keywords=mtr">Ubuntu package archives for mtr</a>. Note the updated mtr version for <a href="http://packages.ubuntu.com/jaunty/mtr">Jaunty</a>.

Load the Jaunty mtr page, and look on the left side of the page where is says “Download Source Package mtr”. Download the three files there, ending in .dsc, orig.tar.gz, and .diff.gz. Alternatively, right-click on the .dsc and “Copy Link Location”, and use the dget command (install the “devscripts” package:

dget http://archive.ubuntu.com/ubuntu/pool/main/m/mtr/mtr_0.75-2.dsc

This will download the three needed files to the current directory. We’re now ready to build mtr with pbuilder.

sudo pbuilder build mtr_0.75-2.dsc

Or for another distribution and architecture:

sudo DIST=dapper ARCH=i386 pbuilder build mtr_0.75-2.dsc

pbuilder will now unpack the base tarball it created in /var/cache/pbuilder/hardy-amd64-base.tgz, download any packages mtr needs, and compile it, and create the .deb files. Here is my <a href="http://www.tolaris.com/blog/wp-content/uploads/2009/03/pbuilder-mtr.txt">pbuilder mtr build log</a>.

Results will be copied to /var/cache/pbuilder/DIST-ARCH/result.

tyler@baal:~$ ls /var/cache/pbuilder/hardy-amd64/result/
mtr_0.75-2_amd64.changes
mtr_0.75-2_amd64.deb
mtr_0.75-2.diff.gz
mtr_0.75-2.dsc
mtr_0.75.orig.tar.gz
mtr-tiny_0.75-2_amd64.deb

Now install .deb file, and you’re done!

Riferimenti