Removing the latest Kernel in CentOS

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:

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):

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:

To get a list of the exact package names, try yum list kernel, then copy/paste from there, and preface with “kernel-“

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:

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!

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!