Check if Reboot Is Required for Linux Kernel Update

»»»Check if Reboot Is Required for Linux Kernel Update
After updating kernel of Linux, a system reboot is normally required in order to complete the update and make the new kernel effective. In fact, kernel update may be the only reason to reboot a Linux system.

If you’re using cron job or control panel (such as cPanel) to automatically perform the update in Red Hat Enterprise Linux (RHEL) and CentOS or related distros using yum rpm based package manager, the kernel may be upgraded, but system is not yet restarted for new kernel to be used.

Use the following steps to determine if the system requires a reboot for kernel update:

  1. Check the latest version of kernel installed on the system with the one of the following commands:
    rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -n1
    ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1
  2. Check the version of kernel currently in use with the following command:
    uname -r
  3. If the results of two commands are different, it means that newer version of kernel is available and installed, pending reboot.
Note
You can also try to use the following script to automativally check and determine if a reboot is required for a Linux system for kernel update:

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

test $LAST_KERNEL = $CURRENT_KERNEL || echo REBOOT

A “REBOOT” text will be display is a system restart is required.

Note that the script may not be accurate if a custom kernel is installed, or error on the names of rpm, and other reasons.

By |2016-12-09T08:38:24+00:00December 9th, 2016|Categories: Linux|Tags: , , , |0 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.