Tips & Tricks

How to change boot order in CentOS 7 or RHEL 7

change boot order
change boot order

How to change boot order in CentOS 7 or RHEL 7

This post explains how to change boot order in CentOS 7 or RHEL 7. As you know, CentOS 7 and higher versions are using grub2 bootloader.

Unlike legacy grub, we are not going to manually edit grub configuration file. In GRUB2, the GRUB configuration file is generated using the commandline tool grub2-mkconfig. It is using the templates from the directory /etc/grub.d and the settings are fetched from the file /etc/default/grub

So first we need to list the Kernels available on the GRUB configuration file using the following command:

Please note if your system uses UEFI, the location of GRUB configuration will be /boot/efi/EFI/centos/grub.cfg

grep ^menuentry /boot/grub2/grub.cfg | cut -f 2 -d \'

The output looks like this:

[root@server ~]# grep ^menuentry /boot/grub2/grub.cfg | cut -f 2 -d \'
CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1160.24.1.el7.x86_64) 7 (Core)
CentOS Linux 7 Rescue 5adf37c1ffe0483daedb94eec20957b0 (3.10.0-1160.15.2.el7.x86_64)
CentOS Linux (3.10.0-1160.15.2.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.11.6.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-00a62363617944e08db8db894ba6145e) 7 (Core)
[root@server ~]#

As in legacy GRUB, the first menuentry is denoted as 0 in GRUB2 too. So if you would like to boot the kernel CentOS Linux (3.10.0-693.11.6.el7.x86_64) 7 (Core) by default, you need to run the following command:

grub2-set-default 4

The kernel CentOS Linux (3.10.0-693.11.6.el7.x86_64) 7 (Core) lies in line number 5 and hence it is denoted as menuentry 4.

Then we need to generate the grub configuration file as the above command made the changes in the settings file /etc/default/grub

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

Once it’s done verify that the current kernel and the new default kernel before reboot:

You can verify the currently using Kernel by using the default command:

uname -r

Sample Output:

[root@server ~]# uname -r
3.10.0-1160.25.1.el7.x86_64
[root@server ~]#

Also, verify the new default Kernel:

grubby --default-kernel

Sample Output:

[root@server ~]# grubby --default-kernel
/boot/vmlinuz-3.10.0-693.11.6.el7.x86_64
[root@server ~]#

Once everything is verified, reboot the system:

reboot

That’s it!

Also Read:

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com

Topics