Backporting Debian packages with pbuilder

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.

Tags: ,

  1. Steve’s avatar

    I’m interested in ‘forward porting’ of php4 packages from Debian Etch to Debian Lenny.

    I tried this out with pbuilder but had failed dependencies lots of things like:

    Unpacking pbuilder-satisfydepends-dummy (from …/pbuilder-satisfydepends-dummy.deb) …
    dpkg: dependency problems prevent configuration of pbuilder-satisfydepends-dummy:
    pbuilder-satisfydepends-dummy depends on apache-dev (>= 1.3.23); however:
    Package apache-dev is not installed.

    Is this an insurmountable obstacle?

    Reply

    1. tyler’s avatar

      No, it is not insurmountable. However, you’ll probably need to edit the package (.dsc file and create a new .diff) to change the dependencies in the individual packages. Probably apache-dev has been renamed, and other packages. PHP is a complicated set of packages, so you might have some work ahead of you.

      Reply

    2. Steve’s avatar

      ahhh I had thought that pbuilder was going to work out dependencies.

      It looks as if I have to work out all the dependencies and install or build each one of them manually.

      I’ve found that in many cases while the dependencies it complains about are available in Lenny pbuilder doesn’t install them while in other cases it does.

      Its been pretty confusing so far, however this is possibly because I’m ‘forward porting’ rather than ‘back porting’. In working my way toward php4 I had to build db4.4 packages as Lenny appears to have 4.2,4.5 and 4.6… but 4.4 conflicts with these… so that wasn’t going to work out. I gave up at this point; as sole sysadmin in a small web development/hosting company, I don’t have time to resolve this complexity.

      It would be lovely if there were already existing php4 packages for Lenny :( I know php4 won’t get any security updates but that doesn’t mean I shouldn’t maintain the rest of the packages on the servers… and we don’t have the resources to upgrade all of our apps to php5 in anything like a reasonable amount of time (ie before end-of-life for Etch).

      Reply

    3. tyler’s avatar

      pbuilder will download and install any packages needed to build your target package. However, you’ll still have to download .dsc, .diff, and .tar.gz files for all the packages you want to build, and build them. Some of your new packages may depend on the ones you’ve previously built, so you’ll have to make them available too. See this, You’ll also have to use your /var/cache/pbuilder/DIST-ARCH/result directory as a local apt-cache. That link will help.

      I’ve run PHP4 packages from Ubuntu dapper in hardy (just never removed them after upgrade), and they work fine. At least, as php4-cgi (not as an apache module). That allowed me to run legacy apps for the year I needed to remove them.

      Reply

    4. Adam’s avatar

      Thank you. That’s really useful. I now have a very nice package for darcs2 on hardy.

      Reply

    5. Jason Boxman’s avatar

      I just went through this for the latest Apache packages from Lenny for an Etch box. The pbuilderrc is quite appreciated. I moved my care-n-feeding hooks into the user dir and everything worked. Backporting Apache 2.2 to Sarge was more of a challenge, though. I didn’t know about dget. Also awesome.

      Thanks.

      Reply

    6. SKaRCHa’s avatar

      Very, very useful… This helped me to backport some packages from Ubuntu Karmic to Ubuntu Jaunty…

      Thank you very much! ;)

      Reply

    7. Kushal Koolwal’s avatar

      Say I want to backport a package from Jaunty to Hardy. So should I be installing the pbuilder and doing all the build process on Jaunty or Hardy. Or it does not matter?

      Reply

    8. tyler’s avatar

      Kushal,

      It doesn’t matter. On either platform, download the jaunty source files, and run:

      sudo DIST=hardy pbuilder builder program.dsc

      Reply

    9. sassyn’s avatar

      Hi,

      Thanks for this.

      I followed this, but didn’t manage to make it happen.
      The problem is that the pkg I need is coming from version 14.04 and i run 12.04
      So I dget the foo.dsc and try to build it using pbuilder, but the foo.dsc needs some other pkgs version which are no exits in the verion 12.04,
      so it failed.
      I started to download each required pkg (bar.dsc, zoo.dsc, etc…) that foo was depend on, but then got to a endless loop, since bar.dsc also wanted some pkg that where missing in the 12.04.

      So I play a little with the control file of the foo pkg, and got to a point where I had only 4 pkg that need to come from version 14.04 to version 12.04.
      I manage to build them, and also create a local repo, so the base image of pbuilder will be aware of them.

      Then try to build the foo.dsc and failed again.
      What am I’m doing wrong?

      It’s being a week already without any sleep – and I just can’t figure it out.

      Help will be mot welcome!

      Thank
      Sassy

      Reply

      1. Tyler Wagner’s avatar

        You’re not doing anything wrong, Sassy. That’s just how backporting goes. You keep backporting dependencies until you get all of them, or you discover that it won’t be possible to backport this package.

        What package is it?

        Reply

Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.