6.4. Keeping the System Updated

An unmanaged system drifts out of date; a badly managed one changes at the wrong moment. This section covers the middle ground: the routine upgrade loop and its vocabulary, the automation that applies security fixes without an administrator in the chair, the configuration-file prompts and service restarts that upgrades trigger, and the reboot decision that closes every pass. Figure 6.3 shows the loop the subsections walk through.

The routine update cycle and its decision points

Figure 6.3. The update cycle: refresh, review, apply, then the restart and reboot questions. Holds and pins change what the plan contains; they do not change the loop.

6.4.1. Routine Upgrades and Dependency Changes

The pending-upgrade demonstrations need a locally upgradable package, so install the first version of the fixture explicitly - the name=version form requests one exact version rather than the candidate:

$ sudo apt-get install ch06-demo=1.0
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  ch06-demo
0 upgraded, 1 newly installed, 0 to remove and 28 not upgraded.
Need to get 0 B/904 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 file:/srv/ch06-repo trixie/main amd64 ch06-demo all 1.0 [904 B]
Selecting previously unselected package ch06-demo.
(Reading database ... 111156 files and directories currently installed.)
Preparing to unpack .../main/ch06-demo_1.0_all.deb ...
Unpacking ch06-demo (1.0) ...
Setting up ch06-demo (1.0) ...

Selected output; progress lines and needrestart report omitted. The archive's index from Section 6.2.3 lists both 1.0 and 2.0, and the =1.0 chooses the older deliberately - a downgrade relative to the candidate, which is why the version is stated rather than assumed.

With that installed, the machine has one fixture upgrade and one real security batch pending, and the routine loop picks both up. The plan for a whole-system change is best read before making it: apt-get -s upgrade simulates the upgrade of every upgradable package and prints the full transaction, needing no privileges:

$ apt-get -s upgrade
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages will be upgraded:
  ch06-demo fonts-opensymbol libreoffice-base-core libreoffice-calc
  libreoffice-common libreoffice-core libreoffice-draw libreoffice-gtk3
  libreoffice-help-common libreoffice-help-en-us libreoffice-impress
  libreoffice-math libreoffice-style-colibre libreoffice-uiconfig-calc
  libreoffice-uiconfig-common libreoffice-uiconfig-draw
  libreoffice-uiconfig-impress libreoffice-uiconfig-math
  libreoffice-uiconfig-writer libreoffice-writer libuno-cppu3t64
  libuno-cppuhelpergcc3-3t64 libuno-purpenvhelpergcc3-3t64 libuno-sal3t64
  libuno-salhelpergcc3-3t64 libvisio-0.1-1 python3-uno uno-libs-private ure
29 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
[...]
Inst ch06-demo [1.0] (2.0 Debian Handbook Lab:trixie [all])
[...]
Conf ch06-demo (2.0 Debian Handbook Lab:trixie [all])

Selected output; the middle of the plan - the Inst and Conf lines for the twenty-eight pending security updates - is omitted. The bracketed [1.0] in the ch06-demo line is the installed version the upgrade replaces; Debian Handbook Lab:trixie is the origin label recorded in the practice archive's Release file. The Inst and Conf verbs are the same two steps every real transaction prints as Unpacking and Setting up. On this machine the plan mixes one fixture upgrade with the genuine security batch; a production machine's plan would show its own reality, and reviewing it before every upgrade is the habit worth forming: it names every package that changes, installs, or leaves.

The interactive companion, apt list, shows the same upgradable set in short form:

$ apt list --upgradable
Listing...
ch06-demo/trixie 2.0 all [upgradable from: 1.0]
fonts-opensymbol/stable-security 4:102.12+LibO25.2.3-2+deb13u12 all [upgradable from: 4:102.12+LibO25.2.3-2+deb13u9]
libreoffice-base-core/stable-security 4:25.2.3-2+deb13u12 amd64 [upgradable from: 4:25.2.3-2+deb13u9]
[...]

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Selected output; twenty-six further stable-security lines are omitted. The warning goes to standard error and repeats the rule of Section 6.1.2: apt is for reading by people, apt-get for procedures and scripts.

The plan's shape decides the command. apt-get upgrade upgrades what it can without structural change: no new packages installed, nothing removed, so any upgrade that needs a new dependency is skipped and the package is reported kept back. apt-get full-upgrade accepts the structural change - new packages, and removals where conflicts require them. The everyday rule that follows: routine security updates almost always fit upgrade; run the simulation first, and when it reports kept back packages or removals, look at apt-get -s full-upgrade and understand why before running it. A release-to-release upgrade is a different, larger procedure with its own staging - Chapter 29 covers it, and its rules override the routine habits built here.

Two vocabulary notes complete the picture. The "N not upgraded" count on every transaction summary is exactly the kept-back set: packages with newer candidates that this transaction did not touch. And holds (Section 6.5.1) remove a package from upgrade planning entirely - the simulation in that section shows a held package staying put while everything around it moves.

The example machine's security batch is the ordinary kind of work the loop exists for: apt-get upgrade would apply it in one pass, and the fixture upgrade of Section 6.4.3 demonstrates the same mechanics on a single package where the interesting parts - a locally modified configuration file and dpkg's question about it - are visible.

6.4.2. Configuring unattended-upgrades and Maintenance Windows

Security updates matter most on the machines nobody watches daily, and Debian ships the automation for them: the unattended-upgrades package installs security fixes on its own schedule, logging every action. Two independent pieces control it. The first says whether the daily apt work should include an upgrade; the second says what may be upgraded automatically. Check the first as apt itself sees it:

$ apt-config dump APT::Periodic
APT::Periodic "";
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

apt-config dump prints apt's merged configuration for the named scope, from every file under /etc/apt/apt.conf.d/. The two values say: refresh the indexes daily (Update-Package-Lists "1"), and run an unattended upgrade daily (Unattended-Upgrade "1"). On this machine they come from one file:

$ cat /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

The number is a frequency in days - "0" would disable that step. On a system where these lines are absent, the supported way to add them is the package's own question: sudo dpkg-reconfigure -plow unattended-upgrades asks, debconf-style, whether automatic updates should run, and writes 20auto-upgrades from the answer; editing the file directly is equally valid.

The second piece - what may be upgraded - lives in the package's main configuration, and its default is deliberately narrow:

$ grep -E "^(Unattended-Upgrade::|APT::Periodic)" /etc/apt/apt.conf.d/50unattended-upgrades | head -20
Unattended-Upgrade::Origins-Pattern {
Unattended-Upgrade::Package-Blacklist {

The uncommented settings are two blocks: Origins-Pattern decides which repositories' updates qualify, and Package-Blacklist names packages never to touch automatically. The shipped pattern allows, in the release's terms, updates from the stable suite and the security archive - visible concretely in the tool's own dry run below - and nothing else: no backports, no third-party archive, and on this machine not the practice archive either. The file's extensive comments document each setting for local adjustment.

The schedule is systemd's. Two timers drive the daily work:

$ systemctl list-timers "apt*" --no-pager
NEXT                        LEFT LAST                        PASSED UNIT                    ACTIVATES
Thu 2026-11-19 06:56:28 UTC   9h Wed 2026-11-18 06:35:27 UTC      - apt-daily-upgrade.timer apt-daily-upgrade.service
Thu 2026-11-19 07:48:12 UTC  10h Wed 2026-11-18 10:18:39 UTC      - apt-daily.timer         apt-daily.service

2 timers listed.
Pass --all to see loaded but inactive timers, too.

apt-daily.timer runs the refresh and the download portion of the work; apt-daily-upgrade.timer runs the install. Both schedules are deliberately randomized around their nominal times so that a whole fleet of machines does not hit one mirror at once; Chapter 10 covers timer mechanics, and Chapter 8 the journal inspection used to read what ran. One more unit is regularly misread:

$ systemctl status unattended-upgrades --no-pager
● unattended-upgrades.service - Unattended Upgrades Shutdown
     Loaded: loaded (/usr/lib/systemd/system/unattended-upgrades.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-11-18 20:58:31 UTC; 39min ago
 Invocation: 975e70b5eff3439e9cabe60c548cbbcc
       Docs: man:unattended-upgrade(8)
   Main PID: 720 (unattended-upgr)
      Tasks: 2 (limit: 1088)
     Memory: 23.1M (peak: 28.4M)
        CPU: 1.114s
     CGroup: /system.slice/unattended-upgrades.service
             └─720 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal

Warning: some journal files were not opened due to insufficient permissions.

The persistently running service is not an upgrade in progress: it is unattended-upgrade-shutdown --wait-for-signal, the small helper that lets upgrades configured for shutdown time install while the machine stops. The real upgrade work happens under apt-daily-upgrade.service, and everything it does is logged under /var/log/unattended-upgrades/ and /var/log/apt/ (Section 6.7.3 reads those logs).

A maintenance window - "do this, but only at night" - is a third, separate decision, expressed in the same configuration directory. The example states that upgrades run automatically, that reboots never do, and that 02:00 is the reboot time for the day automatic reboots are enabled:

APT::Periodic::Unattended-Upgrade "1";
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

File contents, shown as a listing - saved as /etc/apt/apt.conf.d/51ch06-maintenance. The reboot lines matter only when Automatic-Reboot is true; with it false, the time is a planned value that nothing acts on, and the administrator answers the reboot-requirement check of Section 6.4.4 personally. Verify the merged result:

$ apt-config dump | grep -E "Automatic-Reboot|Periodic::Unattended-Upgrade"
APT::Periodic::Unattended-Upgrade "1";
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

The grep keeps the three settings the file added, and the dump confirms apt merged them with everything else. Remove the practice file again with sudo rm /etc/apt/apt.conf.d/51ch06-maintenance - silent, and the merged configuration returns to its previous state.

Finally, preview an automatic run. unattended-upgrade accepts a dry-run mode that resolves, plans, and reports without installing:

# unattended-upgrade --dry-run --debug
loading plugins from ['/etc/unattended-upgrades/plugins/', '/usr/share/unattended-upgrades/plugins']
Checking if system is running on battery is skipped. Please install powermgmt-base package to check power status and skip installing updates when the system is running on battery.
Starting unattended upgrades script
Allowed origins are: origin=Debian,codename=trixie,label=Debian, origin=Debian,codename=trixie,label=Debian-Security, origin=Debian,codename=trixie-security,label=Debian-Security
Initial blacklist:
Initial whitelist (not strict):
[...]
Checking: ch06-demo=2.0 ([<Origin component:'main' archive:'trixie' origin:'Debian Handbook Lab' label:'Debian Handbook Lab' site:'' isTrusted:True>])
adjusting candidate to version ch06-demo=1.0 in allowed origin [<Origin component:'main' archive:'trixie' origin:'Debian Handbook Lab' label:'Debian Handbook Lab' site:'' isTrusted:True>, <Origin component:'now' archive:'now' origin:'' label:'' site:'' isTrusted:False>]
[...]
pkgs that look like they should be upgraded: fonts-opensymbol
libreoffice-base-core
[...]
ure
Option --dry-run given, *not* performing real actions
Packages that will be upgraded: fonts-opensymbol libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gtk3 libreoffice-help-common libreoffice-help-en-us libreoffice-impress libreoffice-math libreoffice-style-colibre libreoffice-uiconfig-calc libreoffice-uiconfig-common libreoffice-uiconfig-draw libreoffice-uiconfig-impress libreoffice-uiconfig-math libreoffice-uiconfig-writer libreoffice-writer libuno-cppu3t64 libuno-cppuhelpergcc3-3t64 libuno-purpenvhelpergcc3-3t64 libuno-sal3t64 libuno-salhelpergcc3-3t64 libvisio-0.1-1 python3-uno uno-libs-private ure
[...]
upgrade result: True All upgrades installed

Selected output from a long debug report, run in the root shell; the pinning bookkeeping and per-archive fetch lines are omitted. The battery note is informational - the check is skipped when powermgmt-base is not installed.

Three lines carry the meaning. Allowed origins are: states the policy exactly: the stable suite and the security archive, by origin, codename, and label. The Checking: ch06-demo lines show the boundary working - the fixture's newer 2.0 comes from an origin not in the pattern, so its candidate is adjusted back to the installed 1.0 and it is not upgraded automatically, which is precisely the containment a third-party source deserves. And the final Packages that will be upgraded: list is the security batch - the same twenty-eight LibreOffice updates the manual simulation showed, now confirmed as eligible for automatic installation. The --dry-run line itself is the guarantee that nothing was installed by this preview.

The settings worth knowing, in one table:

Setting (in 50unattended-upgrades or a local file) Effect
Origins-Pattern { … } Which repositories' updates may install automatically.
Package-Blacklist { … } Packages never upgraded automatically, by name or regex.
Unattended-Upgrade::Automatic-Reboot Reboot automatically when an upgrade requires it.
Unattended-Upgrade::Automatic-Reboot-Time When that reboot happens.
APT::Periodic::Update-Package-Lists / Unattended-Upgrade Daily frequencies, in days, for refresh and upgrade.

Email notification settings exist in the same file for machines that should report their automatic work; delivering such mail is the subject of Chapter 8, not of this chapter's example system.

6.4.3. Handling Configuration File Prompts and Service Restarts

The upgrade of the fixture package puts the two consequential moments of every real upgrade on display: dpkg's question about a locally modified configuration file, and the service restarts an upgrade may perform. First make the situation realistic - the fixture's conffile /etc/ch06-demo.conf ships mode=stable in version 1.0; edit it, as an administrator legitimately would:

# printf "mode=local-change\n" > /etc/ch06-demo.conf
$ cat /etc/ch06-demo.conf
mode=local-change

The printf redirection writes the file and prints nothing; the cat confirms the content. The conffile is now locally modified, and version 2.0 ships a new one - mode=updated. Upgrade with the policy that says "my local file wins by default":

$ sudo apt-get -o Dpkg::Options::=--force-confold install ch06-demo
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be upgraded:
  ch06-demo
1 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
Need to get 0 B/904 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 file:/srv/ch06-repo trixie/main amd64 ch06-demo all 2.0 [904 B]
apt-listchanges: Reading changelogs...
(Reading database ... 111159 files and directories currently installed.)
Preparing to unpack .../main/ch06-demo_2.0_all.deb ...
Unpacking ch06-demo (2.0) over (1.0) ...
Setting up ch06-demo (2.0) ...

Configuration file '/etc/ch06-demo.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Using current old file as you requested.

Selected output; progress lines and the needrestart report omitted. The apt-listchanges line appears on this machine because the optional apt-listchanges package is installed; it prints changelog excerpts during upgrades. The -o Dpkg::Options::=--force-confold hands dpkg one per-transaction option - the same effect as putting the option in /etc/apt/apt.conf.d/, but only for this command.

The transaction upgraded one named package with no side effects, so again no confirmation prompt. The conffile report is the interesting part: dpkg detected the three-way difference - the file on disk differs from both what 1.0 installed and what 2.0 ships - and, told to keep the old file, printed its decision rather than asking. Both facts are worth verifying:

$ dpkg-query -W -f='${Status} ${Version}\n' ch06-demo
install ok installed 2.0
$ cat /etc/ch06-demo.conf
mode=local-change

Version 2.0 is installed; the local edit survived. The interactive form of the same decision deserves practice, and a downgrade back to 1.0 - which again ships mode=stable - produces the full question. Downgrades are never automatic (apt refuses them without --allow-downgrades, a guard against accidental rollbacks), so the command states both the version and the permission:

$ sudo apt-get -y -o Dpkg::Options::=--force-confask install --allow-downgrades ch06-demo=1.0
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be DOWNGRADED:
  ch06-demo
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 28 not upgraded.
Need to get 0 B/904 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 file:/srv/ch06-repo trixie/main amd64 ch06-demo all 1.0 [904 B]
dpkg: warning: downgrading ch06-demo (2.0) to (1.0)
(Reading database ... 111159 files and directories currently installed.)
Preparing to unpack .../main/ch06-demo_1.0_all.deb ...
Unpacking ch06-demo (1.0) over (2.0) ...
Setting up ch06-demo (1.0) ...

Configuration file '/etc/ch06-demo.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** ch06-demo.conf (Y/I/N/O/D/Z) [default=N] ?

Selected output; the -y answers the routine transaction confirmation so the conffile question is the only interactive step, and progress lines plus the needrestart report are omitted. The capture ends at the question itself: dpkg does not echo the answer back through the recording pipe, so the typed character does not appear - on a terminal it shows after the prompt, and the answer given here was N.

This is dpkg's real conffile prompt, unchanged in shape across Debian releases, and every answer is a policy:

Answer Action
Y or I Install the maintainer's version, replacing the local file.
N or O Keep the local version - the default.
D Show a diff of the two versions, then re-ask.
Z Open a shell to investigate; exit returns to the question.

The N answered here kept the local edit - the final state below proves it. A shipped conffile meeting a locally modified one is exactly the state in which dpkg asks by default, so no forcing option was needed to produce the question; --force-confask was stated to make the asking explicit, and its documented effect reaches further - it asks about a locally modified conffile even when the shipped version did not change, where dpkg otherwise keeps the local file silently. The option family:

Dpkg::Options::= value Behavior on shipped conffiles
--force-confold Keep the local version silently.
--force-confnew Install the maintainer's version silently.
--force-confask Ask about a locally modified conffile even when the shipped version did not change.
--force-confdef Take dpkg's default action without prompting - for a locally modified or deleted conffile whose shipped version also changed, that keeps the local state; only a conffile with no default action still asks.

For unattended runs the combination --force-confdef --force-confold is the usual policy: follow sane defaults, never block on a question. Whichever choice is taken, dpkg keeps the loser as *.dpkg-old or *.dpkg-new beside the conffile, so a Y decision can be compared afterwards and an N decision can still adopt the maintainer's file by hand. One caution completes the conffile story: the protection extends only to registered conffiles. A file a package owns but never declared - anything not listed by dpkg-query -W -f='${Conffiles}' - is overwritten on upgrade without question, which is why Section 6.1.3's rule about configuration living under /etc and being declared matters.

The other consequence of upgrades is restarts. A package that ships a daemon arranges its own service management: its maintainer scripts restart or reload the service as part of configuration - Chapter 8 covers what that means under systemd - and libraries used by running daemons leave those daemons executing old code until something restarts them. Debian's needrestart, installed on the example system, runs as a dpkg hook after every transaction and reports the situation - the first install capture of Section 6.3.2 showed it, and every later install capture carried the same assessment before trimming kept the transcripts short. On a machine where nothing runs long enough to matter, the report reads:

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

On a server holding long-running daemons, the same report names the services and sessions using outdated libraries, and the administrator restarts them deliberately - the hook reports; it does not act. The reboot half of the question is the next subsection's subject.

6.4.4. Identifying Reboot Requirements

Not every update requires a reboot, and blanket "reboot after updating" policies waste more time than they save. Three checks, in rising order of effort, answer the question for a machine. The first is needrestart's kernel report, in its batch form:

# needrestart -b
NEEDRESTART-VER: 3.11
NEEDRESTART-KCUR: 6.12.117+deb13-amd64
NEEDRESTART-KEXP: 6.12.117+deb13-amd64
NEEDRESTART-KSTA: 1

The -b batch output is designed for scripts and never prompts. It reports the running kernel (KCUR), the newest installed kernel (KEXP), and a status code whose meanings the package documents:

NEEDRESTART-KSTA Meaning
0 Unknown; detection failed.
1 No pending kernel upgrade.
2 ABI-compatible upgrade pending - same userspace interface.
3 Version upgrade pending - reboot to run the new kernel.

1 here: the running kernel is the newest installed. The second check is that same comparison done by hand, which is also how a machine without needrestart is checked - the kernel metapackage against the running version:

$ uname -r
6.12.117+deb13-amd64
$ dpkg-query -W -f='${Package} ${Version}\n' linux-image-amd64
linux-image-amd64 6.12.117-1
$ ls -1 /boot/vmlinuz-*
/boot/vmlinuz-6.12.117+deb13-amd64
/boot/vmlinuz-6.12.86+deb13-amd64

The running kernel 6.12.117+deb13-amd64 matches the installed metapackage's kernel, so nothing is pending; the older 6.12.86+deb13-amd64 in /boot is the previous kernel, kept deliberately as the fallback boot entry - Chapter 7 covers kernel metapackages and why the previous kernel must stay. The metapackage version 6.12.117-1 and the kernel string 6.12.117+deb13-amd64 are the same release in two naming schemes: the package version, and the version plus Debian suffix that the kernel itself reports.

The third check covers the packages that cannot be fixed by restarting services at all: kernel, kernel modules, the C library, systemd itself. Updates to those change code already loaded into every process, so only a reboot adopts them. Debian's convention for flagging this is a marker file pair, written by hooks when such a package installs - the reboot-notifier package's kernel hook is the standard implementation on Debian, writing its notice to /var/run/reboot-required (/var/run is a symlink to /run, so it is the same file) and the triggering package's name into reboot-required.pkgs. The example system does not install reboot-notifier, so to demonstrate the detection as its hook performs it, create the two files with the same content the hook writes, as root:

# printf "linux-image-amd64\n" > /run/reboot-required.pkgs
# printf "*** System restart required ***\n" > /run/reboot-required
# ls -l /run/reboot-required /run/reboot-required.pkgs
-rw-r--r-- 1 root root 32 Nov 18 21:37 /run/reboot-required
-rw-r--r-- 1 root root 18 Nov 18 21:37 /run/reboot-required.pkgs

The first two redirections write the files and print nothing; the listing shows both in place. The notice files live under /run, which is wiped at every boot - so the marker's presence means "a reboot is pending since the last one", exactly the question being asked. Read the trigger:

$ cat /run/reboot-required.pkgs
linux-image-amd64

Any monitoring or login-banner check reads these files the same way. Clean up the practice marker so the machine reports honestly again:

# rm -f /run/reboot-required /run/reboot-required.pkgs

The command prints nothing on success; the pending marker is gone, and on this system needrestart's KSTA 1 is the truthful answer.

The decision rule that ties the checks together: reboot when the kernel status says 2 or 3, when a reboot-required marker exists, or when updates touched the kernel, modules, systemd, or the C library; restart services per the needrestart report otherwise; and treat a reboot after a kernel update as a test of the fallback path, not just a chore - booting the new kernel while the previous one remains selectable is the state Chapter 7 relies on for recovery.