6.7. Repairing Package Problems
Package management fails in ways that are consistent enough to have standard answers: a transaction interrupted halfway, a dependency that cannot be satisfied, a repository whose signature or freshness no longer checks out. The repair paths are short because the two-layer design keeps the failure visible - dpkg's database always states exactly where a package stopped, and apt's errors name the source and the reason. This section works each failure as it actually presents, then closes with the logs and cached files that answer "what happened here, and what do I have to work with?".
| Symptom | First command | Section |
|---|---|---|
| An install or upgrade stopped mid-transaction | dpkg --audit |
6.7.1 |
A package is stuck half-configured |
dpkg --configure -a |
6.7.1 |
A package is stuck unpacked, dependencies missing |
apt-get -f install |
6.7.1 |
apt-get update warns about signatures |
check the source's key | 6.7.2 |
apt-get update calls a release expired |
re-sign or re-stage | 6.7.2 |
| "What did apt do last Tuesday?" | /var/log/apt/history.log |
6.7.3 |
6.7.1. Interrupted Configuration and Broken Dependencies
Two fixtures were built for exactly this section. The first,
ch06-fragile, carries a postinst that refuses to complete when a
particular file exists - a faithful stand-in for any real package whose
configuration step fails on a bad config file, an unreachable service,
or an unwritable directory. Create the obstacle, then install:
# touch /etc/ch06-fragile-block
# dpkg -i /home/john/debian-handbook/package-management/local-packages/ch06-fragile_1.0_all.deb
Selecting previously unselected package ch06-fragile.
(Reading database ... 111166 files and directories currently installed.)
Preparing to unpack .../ch06-fragile_1.0_all.deb ...
Unpacking ch06-fragile (1.0) ...
Setting up ch06-fragile (1.0) ...
ch06-fragile: refusing configuration because /etc/ch06-fragile-block exists
dpkg: error processing package ch06-fragile (--install):
installed ch06-fragile package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
ch06-fragile
touch prints nothing; the install is the failure under study. The
sequence is exact: dpkg unpacked the package - the files are on disk -
and then Setting up ran the postinst, whose message and nonzero exit
appear exactly as a terminal shows them, followed by dpkg's own error
report. The
transaction failed, and dpkg's exit status is nonzero, but the database
now records a precise intermediate state:
$ dpkg-query -W -f='${Status}\n' ch06-fragile
install ok half-configured
That is the row of the state table in Section 6.1.3: wanted, flagged, and caught halfway through configuration. The audit command from the same section is the systematic way to find every such package on a machine:
# dpkg --audit
The following packages are only half configured, probably due to problems
configuring them the first time. The configuration should be retried using
dpkg --configure <package> or the configure menu option in dselect:
ch06-fragile Local test package ch06-fragile version 1.0
The repair is two steps, both silent until the second produces its result: remove the obstacle the script complained about, then resume configuration - not by reinstalling, which would repeat the unpack, but by telling dpkg to finish what it started:
# rm -f /etc/ch06-fragile-block
# dpkg --configure -a
Setting up ch06-fragile (1.0) ...
dpkg --configure -a configures every package pending configuration -
the single command that recovers an interrupted upgrade, whatever
interrupted it. With the obstacle gone the postinst succeeds, the
Setting up line completes, and the state confirms it:
$ dpkg-query -W -f='${Status}\n' ch06-fragile
install ok installed
dpkg --configure -a succeeds silently when nothing is pending, so it is
safe to run on suspicion. Clear the fixture with
sudo apt-get purge ch06-fragile (the usual summary and confirmation;
the needrestart hook's skip notice after the failed run is the one line
worth ignoring in that output - the hook states its own reason).
The second fixture fails the other way: ch06-broken-deps declares a
dependency on a package that does not exist anywhere, the exact state a
machine reaches when a locally installed archive needs something a
removed repository used to provide. Install it with dpkg, which does
not resolve dependencies:
# dpkg -i /home/john/debian-handbook/package-management/local-packages/ch06-broken-deps_1.0_all.deb
Selecting previously unselected package ch06-broken-deps.
(Reading database ... 111166 files and directories currently installed.)
Preparing to unpack .../ch06-broken-deps_1.0_all.deb ...
Unpacking ch06-broken-deps (1.0) ...
dpkg: dependency problems prevent configuration of ch06-broken-deps:
ch06-broken-deps depends on ch06-missing-package (>= 1.0); however:
Package ch06-missing-package is not installed.
dpkg: error processing package ch06-broken-deps (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
ch06-broken-deps
Unpacking succeeded and configuration was refused - a different intermediate state:
$ dpkg-query -W -f='${Status}\n' ch06-broken-deps
install ok unpacked
This is where APT takes over, because dependency repair is a resolution
problem and that is APT's layer. apt-get -f install re-plans the
whole system with broken dependencies as its first constraint:
# apt-get -f install
Reading package lists...
Building dependency tree...
Reading state information...
Correcting dependencies... Done
The following packages will be REMOVED:
ch06-broken-deps
0 upgraded, 0 newly installed, 1 to remove and 29 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 111166 files and directories currently installed.)
Removing ch06-broken-deps (1.0) ...
Selected output; progress lines and the needrestart hook's skip notice omitted.
Correcting dependencies... is apt re-resolving; the plan it offers is
the honest one, because the missing dependency cannot be satisfied from
any configured source - so the repair removes the package that demands
it. Read the plan when the command offers it: with a real missing
dependency the fix may instead be to install something (a package
renamed upstream, a repository that should be re-added), and -f
install will propose that when it is possible. Confirm the end state
and the machine-wide audit:
$ dpkg-query -W ch06-broken-deps
dpkg-query: no packages found matching ch06-broken-deps
# dpkg --audit
The query fails because the package is gone entirely; the audit prints
nothing because nothing else is pending. Those two silent answers close
the case. One rule of order matters before anything else in this
section: run dpkg --configure -a and apt-get -f install before
attempting new installs or upgrades - apt refuses most forward work
while the database is inconsistent, and the two repair commands exist
to make the database consistent. When a broken system cannot boot far
enough to run them, the same two commands run from a rescue
environment's chroot - Chapter 16 covers that path,
including the mount points it needs.
6.7.2. Repository Errors, Expired Metadata, and Signature Failures
Repository failures announce themselves at apt-get update, and the
two kinds worth rehearsing are a signature that stops verifying and
metadata that has gone stale. Both are induced here deliberately, on
the practice archive, because the failure output is the part worth
reading.
The signature failure first. Corrupt the archive's InRelease - one
byte of the signed content changed, so the signature no longer matches
it - keeping a good copy to restore from:
# cp /srv/ch06-repo/dists/trixie/InRelease /root/ch06-InRelease.good
# sed -i "s/^Origin: Debian Handbook Lab$/Origin: Debian Handbook Lab X/" /srv/ch06-repo/dists/trixie/InRelease
Both commands are silent. This is the deliberate fault - the same file a truncated download or a tampered mirror would present. Now update:
$ sudo apt-get update
Get:1 file:/srv/ch06-repo trixie InRelease [1876 B]
Get:1 file:/srv/ch06-repo trixie InRelease [1876 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Err:1 file:/srv/ch06-repo trixie InRelease
Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
Get:4 file:/srv/ch06-offline/repo trixie/main amd64 Packages [676 B]
Hit:5 https://deb.debian.org/debian trixie InRelease
Hit:6 https://security.debian.org/debian-security trixie-security InRelease
Hit:7 https://deb.debian.org/debian trixie-updates InRelease
Hit:8 https://deb.debian.org/debian trixie-backports InRelease
Reading package lists...
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. OpenPGP signature verification failed: file:/srv/ch06-repo trixie InRelease: Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
W: Failed to fetch file:/srv/ch06-repo/dists/trixie/InRelease Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
W: Some index files failed to download. They have been ignored, or old ones used instead.
Three facts in that output decide everything. The verification ran and
failed - sqv, apt's signature checker, states the reason plainly:
the message has been manipulated. The failed source is isolated: the
other two local archives and all four Debian suites refreshed
normally. And the run's summary says what happens next: the failing
repository is not updated, the previous index files stay in use, and -
note the exit status - the command succeeds with warnings. That
lenience is apt's default: one broken source does not block the
machine's other updates. For scripts and automation that must treat
any failed source as fatal, one option turns the same failure into an
error:
$ sudo apt-get -o APT::Update::Error-Mode=any update
Get:1 file:/srv/ch06-repo trixie InRelease [1876 B]
Get:1 file:/srv/ch06-repo trixie InRelease [1876 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Err:1 file:/srv/ch06-repo trixie InRelease
Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
Hit:4 https://security.debian.org/debian-security trixie-security InRelease
Hit:5 https://deb.debian.org/debian trixie InRelease
Hit:6 https://deb.debian.org/debian trixie-updates InRelease
Hit:7 https://deb.debian.org/debian trixie-backports InRelease
Reading package lists...
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. OpenPGP signature verification failed: file:/srv/ch06-repo trixie InRelease: Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
E: Failed to fetch file:/srv/ch06-repo/dists/trixie/InRelease Sub-process /usr/bin/sqv returned an error code (1), error message is: Verifying signature: Message has been manipulated
E: Some index files failed to download. They have been ignored, or old ones used instead.
Identical failure, different contract: the E: lines make it an error,
and the command exits with status 100 instead of 0.
APT::Update::Error-Mode=any is the setting an unattended pipeline or
a monitoring script wants - a warning in a log is easy to miss; a
nonzero exit status is not.
Diagnosing a real signature failure means answering one question: did the content change, or did the key change? A content change on a source you control means a bad publish - re-sign and republish. A key change should have been announced with the new key's fingerprint; treat an unannounced one as a compromise until verified, and never "fix" the symptom by disabling signature checks. Restoring the good copy here is the content-change case:
# cp /root/ch06-InRelease.good /srv/ch06-repo/dists/trixie/InRelease
# apt-get update
Get:1 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:1 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:2 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:3 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Hit:4 https://security.debian.org/debian-security trixie-security InRelease
Hit:5 https://deb.debian.org/debian trixie InRelease
Hit:6 https://deb.debian.org/debian trixie-updates InRelease
Hit:7 https://deb.debian.org/debian trixie-backports InRelease
Reading package lists...
Silent cp, then a clean refresh: Err gone, no warnings, the source
trusted again.
The second failure is staleness. A copy of the practice archive with
its Valid-Until set to a date in the past - the state of any offline
bundle that waited too long, or any mirror whose publishing stopped -
makes a precise demonstration. Build it and point a source at it:
set -e
rm -rf /srv/ch06-expired
cp -a /srv/ch06-repo /srv/ch06-expired
cd /srv/ch06-expired
sed -i "s/^Valid-Until:.*/Valid-Until: Thu, 01 Jan 2026 00:00:00 UTC/" dists/trixie/Release
GNUPGHOME=/srv/ch06-gnupg gpg --batch --yes --pinentry-mode loopback --passphrase "" \
--default-key lab@example.org --clearsign -o dists/trixie/InRelease dists/trixie/Release
GNUPGHOME=/srv/ch06-gnupg gpg --batch --yes --pinentry-mode loopback --passphrase "" \
--default-key lab@example.org -abs -o dists/trixie/Release.gpg dists/trixie/Release
grep "^Valid-Until:" dists/trixie/Release
Listing saved as /srv/ch06-expired-build.sh. Run it in the root shell:
# bash /srv/ch06-expired-build.sh
gpg: using "lab@example.org" as default secret key for signing
gpg: using "lab@example.org" as default secret key for signing
Valid-Until: Thu, 01 Jan 2026 00:00:00 UTC
The re-signing inside the script is what a publisher maintaining an old
snapshot would really do - the two gpg key-selection notices appear on
standard error, exactly as in Section 6.6.4's build - and the closing grep
prints its one line, confirming the planted date. The source file
/etc/apt/sources.list.d/ch06-expired.sources differs from the local
one only in its URI:
Types: deb
URIs: file:/srv/ch06-expired
Suites: trixie
Components: main
Signed-By: /etc/apt/keyrings/ch06-lab.asc
Now update against it, using the strict error mode so the verdict is unambiguous:
$ sudo apt-get -o APT::Update::Error-Mode=any update
Get:1 file:/srv/ch06-expired trixie InRelease [1874 B]
Get:1 file:/srv/ch06-expired trixie InRelease [1874 B]
Get:2 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:3 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:4 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:2 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:3 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:4 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Hit:5 https://security.debian.org/debian-security trixie-security InRelease
Hit:6 https://deb.debian.org/debian trixie InRelease
Hit:7 https://deb.debian.org/debian trixie-updates InRelease
Hit:8 https://deb.debian.org/debian trixie-backports InRelease
Reading package lists...
E: Release file for file:/srv/ch06-expired/dists/trixie/InRelease is expired (invalid since 321d 21h 44min 58s). Updates for this repository will not be applied.
The signature verified - this is not a trust failure - but the
freshness check refused the metadata: expired, invalid for 321 days and
change, and explicitly "updates for this repository will not be
applied". The Valid-Until field exists precisely so that an
adversary who captures a snapshot of a repository today cannot keep
serving it forever; an honest archive that stops updating goes stale
the same way, by design. The remedies are on the publisher's side:
re-sign with a current Date and a fresh Valid-Until
(Section 6.6.4's script does this on every run), or generate releases
with a longer window when a long offline cycle is planned.
Section 6.6.5 covered the receiving side of that contract. Clean up the
practice source - sudo rm /etc/apt/sources.list.d/ch06-expired.sources
and sudo rm -rf /srv/ch06-expired /srv/ch06-expired-build.sh, both
silent - and the next refresh shows the source gone from the report.
Two further repository errors round out the vocabulary, both
recognizable by shape: an unreachable host produces Err: lines with
a connection error and the same old-indexes-retained behavior
(Chapter 2 demonstrated one with an unreachable
mirror, and Chapter 17 covers
separating DNS from connectivity failures); and a repository that
changes its Origin, Label, or Codename - a vendor shipping a new
release into the same URL - is refused as a release information
change until confirmed, with --allow-releaseinfo-change (or its
per-field variants) as the documented, deliberate confirmation for
automation that expects the change.
6.7.3. Package Logs, Cached Archives, and Recovery Paths
Repairs go faster when the evidence is at hand, and the package stack keeps three kinds of record. The transaction history is the first: apt logs every run with its command line, its requester, and its outcome:
$ tail -n 20 /var/log/apt/history.log
Install: ch06-tool:amd64 (1.0)
End-Date: 2026-11-18 21:43:18
Start-Date: 2026-11-18 21:43:38
Commandline: apt-get -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/ch06-offline.sources -o Dir::Etc::sourceparts=- -o Dir::State::lists=/srv/ch06-offline/lists -o Dir::Cache=/srv/ch06-offline/cache install ch06-leaf
Requested-By: john (1001)
Install: ch06-leaf:amd64 (1.0), ch06-dep:amd64 (1.0, automatic)
End-Date: 2026-11-18 21:43:42
Start-Date: 2026-11-18 21:44:15
Commandline: apt-get purge ch06-fragile
Requested-By: john (1001)
Purge: ch06-fragile:amd64 (1.0)
End-Date: 2026-11-18 21:44:16
Start-Date: 2026-11-18 21:44:27
Commandline: apt-get -f install
Requested-By: john (1001)
Remove: ch06-broken-deps:amd64 (1.0)
End-Date: 2026-11-18 21:44:28
Each entry brackets one transaction with start and end timestamps,
records the exact Commandline, the Requested-By account, and one
line per action - Install, Upgrade, Remove, Purge - with the
(automatic) marker preserved, so even a log-only reconstruction knows
which packages came in as dependencies. The excerpt above is this
chapter's own recent history: the reprepro install, the offline
transaction with its directory options visible, the fragile purge, and
the dependency repair. dpkg's own log is finer-grained, one line per
state change:
# grep "status installed" /var/log/dpkg.log | tail -n 10
2026-11-18 17:36:53 status installed gcc-14:amd64 14.2.0-19
2026-11-18 17:36:53 status installed g++-14-x86-64-linux-gnu:amd64 14.2.0-19
2026-11-18 17:36:54 status installed g++-14:amd64 14.2.0-19
2026-11-18 17:36:55 status installed gcc:amd64 4:14.2.0-1
2026-11-18 17:36:55 status installed g++:amd64 4:14.2.0-1
2026-11-18 17:36:56 status installed build-essential:amd64 12.12
2026-11-18 17:37:05 status installed man-db:amd64 2.13.1-1
2026-11-18 17:37:05 status installed libc-bin:amd64 2.41-12+deb13u4
2026-11-18 17:39:48 status installed apt-file:all 3.3
grep: /var/log/dpkg.log: binary file matches
The filter pairs one logical operation - every status installed line,
newest last. The closing note is grep's own: the log contains some
non-text bytes, so grep reports the binary match instead of printing
those lines; grep -a forces text treatment when the detail matters. A
third file, /var/log/apt/term.log, keeps the terminal transcript of
dpkg's runs - the unpack and setup lines, conffile prompts included -
for transactions whose history entry needs the detail. Both logs rotate
through logrotate; Chapter 8 covers retention
policy.
The second record is the archive cache of Section 6.6.1:
/var/cache/apt/archives/ holds what was recently fetched, and after a
failed upgrade the cached .deb files are recovery material - a
dpkg -i against the cached archive re-applies one package without
network, and the cache survives whatever interrupted the transaction.
apt-get clean deliberately destroys this record, which is a reason
not to run it casually on a machine with marginal connectivity.
The third record is the database's own consistency, and two commands assert it:
# apt-get check
Reading package lists...
Building dependency tree...
Reading state information...
apt-get check verifies that the installed package set satisfies its
own dependencies and exits 0 when it does - the quick health check to
run after any repair, and the answer here is the three silent lines
with no complaint following. Paired with dpkg --audit's empty output -
run it the same way - the two together say the machine is consistent
again, the state to reach before the chapter's practice material is put
away.
Beyond consistency, two further recovery paths exist for damage that
review and repair do not cover. dpkg --verify checks installed files
against the recorded checksums, naming any file that differs from what
its package shipped - the integrity baseline for an audit or a
suspected-modified system, and Chapter 26 uses it
that way. And a package whose installed copy is damaged is
reinstallable in place with apt-get install --reinstall pkg, which
replaces the files while leaving configuration and ownership of
/etc choices alone.
Finally, the practice material. Purge the remaining fixtures first - one
transaction, sudo apt-get purge ch06-demo ch06-leaf ch06-dep
ch06-tool, with the usual summary and confirmation - after which
dpkg-query -W 'ch06-*' reports no packages found. Then remove cowsay,
whose version policy opened Section 6.2.4 - a plain removal, since it
owns no configuration:
$ sudo apt-get remove cowsay
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
cowsay
0 upgraded, 0 newly installed, 1 to remove and 28 not upgraded.
After this operation, 94.2 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 111215 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-8) ...
Processing triggers for man-db (2.13.1-1) ...
Selected output; progress lines omitted. The "not upgraded" count is
the security batch again - with every fixture purged, nothing else
waits. Then the configuration and data, all of it deliberate and none
of it needed by the base system, as root: the three source files and
the pin (rm -f /etc/apt/sources.list.d/ch06-local.sources
/etc/apt/sources.list.d/ch06-reprepro.sources
/etc/apt/sources.list.d/ch06-offline.sources
/etc/apt/preferences.d/ch06-cowsay.pref), the exported keys
(rm -f /etc/apt/keyrings/ch06-lab.asc /etc/apt/keyrings/ch06-lab.gpg),
the signed archives with their signing key and build scripts
(rm -rf /srv/ch06-repo /srv/ch06-reprepro /srv/ch06-offline
/srv/ch06-gnupg and
rm -f /srv/ch06-offline-build.sh /root/ch06-InRelease.good). A final
sudo apt-get update returns the sources to Debian's four suites alone,
and john can clear the workspace with
rm -rf ~/debian-handbook/package-management - the fixtures, staged
archives, and downloaded .deb files are all reproducible from this
chapter's listings.
What remains is the loop the chapter has been teaching all along: sources configured and pinned deliberately, signed metadata verified on every refresh, changes planned before they are applied, configuration questions answered by policy rather than by accident, restarts and reboots decided from evidence, and a database that is either consistent or on its documented way back to consistency. The layers above it build on exactly that: services receive their packages the same way (Chapter 8), kernels arrive as packages with their own reboot discipline (Chapter 7), automated fleets apply these same apt commands through configuration management (Chapter 27), security baselines count on the update policy set here (Chapter 26), and the release-to-release upgrade of Chapter 29 is this chapter's routine, scaled up with its own staging rules.