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

Debian-based systems

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 /var/run/reboot-required.pkgs.

However, the UbuntuNotifier is not very specific and also refers to /var/run/reboot-required and not /var/run/reboot-required.pkgs.

What creates the file /var/run/reboot-required

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-required which is called in the .postinst script 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 touch /var/run/reboot-required

 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 /var/run/reboot-required.

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).

RedHat-based systems

Apparently RedHat-based systems do not have the same mechanism. Looking at this post

LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1)
CURRENT_KERNEL=$(uname -r)

  touch /var/run/reboot-required

This post gives an alternative: use needs-restarting form the yum-utils package. The man page needs-restarting explains what the tool does:

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:

What is it good for?

This is obviously very helpful for your orchestration tool or your scripts to check whether a reboot is required.