APT upgrade preflight: sources, held packages and configuration

APT upgrade preflight: sources, held packages and configuration

APT upgrade preflight: sources, held packages and configuration

When self-hosted services are consolidated on a single dedicated server, one package upgrade can affect command-line tools, shared libraries and background processes at the same time. A successful installation message only confirms that the package manager has finished its work; it does not establish application compatibility. A reliable upgrade should leave three kinds of evidence: the dependency plan before installation, decisions about configuration files, and functional checks after installation.

This article uses Debian 13 to demonstrate preflight checks for a narrowly scoped APT upgrade. It does not cover upgrades between distribution releases. In the commands, curl is an actual package name used to illustrate the workflow; for a production change, replace it with the target package that has been reviewed and approved. After paying for a NodeAMD dedicated server, retrieve the credentials from the console and connect over SSH to run the checks. Account privileges depend on the access actually provided.

1. Check package sources and the package database

Identify the running system first, then inspect its package sources. Do not infer the distribution from the shell prompt or copy source configuration files directly from an old machine.

cat /etc/os-release
sudo grep -RnsE '^[[:space:]]*(deb |deb-src |Types:|URIs:|Suites:|Components:|Signed-By:)' \
  /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
sudo dpkg --audit
sudo apt-get check
sudo apt-get update
apt-cache policy curl

Debian supports both traditional .list files and deb822-format .sources files; check both. Pay attention to release codenames, components, signing configuration, and any duplicate entries or entries for a different distribution release. The installed version, candidate version and sources shown by apt-cache policy should match the intended change.

update refreshes package indexes; it does not install upgrades. Resolve source issues first if downloads fail, signature checks report problems, or some indexes fall back to cached copies. A few normal-looking lines at the end are not a reason to proceed. Any output from dpkg --audit also needs attention first, especially unconfigured packages left behind by an interrupted installation.

2. Save a baseline, then simulate the dependency plan

The baseline directory is readable only by the administrator. These inventories are for comparison; they are not a restorable system image.

sudo install -d -m 0700 /root/apt-preflight
sudo sh -c 'dpkg-query -W \
  -f="${binary:Package}\t${Version}\t${db:Status-Abbrev}\n" \
  > /root/apt-preflight/packages.before'
sudo sh -c 'apt-mark showhold > /root/apt-preflight/holds.before'
sudo sh -c 'apt-mark showmanual > /root/apt-preflight/manual.before'
sudo sh -c 'apt-get -s install --only-upgrade curl \
  > /root/apt-preflight/plan.txt 2>&1'
sudo cat /root/apt-preflight/plan.txt

Redirection is handled by a privileged shell here. Simply prefixing a command with sudo does not give the current shell permission to write to a protected directory. Check the exit status of every command; the existence of an output file is not proof that the command succeeded.

Review the plan item by item, checking packages to be added, upgraded, removed or kept back. Upgrading a single tool can still trigger changes to shared libraries. If the plan removes a dependency required by an application, stop and investigate rather than simply adding an automatic confirmation option.

A package being kept back is not necessarily a fault

apt-mark showhold lists only explicit holds. A package may also remain unchanged because of dependencies, priorities or its candidate version. Run sudo apt-get -s upgrade and sudo apt-get -s dist-upgrade separately to compare their plans. The latter allows the dependency solver to add or remove packages; it is not “more thorough and therefore safer.” Record why packages are being kept back, and do not leave those decisions unreviewed indefinitely.

3. Distinguish configuration evidence from full recovery

Debian's conffile mechanism tracks some configuration files, but it does not manage every application's configuration. First, inspect the files registered by the target package:

dpkg-query -W -f='${Conffiles}\n' curl
sudo tar -C / -czf /root/apt-preflight/etc.before.tar.gz etc
sudo chmod 0600 /root/apt-preflight/etc.before.tar.gz

The query for curl may return nothing. That does not mean there is no configuration on the server worth protecting. If the actual target is a background service, separately inventory its runtime configuration, included files, certificate references and application data. Pause configuration editing while creating the archive, and check the exit status of tar. This archive cannot be relied on to provide a consistent copy of data that is being actively written.

Configuration backups may contain passwords and private keys. Do not attach them directly to public issue reports. If they must be transferred off the server, use access-controlled encrypted storage and verify that the archive can be read.

Configuration evidence answers “What was there before the change?” A recovery plan answers “How do we get back to a working state?” Neither can replace the other.

When a configuration file conflict occurs, compare the differences first. Keeping the local configuration may omit settings required by the new version, while accepting the maintainer's version may overwrite application-specific customizations. Do not globally force either choice; after merging, use the application's own configuration validation facility. Database schema migrations also require a separate data recovery plan: downgrading a package does not reverse a migration.

4. Install and verify process state

Run the simulation again immediately before installation. If package sources, hold settings or package indexes have changed in the meantime, the old plan cannot simply be reused. After confirming that no other package management tasks are running, execute:

sudo apt-get -s install --only-upgrade curl
sudo apt-get install --only-upgrade curl
sudo dpkg --audit
sudo apt-get check
dpkg-query -W -f='${binary:Package}\t${Version}\t${Status}\n' curl
curl --version
systemctl --failed --no-pager

Do not delete APT or dpkg lock files to bypass an installation already in progress. If there is a lock conflict, first identify the process holding the lock and how it was started.

Verification has two layers. At the package level, check the version, fully installed status and dependencies. At the application level, test actual usage paths, such as script invocations, expected arguments and output parsing. curl --version only confirms that the tool starts; it is no substitute for testing an actual request.

After a shared library update, running processes may continue using the old library mappings. An empty systemctl --failed result does not prove that processes have loaded the new version. Decide whether services need restarting based on package messages and process checks. For a kernel update, separately verify the running kernel version rather than relying on what is installed on disk.

5. Finish with explicit stop conditions

The change record should retain, at a minimum, the target version, source, simulated plan, configuration decisions, installation result and application test results. Do not mark the change as complete if any of the following apply:

  • The actual installation scope differs from the approved plan.
  • The package database still has inconsistencies, or a service has entered a failed state.
  • Configuration syntax checks pass, but actual application workflows behave differently.
  • Processes requiring a restart have not been handled, and verification still relies on old processes.
  • Old packages, dependencies or data backups required by the recovery procedure cannot be obtained.

When troubleshooting, first preserve the installation output and relevant entries from /var/log/apt/history.log and /var/log/dpkg.log, then decide whether to repair or recover. Do not immediately follow up with bulk cleanup commands that introduce further changes to the system. An upgrade is complete when package state, configuration state and application behavior are all consistent—not merely when the last installation command reports success.

Frequently asked questions

Does a successful APT simulation guarantee a successful upgrade?

No. Simulation primarily resolves dependencies; it does not run package maintainer scripts or validate disk writes, service restarts or application compatibility. Repeat it immediately before installation and verify behavior afterward.

Are a package version list and an /etc backup enough for rollback?

No. The list does not contain old package files, and configuration backups do not preserve pre-migration application data. Recovery also requires available old packages, compatible dependencies and tested application data backups.

NodeAMD EPYC 7543P dedicated server, from $439/month

Configure a dedicated server with NodeAMD View NodeAMD rental pricing

From reading to server planning

Compare configurations, options, and billing to choose the right host for self-managed services.