[Debian] How to modify debian packages
by Riley MacDonald, January 28, 2018

Knowing how to modify Debian packages on unix systems is a powerful asset for (but not limited to):

  • Creating detailed issue/bug reports
  • Debugging issues
  • Developing new features

The following packages are suggested for Debian package management/modification:

  • devscripts
  • apt
  • dpkg

Fetch the sources
If you have deb-src sources included in your /etc/apt/sources.list (entries which begin with deb-src) you can use apt to fetch package sources. Alternatively you can commonly use wget, dget, dpkg-source -x (extract source from a dsc-file) or git to fetch packages.

$ sudo apt source <package>

Installing Dependencies
Dependencies of a package are defined in the debian control file at debian/control. Use apt build-dep ./ to install the dependencies required to build the package.

Make the desired changes
Now that you have access to all the source files you can make your changes as required.

Incrementing Package Version
When modifying packages you’ll want to append something unique to the package version in order to distinguish your changes from the original package. It’s best practice to update the changelog when making changes. This can be done easily using dch (the debchange package found within the devscripts package):

/sourcePackage/ $ dch --local "-version-append" "change log entry and description of change"

Applying Patches
In some cases you’ll want to apply a patch to your package. Patches (which are essentially diffs can be applied using the patch command):

$ wget http://somepatch.com
    -> /tmp/some-patch
$ patch -p1 < /tmp/some-patch

After applying a patch don’t forget to bump the version number using dch (see “Incrementing Package Version” above). Some patches may require additional steps (such as quilt patch versions). These types of patches will need to be applied using another technique such as dpkg-source --commit which I won’t cover in this post.

Building the .deb package(s)
Now that you’ve applied your changes and bumped the version number it’s time to build the package. The build process is handled by dpkg-buildpackage. In this example I use the -us and -uc arguments to get around potential gnupg signing issues.

$ dpkg-buildpackage -us -uc -b

If you intend to publish the package consider using debuild which creates all the files necessary for uploading a Debian package. See the manpage for details.

Building will generate several .deb files in the parent directory (all for different architectures). Use apt install or dpkg to install the deb for your machine (apt will handle any missing dependencies, dpkg won’t).

Open the comment form

Leave a comment:

Comments will be reviewed before they are posted.

User Comments:

Be the first to leave a comment on this post!