See www.zabbix.com for the official Zabbix site.

Docs/howto/rebuild debs

From Zabbix.org
Jump to: navigation, search

Rebuilding a package from source in Debian and derivatives (Mepis, Mint, Ubuntu)

This guide will focus primarily in Debian, although building from source in other derivatives should be basically the same process. The upstream documentation on package management is ultimately the most authoritative source of wisdom.

Why should you choose packaging over "make install"?

The reasons have been nicely summarized here.

Where are the source packages?

To find out what versions can be found in the official repositories, the following URLs can be used:

This guide addresses the following scenarios

  1. You are using Debian stable, and want to rebuild from source to change some default options
  2. You are using Debian stable, and want to use the version in testing or unstable
  3. You want to build a deb package from upstream sources
  4. Alternatives to the official Debian packaging system
  • The rest of the guide will assume the commands are being run by a non-root user with sudo access
   $ sudo -l
   $ sudo aptitude install build-essential devscripts quilt

1. You are using Debian stable, and want to rebuild the sources

This would be the case when you want to activate/deactivate some feature that's built by default in the precompiled binaries, apply an extra patch, backport a feature, use compile-time optimizations (target an specific platform, hardening options). The steps would be:

  • Create a temporary directory to work in
   $ mkdir ~/temp && cd ~/temp
  • Get the source package
   $ apt-get source zabbix

or alternatively (if you don't have a deb-src line in your sources.list pointing to the stable release), you can get the .dsc file from the web, for current stable this would be

   $ dget http://ftp.de.debian.org/debian/pool/main/z/zabbix/zabbix_1.8.2-1squeeze4.dsc
  • Any of the two alternative methods will
  1. fetch the sources from the repositories
  2. validate the cryptographic signature of the package
  3. apply all distro specific patches
  • Check the debian/rules makefile
   $ cd zabbix*
   $ vi debian/rules

This is the main makefile for the packaging process, here you can review optional configure options, and can also enable/disable features regarding all the packages that will be built (server, agent, proxy)

  • Review the patches with quilt

Let's suppose you are interested in one or more of the distro patches not being applied. To check what patches are available in the sources, use

   $ quilt series

Check for the already applied patches (at this stage the list should be identical)

   $ quilt applied

Revert all the patches

   $ quilt pop -a

Optionally remove the unwanted ones

   $ quilt delete -r $patch_name

Apply the rest of the patches

   $ quilt push -a
  • Install the dependencies of the package you are going to recompile
   $ apt-get build-dep zabbix
  • Optionally tag the package
   $ dch -l +local 'Rebuilt from sources'

Check the dch manpage if you need to add a more elaborated changelog entry.

  • Finally, recompile the package
   $ debuild -us -uc

After the process, outside the zabbix-* directory, you will find the deb packages you just compiled, ready to install

   $ sudo dpkg -i $deb_package

2. You are using Debian stable, and want to use the version in testing or unstable

This process is known as backporting

The following precautions apply

  • The package might not build for you at all
  • In order to build it might need updated dependencies
  • In order to build it might need additional packages
  • The packaging layout might have changed


The process is the same as rebuilding for the stable release, with the exception of the source package, which can be obtained either from apt repositories using a line like this in your sources.list (note, only one of the two alternatives)

   deb-src http://ftp.de.debian.org/debian/ testing main non-free contrib
   deb-src http://ftp.de.debian.org/debian/ unstable main non-free contrib

or again, using the web

   $ dget http://ftp.de.debian.org/debian/pool/main/z/zabbix/zabbix_2.0.5+dfsg-1.dsc

An extra precaution would be tagging the packages to ease identification in case uninstallation is needed.

   $ dch -l ~local 'Sid backport'

The rest of the process is identical, and the result will be backported packages that can be installed along the rest.

3. You want to build a deb package from upstream sources

If you want or need a more recent version than the one that can be found in Sid, you can still check the experimental repository, and the git repository of the mantainer(s) to see if there's something in the works. Beyond that, you need to use the upstream project Subversion repo, but yet one can benefit from the Debian packaging structure. To that end, a snapshot of the latest stable or alpha release can be downloaded. So, after having downloaded the source package from the distro repo as outlined above, the next steps would be (differences in the versions in use might apply):

    $ wget http://www.zabbix.com/downloads/nightly/pre-zabbix-2.0.6rc1-34153.tar.gz
    $ mv pre-zabbix-2.0.6rc1-34153.tar.gz zabbix_2.0.6rc1-34153.orig.tar.gz
    $ cd zabbix-1.8.2
    $ uupdate ../zabbix_2.0.6rc1-34153.orig.tar.gz -v 2.0.6
    $ cd ../zabbix-2.0.6

After this, all the patches in the debian/patches must be reviewed in order to determine if they still are useful or have to be discarded. Use quilt as described above. Finish the recompile process tagging

   $ dch -l ~local 'Upstream packaging'

rebuilding

   $ debuild -us -uc

and installing

   $ sudo dpkg -i $deb_package

the package(s).

4. Alternatives to the official Debian packaging system

Some people find the Debian packaging system excessively complicated but still want to benefit from the advantages of using a packaged software. Some projects exist that try to address this situation. A list is given here, but the details of using these tools is left as an exercise for the reader.


David Sastre Medina, 2013

d.sastre.medina<at>gmail.com

dawud on freenode.net IRC

This page has been written using the RPM howto as a template. Thanks, Volter. Please help improving this page with comments, suggestions and corrections.

Alternative approach using a chroot

pbuilder is a comfortable way to set up a chroot, install the package's build requirements and actually build it for any Debian release you like. Be aware that there are various reasons why such a private backport may fail! With a suitable .pbuilderrc in place, building is quite comfortable:

Pre-requisites

.pbuilderrc:

   # Inspired by https://wiki.debian.org/PbuilderTricks
    
   HOOKDIR="/var/cache/pbuilder/hook.d/"
    
   # List of Debian suites.
   DEBIAN_SUITES=(sid squeeze wheezy jessie stretch)
   STABLE_SUITES=(wheezy jessie squeeze)
    
   # Mirrors to use. Update these to your preferred mirror.
   DEBIAN_MIRROR="ftp.de.debian.org"
    
   # 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 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"
   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"
       if $(echo ${STABLE_SUITES[@]} | grep -q $DIST); then
           if [ $DIST == "squeeze" ]; then
               SQUEEZESITE="http://$DEBIAN_MIRROR/debian-backports/"
               OTHERMIRROR="$OTHERMIRROR | deb $SQUEEZESITE $DIST-backports $COMPONENTS"
           else
               OTHERMIRROR="$OTHERMIRROR | deb $MIRRORSITE $DIST-backports $COMPONENTS"
           fi
       fi
   else
       echo "Unknown distribution: $DIST"
       exit 1
   fi

E01apt-preferences:

   #!/bin/sh
   set -e
    
   STABLE_VERSION_REGEX='^6.*'
    
   if $(egrep -q "$STABLE_VERSION_REGEX" "/etc/debian_version"); then
   cat > "/etc/apt/preferences" << EOF
   Package: debhelper
   Pin: release a=squeeze-backports
   Pin-Priority: 999
    
   Package: lintian
   Pin: release a=squeeze-backports
   Pin-Priority: 999
    
   Package: man-db
   Pin: release a=squeeze-backports
   Pin-Priority: 999
   EOF
   fi

https://wiki.debian.org/PbuilderTricks

Doing the rebuild

 # You only need to download the sources once, of course
 dget http://ftp.de.debian.org/debian/pool/main/r/redis/redis_2.8.17-1.dsc
 # Override the .pbuilder defaults as needed
 export DIST=jessie
 #export ARCH=i386
  
 pbuilder create
 pbuilder build redis_2.8.17-1.dsc

The resulting packages are now in /var/cache/pbuilder/$NAME/result/. You can now sign them and/or put them in a repo, as desired.