How to change default boot kernel permanently or temporarily on CentOS

Question: I have several kernel images installed on my CentOS box, and I want to change the default boot kernel either permanently or temporarily ("just once"). How can I change the default kernel version used by GRUB/GRUB2 on CentOS?

When there are multiple kernels installed on CentOS, GRUB/GRUB2 boot loader chooses and loads one of them as the default kernel during boot time. The default kernel can be chosen differently. For example, CentOS can be configured to boot into a newly installed kernel (e.g., CentOS 6), or it can boot a last saved entry regardless of the kernel is newer or older (e.g., CentOS 7).

If you want to change the default kernel to a particular kernel version permanently, you can modify GRUB configuration as follows.

Change the Default Kernel Version Permanently on CentOS 7

First, list all available kernel images added to GRUB2 by running the following command.

$ grep '^menuentry' /boot/grub2/grub.cfg

Identify the GRUB menu entry for the kernel that you want to set as default. Each menu entry is assigned by GRUB2 a numeric value starting from 0 in an increasing order. That is, the first menu entry assigned 0, the second entry assigned 1, etc. For example, the menu entry value for the kernel 3.10.0-327 is '2' in the above screenshot.

Open /etc/default/grub with a text editor, and set GRUB_DEFAULT to the numeric entry value for the kernel you chose as the default. In this example, I choose the kernel 3.10.0-327 as the default kernel.

GRUB_DEFAULT=2

Finally, re-generate GRUB configuration.

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot and confirm that the specified kernel is selected by GRUB2 by default.

Change the Default Kernel Version Permanently on CentOS 6 or earlier

CentOS 6 or earlier does not ship with GRUB2, but GRUB as a default boot loader.

The first step to change the default boot kernel on CentOS 6 is to get a list of all available kernel images added to GRUB. The following command will show you the list.

$ sudo grep '^[[:space:]]*kernel' /boot/grub/grub.conf

From the list, identify the kernel that you want to set as default. Each kernel in the list is assigned by GRUB a numeric entry value starting from 0 in an increasing order. That is, the first entry assigned 0, the second entry assigned 1, etc. For example, the kernel 2.6.32-431 is assigned GRUB entry value '1' in the above screenshot.

Open /boot/grub/grub.conf with a text editor, look for 'default=N', and change N to the GRUB entry value for the default kernel to use. For example, to set the kernel 2.6.32-431 as the default kernel:

default=1

Reboot and confirm that the chosen kernel has been booted by default.

Change the Default Boot Kernel Temporarily on CentOS

Often times you may want to switch to a different kernel just temporarily, not permanently. Even if you do want to change the default kernel permanently, it is a good idea to try a temporary boot to a new kernel before making a permanent transition from the old kernel to a new one. That way, in case there is any kernel crash with the new kernel, you can easily fall back to the old kernel simply by rebooting.

Of course you can choose a kernel to boot interactively via GRUB menu. However, such interactive control is not always available, for example, when you are booting over SSH remotely.

Here is how to change the default boot kernel "temporarily" from the command line. I assume that '2' is the numeric GRUB menu entry value of a kernel that you want to boot into during the next boot session. Replace the number with your own.

On CentOS 7:

[root~]# grub2-reboot 2
[root~]# reboot

On CentOS 6:

[root~]# echo "savedefault --default=2 --once" | grub --batch
[root~]# reboot

Once you reboot, you will boot into a specified kernel "just once". Next time you reboot, you will revert to the default kernel.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

One thought on “How to change default boot kernel permanently or temporarily on CentOS

Leave a comment

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