When to reboot after Linux updates: needrestart, kernel updates and live patching
Installing an update replaces files on disk. Programs that are already running keep the old code in memory until they restart, and the kernel keeps running the old version until the next boot. A server that installs security updates every night but never restarts anything still runs the vulnerable code. A few commands show what still runs old code, and a planned reboot takes care of the rest.
What needs what
| Updated package | Fixed after |
|---|---|
| A program (nginx, postgresql, sshd) | Restart of that service. Package scripts usually do it. |
| A shared library (OpenSSL, zlib, libcurl) | Restart of every process that loaded the old library. |
| The kernel | Reboot (or a live patch for selected fixes). |
| CPU microcode | Reboot. |
| systemd, dbus, glibc | Reboot is the simple way; restarting them in place is possible but fiddly. |
Debian and Ubuntu
Is a reboot needed?
ls /var/run/reboot-required && cat /var/run/reboot-required.pkgs
The file exists when a package asked for a reboot, and reboot-required.pkgs names the packages. On Ubuntu, the
package update-notifier-common creates it. On Debian, the unattended-upgrades package installs a kernel hook
(/etc/kernel/postinst.d/unattended-upgrades) that creates it after a kernel update; without that package,
compare the running and the installed kernels:
uname -r
ls /boot/vmlinuz-*
If the newest vmlinuz is newer than the running kernel, a reboot is due.
Which services run old code?
needrestart checks every process for deleted or replaced libraries and lists the services to restart:
sudo apt install needrestart
sudo needrestart -r l
-r l only lists, -r i asks for each service, -r a restarts them without asking. -k checks only the
kernel, -w only the CPU microcode.
needrestart also runs after each apt upgrade (through /etc/apt/apt.conf.d/99needrestart). On Ubuntu 24.04
it restarts the affected services on its own after unattended-upgrades. To only list them, or to keep a
service out, add a file in /etc/needrestart/conf.d/:
# /etc/needrestart/conf.d/50-local.conf
$nrconf{restart} = 'l';
RHEL, Rocky Linux and AlmaLinux
sudo dnf needs-restarting -r
It prints whether a reboot is needed and exits with code 1 if so, 0 if not, which makes it easy to use in a script. The services that run old code:
sudo dnf needs-restarting -s
Restart them with sudo systemctl restart <service>.
Alpine
Alpine installs one kernel version at a time. After a kernel upgrade, the modules of the running kernel are
gone from /lib/modules, so loading a new module (for example when Docker needs a netfilter module) fails until
the reboot. Compare:
uname -r
ls /lib/modules
If the directory name differs from uname -r, reboot. For services that use updated libraries, restart them
with rc-service <service> restart.
Plan the reboots
- Pick a window. A weekly window covers most kernel updates. For a fix that is exploited in the wild, reboot the same day.
- Let the update tool reboot. unattended-upgrades reboots when
/var/run/reboot-requiredexists if you setUnattended-Upgrade::Automatic-Reboot "true";and a time withUnattended-Upgrade::Automatic-Reboot-Time "04:00";. dnf-automatic does the same withreboot = when-neededin/etc/dnf/automatic.conf. The guides on unattended-upgrades and dnf-automatic have the details. - Make sure everything comes back. Services must be enabled (
systemctl is-enabled <service>,rc-update showon Alpine) and containers need a restart policy such as--restart unless-stopped. Test one reboot by hand before you let a timer do it. - Several servers: reboot them one after another, and check that each is healthy before the next one goes down.
Live patching
Live patching changes the running kernel in memory, without a reboot.
- Ubuntu Livepatch is part of Ubuntu Pro (free for personal use on up to five machines). Turn it on with
sudo pro enable livepatch. It covers kernel vulnerabilities of high and critical priority. - RHEL provides live patches (kpatch) for Critical and Important CVEs. From RHEL 9.6 on, they cover selected kernels of each supported minor release, about one a quarter, for a year after that kernel was released.
Live patches cover a subset of the kernel fixes, and the running kernel still reports its old version. Canonical states that Livepatch is not a replacement for rebooting. Use it to stretch the time until the next planned reboot.
Check after the reboot
uname -r # the newest installed kernel
ls /var/run/reboot-required 2>/dev/null # Debian, Ubuntu: gone
sudo dnf needs-restarting -r # RHEL family: exit code 0
Patchbrief compares the running and the installed kernel on every server each day and lists the servers that wait for a reboot.
Sources
- needrestart README — what it checks (services, kernel, microcode, containers)
- dnf needs-restarting —
-rexit codes,-s - dnf-automatic —
reboot = when-needed - Ubuntu Server: automatic updates — needrestart restarts services after unattended-upgrades on Ubuntu 24.04,
$nrconf{restart} - Ubuntu Livepatch — scope,
pro enable livepatch, not a replacement for rebooting, free for five machines - Red Hat: kernel live patch support cadence update (2024-06-03) — Critical and Important CVEs, selected kernels about quarterly, one year, from RHEL 9.6
- RHEL 10: applying patches with kernel live patching — kpatch and the supported kernels
Check your servers every day
The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.