Change default kernel on Boot - CentOS

Recently a friend of mine had his server compromised. This was because no updates were done on his server for the past 2 years. When he did, among other things he needed to update his default kernel so that when the server was rebooted it knew which kernel to load.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
June 9, 2020
Accepted Answer

Before we begin, I would like to mention that the tutorial is intended for CentOS 6,7,8/RHEL/OEL 7 machines only and it won’t work on Ubuntu.

Imagine the following scenario. You haven’t updated your server in a looong long time and you now wish to update every package on it. This is what we’ll follow on this tutorial with the inclusion of changing the default kernel as well.

Now, firstly, we need to SSH to our server:

ssh root@XXX.XXX.XXX.XXX

where XXX.XXX.XXX.XXX is your actual server’s IP address.

Once in, we need to start updating the services. This can be easily achievable with the command yum ;

yum update

This will find all packages on your server and update everyone that needs updating, including the kernel. It might take some time but you’ll have the most recent package based on your repositories afterwards.

Having said that, this doesn’t mean your server has actually updated it’s default kernel. This in most cases needs to be done manually by yourself.

The information for the kernels is located in your grub config /boot/grub2/grub.cfg which is set as a symlink to /etc/grub2.cfg. To actually check the installed versions run the following command

awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg

It will show something in the mists of

Linux NameOfServer 4.18.0-117.3.1.el8_1.x86_64
Linux NameOfServer 4.18.0-147.3.1.el8_1.x86_64
Linux NameOfServer 4.18.0-147.8.1.el8_1.x86_64

Now, if we take a closer look, we’ll see all of the mentioned lines are almost similar however the last one is the latest. We’ll want to set that as our default kernel. To do, we run the command

grub2-set-default 2

Yes, it’s the line number 3 but denoted as entry 2.

Now that you’ve executed the command, you should be good to go on rebooting the server. Once it boots it should be with the latest kernel installed on your machine.

Regards, KDSys

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel