Centos – Determine if reboot is required to update kernel

centoslinux-kernelrebootupgrade

I am running a server which runs on CentOS with cPanel (latest version) and I have it set to automatically update using yum. Since it needs to be rebooted in order to update the kernel (and possibly other things), I was wondering if there's any way to figure out if a reboot is required?

EDIT: The server is a VPS and it's running on OpenVZ. Because of the way OpenVZ works, there's no /boot/vmlinuz and yum list installed kernel doesn't work either.

Best Answer

You can try the following bash script from this answer from ServerFault.

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

test $LAST_KERNEL = $CURRENT_KERNEL || echo REBOOT
Related Question