Reinstall the Linux Kernel on CentOS or RHEL

Mattias Geniar, Monday, July 23, 2012 - last modified: Thursday, December 18, 2014

One would expect that yum's reinstall command would do the trick, but alas -- it does not.

# yum reinstall kernel
Package kernel-2.6.18-194.32.1.el5.x86_64 is allowed multiple installs, skipping
Package kernel-2.6.18-274.12.1.el5.x86_64 is allowed multiple installs, skipping
Package kernel-2.6.18-194.el5.x86_64 is allowed multiple installs, skipping
Package kernel-2.6.18-308.1.1.el5.x86_64 is allowed multiple installs, skipping
Package kernel-2.6.18-308.11.1.el5.x86_64 is allowed multiple installs, skipping
Nothing to do

To reinstall the kernel, you actually have to remove it first and then install it again. You can remove your currently running kernel since it's operating completely from memory and does not rely on the physical files at the moment you're trying to reinstall it. So, first find out your current version.

# uname -r
2.6.18-308.11.1.el5

List the installed kernels

See what other kernels you may have installed.

# rpm -qa | grep kernel | sort
kernel-2.6.18-194.32.1.el5
kernel-2.6.18-194.el5
kernel-2.6.18-274.12.1.el5
kernel-2.6.18-308.1.1.el5
kernel-2.6.18-308.11.1.el5
kernel-headers-2.6.18-308.1.1.el5

Remove obsolete kernels

If you don't need the older kernels, you can safely remove them. You should keep at least one extra, just in case this reinstall fails (or if the new kernel is giving you problems).

# yum remove kernel-2.6.18-194.32.1.el5 kernel-2.6.18-194.el5

Reinstall the Linux Kernel via RPM/Yum

Now, to reinstall the kernel you want, first remove it by specifying the exact version (usually the currently running kernel, see uname -r above).

# yum remove kernel-2.6.18-308.11.1.el5
=====================================================================
 Package       Arch       Version               Repository    Size
=====================================================================
Removing:
 kernel        x86_64     2.6.18-308.11.1.el5   installed     98 M

Transaction Summary
=====================================================================
Remove        1 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: y

Confirm that the kernel is actually removed.

# rpm -qa | grep kernel | sort -n               
kernel-2.6.18-308.1.1.el5
kernel-headers-2.6.18-308.11.1.el5

It's not showing up (only the older kernel), so reinstall it.

# yum install kernel-2.6.18-308.11.1.el5
=======================================================================
 Package       Arch       Version              Repository      Size
=======================================================================
Installing:
 kernel        x86_64     2.6.18-308.11.1.el5  updates         21 M

Transaction Summary
=======================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 21 M
Is this ok [y/N]: y

Verify the new Linux Kernel is installed

And you should see the Kernel appear again.

# rpm -qa | grep kernel | sort -n                
kernel-2.6.18-308.11.1.el5
kernel-2.6.18-308.1.1.el5
kernel-headers-2.6.18-308.11.1.el5

After that, reboot the server again to make sure everything went as expected and you should have a cleanly reinstalled Linux Kernel available to you (for whatever reason this may have been necessary).



Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

Dr.Dedo Thursday, December 18, 2014 at 12:08 - Reply

thanks, happened just last night to me and one remote server didnt show up again due to an installation error of the kernel.


kerils Thursday, January 5, 2017 at 12:00 - Reply

Hi,
Thanks for the tutorial.
Is there any chance that my files or apps or setup would be affected by this manipulation?
I need to be sure that this manipulation only affects the kernel of my server but do not erase anything on it.
thanks in advance for your answer.


rory Thursday, April 6, 2017 at 18:38 - Reply

THANKS!!

Helped me out loads.


Afterbanks Thursday, April 27, 2017 at 12:43 - Reply

I had a problem when recompiling the kernel:
E: Failed to install /usr/lib/libfreeblpriv3.so

I found out that reinstalling which solves the problem:
yum reinstall which -y


Chris Thursday, July 27, 2017 at 17:00 - Reply

On CentOS 7 it won’t allow me to remove the running kernel:

$ sudo yum remove kernel-3.10.0-514.26.2.el7
Loaded plugins: fastestmirror, langpacks
Skipping the running kernel: kernel-3.10.0-514.26.2.el7.x86_64
No Packages marked for removal


Leave a Reply

Your email address will not be published. Required fields are marked *

Inbound links