Debian Packaging: From Source to Repository
Patches and Source Management
A practical Debian packaging course lesson covering patches and source management.
Patches and Source Management
Debian maintainers sometimes need to modify upstream source code to fix bugs, adapt software to Debian, or make builds work on a particular platform.
The 3.0 (quilt) source format provides a structured way to maintain such changes.
In this lesson, we will understand the role of quilt, inspect a patch series, and create a small illustrative patch.
Learning Objectives
- Understand the difference between upstream source and Debian changes.
- Learn how quilt organizes patches.
- Inspect the patch series metadata.
- Create and apply a simple patch.
- Keep patches focused and documented.
1. Why Maintain Patches?
A patch is a controlled change to source code.
Common reasons include:
- Fixing a bug before upstream accepts a fix.
- Adapting a build for Debian.
- Applying a security fix.
- Disabling behavior that is unsuitable for a distribution.
Whenever possible, changes should be sent upstream so that Debian does not need to maintain them indefinitely.
2. The Debian Patch Directory
For source format 3.0 (quilt), Debian patches are commonly stored in:
1
2
3
debian/patches/
├── series
└── example.patch
The series file lists patches in the order they should be applied.
Create the directory:
1
2
cd ~/packaging-lab/syspeek
mkdir -p debian/patches
3. Create an Illustrative Patch
For teaching purposes, add a small comment to the application source.
First, create a patch file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat > debian/patches/document-source.patch <<'EOF'
Description: Add a packaging-course source comment
This patch demonstrates how Debian changes can be recorded
separately from the upstream source.
--- a/main.go
+++ b/main.go
@@ -1,4 +1,5 @@
package main
+// Syspeek is a small Linux system information utility.
import (
"flag"
"fmt"
EOF
Add it to the series:
1
printf 'document-source.patch\n' > debian/patches/series
This patch is illustrative. In a real package, patches should address an actual need and should be tested against the exact upstream source version.
4. Apply and Reverse Patches
The quilt tool can apply patches listed in the series file:
1
quilt push -a
Inspect the applied patch:
1
quilt applied
To reverse the most recently applied patch:
1
quilt pop
If you are working with a source tree already prepared by dpkg-source, the patch state may be managed as part of the source-package workflow.
5. Keep Patches Maintainable
A good patch should:
- Have a clear filename.
- Explain why the change is needed.
- Be as small as practical.
- Apply cleanly to the intended source version.
- Include an upstream status when relevant.
- Be removed when the change is no longer needed.
Do not use patches as a substitute for ordinary packaging metadata. A change to debian/control belongs in the packaging files, not in an upstream source patch.
6. Source Control and Review
Use version control to review changes:
1
git diff
If this project is not yet a Git repository, initialize one when you are ready to track changes:
1
2
3
git init
git add .
git status
This is optional for the package build itself, but source control makes it easier to review packaging changes and recover from mistakes.
7. What We Learned
We introduced quilt and the debian/patches/series file. We also discussed why patches should be small, documented, and preferably contributed upstream.
Exercises
- Inspect the
seriesfile. - Apply and reverse the example patch.
- Write a short description explaining why the patch exists.
- Read the Debian documentation on the
3.0 (quilt)source format.
What’s Next?
A package that builds is not necessarily a good package. Next, we will test Syspeek, inspect the package with Lintian, and learn about automated package tests.