6

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.

  • OpenVZ slices do not have their own kernel and so there is no point in trying to update it. The whole machine just runs one kernel belonging to the host system. – goldilocks Jan 3 '15 at 18:59
9

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
  • as an answer - good, but as a solution - no, this will return REBOOT in case of a custom kernel installed/compiled, kernel is not installed, and other rpm names errors. – ADM Jul 13 '14 at 10:02
  • If a package is upgraded which required an upgrade in initrd, a reboot is required but it is the same kernel version. – hschou Feb 16 '17 at 22:02
2

First of all, we print out running kernel version:

# uname -r 
2.6.32-71.29.1.el6.i686

Ok, we have to patch:

# yum update kernel*

Grab the kexec tools:

# yum install kexec-tools

Now we get last installed kernel version release and put it on a var:

# latestkernel=`ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1` 

# echo $latestkernel 
2.6.32-220.4.1.el6.i686

Now we need to load the new kernel version in memory:

# kexec -l /boot/vmlinuz-${latestkernel} --initrd=/boot/initramfs-${latestkernel}.img --append="`cat /proc/cmdline`"

Finally, we can issue a reset:

# kexec -e

..and.. wow, we lost the system! ..Well, not exactly.

The system will “restart without restarting”..something like a fast reboot, without performing BIOS checks (and you know how long can a full system restart last).

# uname -r
2.6.32-220.4.1.el6.i686

It worked!

  • Be aware that kernel reset will perform a connection reset as well, together with resetting your uptime, so if you’re searching for something to grant your uptime record while security patching, well, this is not for you.
  • I should've noted that it is a OpenVZ VPS and therefore /boot/vmlinuz doesn't exist. Is there anyway to get around that? – ub3rst4r Jun 19 '13 at 16:20
  • This question can be better answered in Ask Ubuntu. – Ashish Jun 20 '13 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.