Last updated on October 8, 2020 by Dan Nanni
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.
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.
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.
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.
[root~]# grub2-reboot 2 [root~]# reboot
[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.
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean