Software Development with Linux

Re building DEB sources using Gentoo Sabayon

WED, 01 JUN 2011

While it is easier to build packages for a Linux distribution using that distribution, that solution is not always available or usable.  For example, you may not want to start a VM each time you want to build a package, or maintain chroot environment for all distributions, especially if you only want to re-create sources.

Now, in the same vein as Building source and binary .deb from .dsc, .orig.tar.gz, and .debian.tar.gz files, here is how to re-build those sources using Gentoo or Sabayon Linux.

First, lets install the required packages.  Those commands or for Sabayon Linux, but you should be able to to that using emerge if you are using Gentoo.


  1. Install dpkg, fakeroot, and debhelper


    • sudo equo install dpkg fakeroot debhelper



  2. Create a fake status file


    • sudo touch /var/lib/lib/dpkg/status




Now, onto the .deb source creation itself.


  1. Create a directory to work from


    • mkdir newpackage && cd newpackage



  2. Download the .dsc, .orig.tar.gz, and .debian.tar.gz files for the software you needed.

  3. Create the source directory


    • dpkg-source -x <packagename_version>.dsc



  4. Get into the package source directory


    • cd <packagename-version>



  5. Change what you want to change in the package (debian/control, debian/changelog, etc.)

  6. Rebuild the sources


    • dpkg-buildpackage -rfakeroot -S -Zbzip2 -us -uc




That's it!  Your new sources files (.dsc, _source.changes, and .debian.tar.bz2) should be in the previous directory (cd .. to get back to it).

Now, the source package won't be signed.  If you need to, you'll have to do it manually, like this :


  1. Sign the .dsc file


    • echo "" >> <packagename>_<version>.dsc

    • gpg --clearsign <packagename>_<version>.dsc

    • mv <packagename>_<version>.dsc.asc <packagename>_<version>.dsc



  2. Get updated information about the .dsc file


    • sha1sum <packagename>_<version>.dsc

    • sha256sum <packagename>_<version>.dsc

    • md5sum <packagename>_<version>.dsc

    • ls -l <packagename>_<version>.dsc | awk '{ print $5 }'



  3. Update the _source.changes file with the previous information.  You need to change the SHA1 and SHA256 checksum values.  The MD5 checksum value goes into the unlabelled section.  And don't forget to update the size of the .dsc file too, which you got from the previous 'ls' command.

  4. Sign the _source.changes file


    • echo "" >> <packagename>_<version>_source.changes

    • gpg --clearsign <packagename>_<version>_source.changes

    • mv <packagename>_<version>_source.changes.asc <packagename>_<version>_source.changes




You can check the validity of those files by using dpkg-source -x to extract them, as you did when you started.