29.5. Handling Upgrade Failures
Failures during a release upgrade fall into a few recognizable shapes: a package script leaves the database half-configured, a dependency cannot be satisfied, a service does not start after the reboot, or the host does not boot at all. Each has a different recovery path. The common mistake is to treat every failure as a reason to downgrade packages. A package downgrade is a narrow operation with narrow guarantees; it is not a system rollback.
29.5.1. Interrupted APT Operations and Dependency Conflicts
If apt or dpkg is interrupted, do not start another package operation blindly. First ask dpkg what state it recorded. On life1, in a root shell, install a practice package whose post-installation script deliberately fails:
# dpkg -i /srv/handbook-repo/handbook-broken_1.0.deb
Selecting previously unselected package handbook-broken.
(Reading database ... 68090 files and directories currently installed.)
Preparing to unpack .../handbook-broken_1.0.deb ...
Unpacking handbook-broken (1.0) ...
Setting up handbook-broken (1.0) ...
handbook-broken: refusing to configure
dpkg: error processing package handbook-broken (--install):
installed handbook-broken package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
handbook-broken
Selected output. The package files are installed but the package is not configured. Ask dpkg for the recorded state:
# 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:
handbook-broken Practice package whose configuration step fails
The report names the package and the operation to retry. For a package whose
script failed because of a transient condition - a missing directory, a service
that was not yet listening - fix the condition and retry the configuration with
dpkg --configure -a, which configures every unpacked package and prints
nothing when all of them complete. If the same package fails again, read the
script's error and the package documentation; a real package's postinst usually
names the file or service it could not reach. Do not remove configuration files
just to clear the state.
If the package is not needed and cannot be configured, remove it with the force option that is specific to this situation:
# dpkg --remove --force-remove-reinstreq handbook-broken
(Reading database ... 68088 files and directories currently installed.)
Removing handbook-broken (1.0) ...
After the removal, dpkg --audit prints nothing. The force option is narrow: it
allows removal of a package that dpkg would otherwise refuse to touch because its
state requires reinstallation. It does not repair dependencies and it does not
make a broken package safe to keep.
A package can also be unpacked while its dependencies are missing. dpkg -i
does not resolve dependencies; it installs or unpacks the named archive and
reports the dependency problem:
# dpkg --unpack /srv/handbook-repo/handbook-missing-dep_1.0.deb
Selecting previously unselected package handbook-missing-dep.
(Reading database ... 68090 files and directories currently installed.)
Preparing to unpack .../handbook-missing-dep_1.0.deb ...
Unpacking handbook-missing-dep (1.0) ...
The practice package declares a dependency on a package that no archive contains. APT can repair the resulting state by removing the package that cannot be configured, or by installing the missing dependency if one is available:
# apt-get -f install
Reading package lists...
Building dependency tree...
Reading state information...
Correcting dependencies... Done
The following packages will be REMOVED:
handbook-missing-dep
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Selected output; the removal follows. The package is gone because its declared dependency does not exist in any configured archive:
# dpkg-query -W handbook-missing-dep
dpkg-query: no packages found matching handbook-missing-dep
The nonzero exit and the message are the confirmation. A real dependency is
repaired by installing it, not by forcing the package to configure without it.
--force-depends may allow a package to configure while a dependency is missing,
but the resulting system is not a valid dependency state and the next upgrade
will encounter it again.
Conflicting packages fail before installation:
# dpkg -i /srv/handbook-repo/handbook-conflict_1.0.deb
Selecting previously unselected package handbook-conflict.
dpkg: regarding .../handbook-conflict_1.0.deb containing handbook-conflict:
handbook-conflict conflicts with handbook-agent
handbook-agent (version 2.0) is present and installed.
dpkg: error processing archive /srv/handbook-repo/handbook-conflict_1.0.deb (--install):
conflicting packages - not installing handbook-conflict
Errors were encountered while processing:
/srv/handbook-repo/handbook-conflict_1.0.deb
The package was not installed, and nothing remained to clean up:
# dpkg --purge handbook-conflict
dpkg: warning: ignoring request to remove handbook-conflict which isn't installed
The error names the conflict and the installed package that causes it, which is
the information needed to choose between them. Do not remove the installed
package without checking which service depends on it. If the conflict is real and
the old package must go, remove it with apt so that dependent packages are
handled, not with dpkg --force-all.
The dpkg options used in this section are:
| Option | Description |
|---|---|
-i, --install |
Install or upgrade the named .deb archives without resolving dependencies. |
--unpack |
Unpack the archive without configuring it; useful for inspecting a dependency failure. |
--configure -a |
Configure every package that is unpacked but not configured. |
--audit |
Report packages that are half-installed, half-configured, or otherwise broken. |
--remove |
Remove an installed package but keep its configuration files. |
--purge |
Remove the package and its configuration files. |
--force-remove-reinstreq |
Allow removal of a package whose state requires reinstalling it. |
--force-depends |
Configure despite a missing dependency; use only as a last resort and repair the dependency afterward. |
A broken package is not necessarily a broken system. The repair order is: read
dpkg --audit, fix the underlying cause, retry dpkg --configure -a, then use
apt-get -f install if the dependency graph is inconsistent. Reboot only after
the database is consistent, because a reboot does not repair package state.
29.5.2. Boot and Remote Access Failures After Upgrade
A host that does not boot after an upgrade needs the console, not another SSH attempt. Select the previous kernel in the boot menu if one is available. Debian keeps installed kernels until they are removed by autoremove or by an administrator, and the boot menu normally lists them. If the boot menu itself is missing, use the firmware boot menu or a rescue environment; Chapter 16 covers rescue media and initramfs repair, and Chapter 7 covers GRUB entries and kernel parameters.
A host that boots but does not accept SSH has a narrower set of causes. Check the
console or provider console for the login prompt and the network state. From a
local root shell, validate the daemon configuration - sshd -t prints nothing
when the configuration parses, exactly as in Section 29.3.1. Then check that the
daemon is listening where expected with ss -lntp, looking for the sshd
process on port 22 on both address families, as the inventory in Section 29.1.2
shows for this host. If the socket is absent, the service is not running or is
bound to a different address: check systemctl status ssh and the unit's journal.
If the socket is present but the client is rejected, the problem is
authentication, a firewall, or a host-key mismatch, not the listener.
Chapter 18 covers nftables rules and
Chapter 20 covers authentication debugging.
A changed host key produces a client warning such as "REMOTE HOST
IDENTIFICATION HAS CHANGED." This is a security event until proven otherwise.
Do not set StrictHostKeyChecking=no, and do not discard the known-hosts file.
Obtain the server's new fingerprint from the console or another trusted channel,
compare it with the warning, and investigate why the key changed. A reinstall or
a deliberately regenerated key explains the change; an unexplained change may
mean the host was replaced or compromised. After verification, remove only the
old entry with ssh-keygen -R 192.168.229.20; the command reports each line it
removed and the file it updated, and the next connection asks for confirmation
of the new key. On life1, as john, the practice host's trusted keys remained
in place through the upgrade:
$ ssh-keygen -F 192.168.229.20 -l
# Host 192.168.229.20 found: line 1
192.168.229.20 ED25519 SHA256:arNuNEbnLeV75SQx/SegQu3eZZyFn5MSBJkQdwNZ3qw root@trixie
# Host 192.168.229.20 found: line 2
192.168.229.20 RSA SHA256:Y2BnneHs+ajJOp7wxvEjlo6G4LePCSSgcfq4cwwB39U
# Host 192.168.229.20 found: line 3
192.168.229.20 ECDSA SHA256:dPf71Z3nAvUsLj1PuCEDBAzoPDgt4IAe0Zn8As9iUrI
A key that is still present and matches the trusted fingerprint is evidence that the host identity did not change during the upgrade. It is not evidence that the user's key or password still works; test an actual login and exit normally.
Boot failures often leave evidence in the previous boot's journal. From a rescue
or single-user environment, journalctl -b -1 -p err --no-pager shows
error-priority messages from the failed boot. A missing root device points to
storage or initramfs, a failed mount points to /etc/fstab or a network mount,
and a service timeout points to a unit dependency. Collect the evidence before
changing the boot loader; a blind grub-install can make a recoverable problem
worse.
29.5.3. Why Package Downgrades Are Not a General Rollback
A package downgrade replaces the files of one package with an older version. It does not reverse the package's maintainer scripts, database migrations, or configuration changes, and it does not downgrade the package's dependencies. The practice package demonstrates the limit. It is currently at version 2.0, whose post-installation script recorded its application state. On life1, in a root shell, downgrade the binary to 1.0:
# dpkg -i /srv/handbook-repo/handbook-agent_1.0.deb
(Reading database ... 68090 files and directories currently installed.)
Preparing to unpack .../handbook-agent_1.0.deb ...
Unpacking handbook-agent (1.0) over (2.0) ...
Setting up handbook-agent (1.0) ...
Selected output; the standard error also carried dpkg's warning:
dpkg: warning: downgrading handbook-agent (2.0) to (1.0)
The binary now reports the old version:
# handbook-agent
handbook-agent 1.0
The application state did not roll back with the package:
# cat /var/lib/handbook-agent/state
schema=2
installed_release=2.0
The package files are 1.0, but the state directory still records schema 2 and the 2.0 release. The 1.0 post-installation script also writes state only when none exists, so the newer state survives the downgrade by design. A real application can be in a worse position: a database schema may have been migrated, a configuration file may have been rewritten in a new format, or a queue may contain messages that the old binary cannot parse. A downgrade can therefore produce a binary that starts but cannot read its own data.
| Recovery method | What it restores | What it does not restore | When it is appropriate |
|---|---|---|---|
| Downgrade one package | The files of that package, if an older archive exists | Dependencies, configuration migrations, application data, service state | A single package regression with a compatible data format and a tested older version |
| Restore configuration files | Local configuration from a backup or a .dpkg-old file |
Package binaries, libraries, application data | A configuration change caused the failure and the package version is otherwise correct |
| Restore the whole system | Root filesystem, packages, configuration, and data from a snapshot or backup | Changes made after the backup; data on other hosts | A failed release upgrade with a verified system-level backup and an acceptable RPO |
| Rebuild or replace | A clean system with declared configuration and restored data | Undeclared local state; time spent rebuilding | The workload is reproducible, the old host can keep serving, or the old system is no longer trustworthy |
A package downgrade is reasonable when the failing package is isolated, the older version is still in a configured archive, the dependency set is unchanged, and the application's data format is compatible. It is not a release rollback. For a release rollback, use a virtual machine snapshot, a filesystem snapshot, a full system backup, or the still-running old host. Test the rollback path before the upgrade; a snapshot that has never been reverted is a hope, not a recovery plan.
APT may refuse a downgrade unless the version is explicitly requested or the pin
priority allows it. --allow-downgrades relaxes that check for a reviewed
operation, but it does not make the operation safe. Read the package's changelog
and the application's schema notes before using it.
29.5.4. Restoring the Previous System or Rebuilding a Replacement
The recovery record should name the host, the service, the configuration paths, the data paths, the backup location, the restore check, and the management access path. The practice record is a short Markdown file kept on the control host, where it survives the failure of the host it describes:
# Lifecycle service recovery record
Host: life2.lifecycle.lab
Service: nginx on TCP 8080 and 8443
Configuration: /etc/nginx/sites-available/lifecycle.conf
Data: /srv/lifecycle/data
Backups: /home/john/debian-handbook/lifecycle/backups
Restore check: sha256sum -c latest.sha256, then extract into a staging directory
Management access: SSH as john through the management network
Last reviewed: 2026-11-24
The fields that matter are the ones a tired administrator needs at 03:00: where the data is, how to verify it, and how to reach the host. Review the record at every point release and after every change to the backup path or the management network. A record that names a decommissioned host or an expired certificate is worse than no record because it produces confident wrong actions.
Restore into a staging directory first, exactly as Section 29.2.5 does. Compare the restored data checksum with the source, run the application's consistency check, and only then replace the live path. For a whole-system restore, boot the rescue environment or attach the backup volume, restore the root filesystem, reinstall the boot loader if needed, and boot with the network disconnected until the service configuration has been reviewed. A restore that immediately exposes an old vulnerable service to the network is not a recovery. Chapter 15 and Chapter 16 cover the whole-system procedures.
When the old system cannot be restored within the RTO, rebuild. A replacement host built from versioned configuration and restored data is often faster than repairing a corrupted package database or an unknown local modification. The practical lab in Section 29.7 follows that path: life2 is built by Ansible, the backup is restored into it, the service is verified, and life1 is retired only after the replacement passes its checks. The decision to rebuild is a business decision about time and risk, not a judgment about the administrator's skill.