Hacking on Debian packages - the quick and dirty way

TurnKey user Ed Carp was recently trying to install TKLBAM on Linux Mint 20.3/Una (which is based on Ubuntu 20.04/Focal). Despite my best efforts, he kept hitting issue after issue.

As part of that troubleshooting process, I wanted to hack on the problematic package and see if I could work around a dependency issue. It turns out that on this occasion, it really wasn't compatible and I had to generate a specific Ubuntu 20.04 compatible build of the package. I'd really like to improve TKLBAM support for Ubuntu and Mint (and other Ubuntu based derivatives), but that's for another day....

This post isn't about TKLBAM, or even Ubuntu; it's about hacking on Debian packages. I decided to write this post for myself as much as anything else. I have used these steps on multiple occasions, but every time I've had to google to remember the exact commands. So I decided to document it as a quick reference for myself. But then I decided to post it all as a blog post as perhaps others might also find value?!

As noted above, I used these instructions to tweak the dependency requirements of a package (I edited the control file). This method can also be used to make other package modifications, such as tweaking and testing of pre and post, install and removal scripts. Plus obviously the binary and other files that get copied to the filesystem.

Download a deb file from a repository

apt-get download PACKAGE_NAME

Where PACKAGE_NAME is the name of the package as noted by tools such as 'apt policy' or 'apt search'.

Unpack a deb package

mkdir -p tmp
dpkg-deb -R PACKAGE_DEB_NAME.deb tmp

Where tmp is a local directory (I literally use 'tmp' but you can use any directory name) and PACKAGE_DEB_NAME.deb is the actual deb file name (and filepath if not in the local dir).

Hack on the package

The package contents will be decompressed to the tmp directory noted in the above command. That contains all the binary files and/or other Debian files (e.g. man pages, changelog, config files, etc). All the Debian packaging files (e.g. control, postrm, etc) will be in a DEBIAN subdirectory. These files can be changed/edited/replaced/etc.

Repack a deb package

Once you have finished hacking on the package, repack it to test.

dpkg-deb -b tmp FIXED_DEB_NAME.deb

Where tmp is the local directory (as noted above) and FIXED_DEB_NAME.deb is the new name you want to give the resulting deb file (and filepath if not in the local dir).

Install local package

apt-get install -y ./FIXED_DEB_NAME.deb

Where FIXED_DEB_NAME.deb is the actual name of the new deb file created above. Be sure to prefix the full path to the file, or prefix with './' if in the local dir.

Also, if you no longer need them, both the downloaded deb file and the unpacked tmp directory can both be cleaned up.

Add new comment