I’ve had a power cut recently, which seems to have corrupted the latest Kernel I have installed on my CentOS 6 server. I can boot into the previous one just fine, but of course if I forget to make a choice on startup, the server doesn’t start up. That’s annoying.
Thankfully there are ways to either fix the latest version, remove it, and even exclude a particular version from future updates. Here’s what worked for me on CentOS 6:
What Kernel are we using
To figure out which version is working for us, we can use the uname command. I guess when that menu with the last 10+ kernels showed up during boot, we may not have paid much attention to the little numbers at the end. uname will tell us:
uname -r 2.6.32-754.27.1.el6.i686
That’s good to know, as this is the version we’d like to retain. In my case it’s the previous Kernel that was installed. But how can we tell what the other versions are?
Listing all installed Kernels
yum can tell us that. I’m getting a total of 5 entries, each of which is corresponding to one I can select on boot (I’ll show you the last two):
yum info kernel Name : kernel Arch : i686 Version : 2.6.32 Release : 754.27.1.el6 Size : 97 M Repo : installed From repo : updates Summary : The Linux kernel URL : http://www.kernel.org/ License : GPLv2 Description : ... Name : kernel Arch : i686 Version : 2.6.32 Release : 754.28.1.el6 Size : 97 M Repo : installed Summary : The Linux kernel URL : http://www.kernel.org/ License : GPLv2
The one you’ve used on boot us printed in bold, in my case that’s release 754.27.1.el6. I’d like to keep that. But the one after that, namely 754.28.1.el6, I’d like to remove and potentially re-install.
Removing a Kernel
We can remove a Kernel version with yum, specifying the version number like so:
yum remove kernel-2.6.32-754.28.1.el6 ... Removed: kernel.i686 0:2.6.32-754.28.1.el6
To get a list of the exact package names, try yum list kernel, then copy/paste from there, and preface with “kernel-“
yum list kernel Installed Packages kernel.i686 2.6.32-754.23.1.el6 @updates kernel.i686 2.6.32-754.24.3.el6 @updates kernel.i686 2.6.32-754.25.1.el6 @updates kernel.i686 2.6.32-754.27.1.el6 @updates kernel.i686 2.6.32-754.28.1.el6 installed
When the process has finished, and with a bit of luck, I should be able to do a regular yum update, and the latest Kernel will be installed again – hopefully in working order. It did in fact work in my case ?
Excluding a Kernel from future updates
In the event that the Kernel has a bug and doesn’t play well with your hardware, even a fresh version might lead to startup panics. Well not to panic, we can exclude specific version numbers from the update process.
Instead of using yum update, you can use the –exclude-kernel option. This will update all packages except for any future kernels:
yum update --exclude-kernel
Another option is to add an exclude statement in /etc/yum.conf under the [main] section. You can either specify
to exclude any further Kernel updates, or you can specify the exact version so that only that particular one will be excluded, yet any Kernels after said version will be updated.
Many thanks to Jonathon Reinhart and Stuart Cardall for these tips!