Sub topic 5
Seeing what is pending before you change anything
This chapter assumes you can use a Linux shell and sudo, know what a package and a repository are, and have SSH access to a Debian/Ubuntu or RHEL-family test machine. It also assumes you have already refreshed repository metadata, which the previous chapter covered. Everything here is read-only. None of the commands change installed packages.
Why review first
Patching is easier to defend when you know what will change before it does. A review step answers four questions:
- Which packages will change, and by how many versions?
- Does the list include a kernel,
glibc,openssl, or a service you run? - Are any of the updates security fixes?
- Will anything block the run, such as a held package or a changed dependency?
The review costs a minute. Without it, you find out about a database server upgrade from the service log afterward.
Reviewing on Debian and Ubuntu
After apt update, list what can be upgraded:
sudo apt update
apt list --upgradableThe output has one line per package, for example:
openssl/jammy-updates,jammy-security 3.0.2-0ubuntu1.15 amd64 [upgradable from: 3.0.2-0ubuntu1.12]Read the line from left to right:
| Part | Meaning |
|---|---|
| `openssl` | Package name |
| `jammy-updates,jammy-security` | Repository pockets that carry this version |
| `3.0.2-0ubuntu1.15` | Candidate version, the one apt would install |
| `[upgradable from: ...]` | Version installed now |
The pocket names matter. On Ubuntu, a package listed in a -security pocket is a security fix. A package that appears only in -updates is a regular bug fix. Debian uses a separate security archive, usually named bookworm-security or similar, and the same reading applies.
apt list prints a warning that its command-line interface is unstable. That is expected. Use it for reading by eye. In scripts, prefer a stable interface such as apt-get -s upgrade (see the next section).
Simulating the upgrade
The list shows candidates, but not what the actual run would do. A simulation shows that, including new dependencies and removals:
apt-get -s upgrade
apt-get -s dist-upgradeThe -s flag (simulate) prints lines starting with Inst, Remv, and Conf without touching the system. Run both forms and compare. upgrade never removes a package or installs a new one. dist-upgrade (the same operation as apt full-upgrade) may do both. If the two simulations differ, some updates need new packages or removals, and you should read them carefully before applying.
A common reason for a difference is a new kernel. Kernel packages carry the version in the package name, so a new kernel arrives as a new package. upgrade leaves it "kept back," and full-upgrade installs it.
Kept-back packages
When apt upgrade finishes with a line such as The following packages have been kept back, those packages need something upgrade is not allowed to do. Common causes:
- The new version needs a package that is not installed yet.
- The new version conflicts with or replaces an installed package.
- The package is on hold (see the later chapter on holds).
- A phased rollout has not reached your machine yet. Ubuntu releases some updates to a percentage of machines at a time, so a package can be visible in the list and still be kept back for a few days.
To see why one package is held back, ask apt directly:
apt-get -s install openssl
apt-cache policy opensslapt-cache policy prints the installed version, the candidate version, and which repositories offer each, with their priorities.
Reading the changelog
To see what a package update fixes before you accept it, read its changelog:
apt changelog opensslThis downloads the changelog from the repository, so it needs network access. Ubuntu changelogs usually name the CVE identifiers (public vulnerability numbers, such as CVE-2024-0727) that an update fixes. This is the quickest way to judge urgency.
Reviewing on RHEL-family systems
On RHEL, Rocky Linux, AlmaLinux, and Fedora, dnf check-update lists available updates and encodes the result in its exit code:
dnf check-update
echo "exit code: $?"| Exit code | Meaning |
|---|---|
| 0 | No updates are available |
| 100 | Updates are available |
| 1 | An error occurred |
Exit code 100 is not a failure. This trips up scripts that run with set -e or that treat any non-zero code as an error. A monitoring check should test for 100 specifically:
dnf check-update --quiet
status=$?
if [ "$status" -eq 100 ]; then
echo "updates pending"
elif [ "$status" -eq 0 ]; then
echo "up to date"
else
echo "dnf check-update failed with status $status" >&2
exit 1
fiThe listing shows package name and architecture, the new version-release, and the repository it comes from. It does not show the installed version. To compare, query with rpm:
rpm -q openssl-libsUsing advisories
RHEL-family repositories publish advisories, which are records that group package updates under an identifier and a type. The types are security, bugfix, enhancement, and newpackage. Security advisories carry a severity: Low, Moderate, Important, or Critical. List the advisories that apply to this machine:
dnf updateinfo list --security
dnf updateinfo list --availableThe first command shows only security advisories. Each line gives an advisory ID (for example RHSA-2024:1234), its severity, and the package it affects. The second shows every available advisory of any type.
For the full text of one advisory, including the CVEs it covers:
dnf updateinfo info RHSA-2024:1234Advisories do not exist in every repository. Third-party repositories often ship packages with no advisory metadata. A package from such a repository appears in dnf check-update but never in updateinfo. If you rely on --security alone, you will miss those updates. Compare the two outputs now and then.
Comparing the two tools
| Question | Debian/Ubuntu | RHEL-family |
|---|---|---|
| Refresh metadata | `sudo apt update` | Automatic, or `dnf makecache` |
| List pending updates | `apt list --upgradable` | `dnf check-update` |
| Simulate a run | `apt-get -s upgrade` | `sudo dnf upgrade` then answer `n` at the prompt |
| Identify security updates | Pocket name (`-security`) | `dnf updateinfo list --security` |
| Read change details | `apt changelog PKG` | `dnf updateinfo info ID` |
| Why was a package held back | `apt-cache policy PKG` | `dnf repoquery`, `dnf versionlock list` |
On dnf, the confirmation prompt is the simulation. dnf upgrade resolves dependencies, prints the full transaction (upgrades, installs, removals, total download size), and waits for y/N. Answer n to leave the system unchanged. Add --assumeno to make that the default in a script.
sudo dnf upgrade --assumenoSpotting items that need extra care
While reading the list, flag these:
- Kernel packages (
linux-image-*,kernel,kernel-core). They need a reboot to take effect. Plan a maintenance window. - Core libraries such as
glibc,openssl, andsystemd. Services using the old copy keep running it until restarted. - Database and application servers (
postgresql,mariadb,nginx). A package upgrade usually restarts the service, which can mean a short outage or a schema migration. - Packages that you pinned or held. They should not appear. If one does, a hold or lock is missing.
- Large lists after a long gap. Many versions behind means more risk. Consider applying in smaller steps on a test machine first.
A short script can save the review output as a record of what you saw before changing anything:
#!/usr/bin/env bash
set -u
out="/var/tmp/pending-$(hostname)-$(date +%F).txt"
if command -v apt-get >/dev/null 2>&1; then
apt-get -s upgrade > "$out"
elif command -v dnf >/dev/null 2>&1; then
dnf check-update --quiet > "$out"
fi
echo "Saved pending-update list to $out"Under set -u the script does not stop on dnf's exit code 100, because set -e is not used. The > redirect captures the list either way.
The review flow
Exercise
A monitoring script on a RHEL server runs dnf check-update and raises an alert whenever the exit code is not 0. It alerts every day, yet the server is healthy. What is the cause, and how should the script be changed?
Show answer
dnf check-update exits with 100 when updates are available. That is a normal result, not an error, so a check that treats every non-zero code as a failure alerts whenever anything is pending. Change the script to treat 0 as up to date, 100 as updates pending, and anything else (such as 1) as a real failure, as in the case statement shown earlier in the chapter.
Exercise
On Ubuntu, apt list --upgradable shows a package, but sudo apt upgrade reports it as kept back. Name two possible causes and one command that helps you investigate.
Show answer
Two causes are that the new version needs a package that is not installed (or removes one), which upgrade is not allowed to do, and that the package is on hold with apt-mark hold. A phased rollout that has not reached the machine is a third. Investigate with apt-cache policy PACKAGE, apt-mark showhold, or apt-get -s install PACKAGE, which shows what the install would require.