How to know when your Linux system requires a reboot
Posted April 20, 2021 by Adrian Wyssmann ‐ 2 min read
When you manage Linux systems it's usually pretty clear how to reboot a system. But do you know how to check whether a system requires a reboot? Cause you don't want to reboot a system if it is not necessary
There are some posts out there which talks about this topic. Check for a required reboot on Debian and Ubuntu systems is an interesting one which speaks about a
However, the UbuntuNotifier is not very specific and also refers to
/var/run/reboot-required and not
What creates the file
I ask the same question but as mentioned I don’t find anything in the official documentation, but only on this Reddit post:
On Debian-like systems it’s created by
/usr/share/update-notifier/notify-reboot-requiredwhich is called in the
.postinstscript of some packages.
On my Debian Buster I don’t have
/usr/share/update-notifier/notify-reboot-required but I found at least one
.postints script which does also a
cat /var/lib/dpkg/info/dbus.postinst | grep reboot-re touch /var/run/reboot-required || true [ -x /usr/share/update-notifier/notify-reboot-required ] && \ /usr/share/update-notifier/notify-reboot-required || true
So looks like ultimately it’s the
.postinst files which are responsible creates the file
According to this post, the file
/var/run/reboot-required.pkgs lists the packages that requested the reboot. I could not verify that on my Debian Buster (yet).
Apparently RedHat-based systems do not have the same mechanism. Looking at this post
#!/bin/bash LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1) CURRENT_KERNEL=$(uname -r) if [[ ! $LAST_KERNEL = $CURRENT_KERNEL ]]; then touch /var/run/reboot-required fi
needs-restarting is a program that reports a list of process ids that started running before they or some component that they use were updated.
So I can run this to see if a reboot is required
$ needs-restarting -r Core libraries or services have been updated: kernel -> 3.10.0-1160.24.1.el7 Reboot is required to ensure that your system benefits from these updates. More information: https://access.redhat.com/solutions/27943
What is it good for?
This is obviously very helpful for your orchestration tool or your scripts to check whether a reboot is required.