How to check if your Arch Linux system needs a reboot

By default Arch will install the kernel in /boot with the name vmlinuz-linux. To determine if the system is running the latest kernel, we can compare the running kernel and the one on disk.

Running kernel

One way to determine the running kernel is with the uname command. By default installed and with the -r parameter it will provide the kernel release version.

# uname -r  
3.17.4-1-ARCH

Kernel on disk

Checking the latest kernel on disk is almost as easy. In this case we have to analyze the /boot/vmlinuz-linux file, which is the default file name for the Linux kernel on Arch Linux.

The file utility can discover the contents of the file and determine that is indeed the kernel.

# file /boot/vmlinuz-linux  
/boot/vmlinuz-linux: Linux kernel x86 boot executable bzImage, version **3.17.4-1-ARCH** (builduser@tobias) #1 SMP PREEMPT Fri Nov 21 21:1, RO-rootFS, swap_dev 0x3, Normal VGA

The interesting part in this case is the kernel version, which is behind the “version” keyword. In this case both the running kernel and kernel on disk are the same, so no reboot is needed.

Monitoring

If you want to automate the reboot check, we can parse the output of the uname and file commands. The small snippet below will help in performing the related check.

#!/bin/sh

set -o nounset

NEXTLINE=0
FIND=""
for I in `file /boot/vmlinuz*`; do
  if [ ${NEXTLINE} -eq 1 ]; then
    FIND="${I}"
    NEXTLINE=0
   else
    if [ "${I}" = "version" ]; then NEXTLINE=1; fi
  fi
done
if [ ! "${FIND}" = "" ]; then
  CURRENT_KERNEL=`uname -r`
  if [ ! "${CURRENT_KERNEL}" = "${FIND}" ]; then
    echo "Boot required"
  fi
fi

Use case

Testing if systems need a reboot is especially useful as part of your software patch management strategy. In our case we have embedded this test in our auditing tool Lynis, which determines for several Linux distributions if the system needs a reboot.

Updated (January 2015): changed script

Related commands

The following commands were used in this article:

  • uname

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution.

Mastodon icon