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 mtr. The version in Hardy is 0.72, but Jaunty now has a package for 0.75. So let’s backport it with pbuilder.
pbuilder is by far the easiest way to backport existing packages to older releases. The Ubuntu wiki provides an excellent pbuilder HowTo. If you want to know more about Debian packages, I also advise you to read the Ubuntu Packaging Guide.
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 Ubuntu package archives for mtr. Note the updated mtr version for Jaunty.
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 pbuilder mtr build log.
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!
mtr 0.75 for Ubuntu Hardy is now in the repository.
Leave a Reply