How to patch & build an existing Debian/Ubuntu package

Publikováno

v

,

Sometimes you need to make a small change into some package that is already present in the repository. Even though the repository may contain an older version of the package than upstream, it can be easier to modify it instead of building the upstream package from scratch, because all the build dependencies can be easily installed and no manual configuration is required.

The steps shown below should work for any Debian/Ubuntu package, but I use the Ubuntu kernel as an example, because I need to use a quirk for my external drive enclosure.

1. Get the current package name, install build dependencies and download the source

sudo apt update
apt list linux-image-unsigned-*
sudo apt build-dep linux-image-unsigned-6.8.0-51-generic
apt source linux-image-unsigned-6.8.0-51-generic

2. Make the required modifications

cd linux-6.8.0
vim drivers/usb/storage/unusual_uas.h

3. Update the package version

dch -i
linux (6.8.0-51.52uas1) noble; urgency=medium

  * JMicron UAS patch

 -- Martin Prokopič <martin@prokopic.net>  Wed, 25 Dec 2024 20:05:10 +0000

Kernel packages have two identical changelogs for some reason and dch updates only one, so we need to manually update the other:

cp debian/changelog debian.master/changelog

4. Build the kernel packages

dpkg-buildpackage -rfakeroot -b -us -uc

If you think you’ll need multiple attempts, you can build with ccache as follows:

PATH="/usr/lib/ccache:$PATH" DEB_BUILD_OPTIONS="ccache" dpkg-buildpackage -rfakeroot -b -us -uc