I love awesome scenarios wherein one needs to roll-back the kernel
Who doesn’t love the kernel!
But there are um, cases when you need to revert an awesome update or perhaps the update didn’t go well!
Ideally since the kernel is loaded into memory, you should be able to delete the installed version(package) from the FS and still be okay.
Ideally, everyone should also be getting free cake.
We have our old friend GRUB
There are multiple ways to achieve this, many of which may be more ‘effecient’. This article is meant to show-case only one of the ways to do it, which I find easy to do.
RHEL 6 / Centos 6
We’re gonna leverage grubby
-
See the default kernel -
grubby --default-kernel
example -/boot/vmlinuz-2.6.32-696.18.7.el6.x86_64
-
Verify what is the kernel version in use -
uname -r
example -2.6.32-696.el6.x86_64
-
See the default kernel to the path of the kernel you want to boot to -
ls -l /boot/vmlinuz*
-
Verify that the kernel to which you want to revert to exists example -
ls -l /boot/vmlinuz-2.6.32-504.el6.x86_64
-
Set the path as the new default -
grubby --set-default=/boot/vmlinuz-2.6.32-504.el6.x86_64
-
Verify that the kernel set is different from the one in use
grubby --default-kernel ; uname -r
-
reboot
-
Once the machine comes back on, verify that the kernel loaded to the path you specified by again checking
grubby --default-kernel ; uname -r
-
Delete the version which you reverted from i.e the problamatic version
yum remove kernel
but be careful you want to only remove the version you don’t need and by default yum should only remove it, but keep your eyes open. -
reboot
again and again verify that the problamatic version is gone and the correct version is in use and checkgrubby --default-kernel ; uname -r
again -
You’re golden! But have a look at
/boot/grub/grub.conf
and/etc/grub.conf
RHEL 7 / Centos 7
We’re gonna leverage grub 2 because that’s the new standard in modern contemporary operating systems.
See also GRUB 2 Shotgun
-
See all available versions
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
Alternativelyrpm -qa | grep -i kernel
-
See current version to which you boot to
grub2-editenv list
There will be numbers associated with the different kernerl versions, you’ll want to leverage those out. -
Change the default kernel
grub2-set-default NUM
likegrub2-set-default 4
-
Verify you set the correct number
grub2-editenv list ; uname -r
-
reboot
-
Once the machine comes back on, verify that the kernel loaded to the path you specified by again checking
grub2-editenv list ; uname -r
-
Delete the version which you reverted from i.e the problamatic version
yum remove kernel
but be careful you want to only remove the version you don’t need and by default yum should only remove it, but keep your eyes open. -
reboot
again and again verify that the problamatic version is gone and the correct version is in use and checkgrub2-editenv list ; uname -r
Alsoawk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
should return that only your intended version is available based on the kernel versions you removed -
See also
/etc/grub*
files