How To Change The Linux Boot Order with Grub


grub bootloader menu centos

Introduction

GRUB, short for Grand Unified Bootloader, is in charge of taking over from the BIOS at boot time. In this tutorial we will learn how to Change the Linux Boot order with Grub.

You need to know that after the BIOS finishes it’s process, GRUB first loads itself, then it loads the Linux kernel into the memory, and just after that it turn over execution to the kernel.

It also supports multiple Linux kernels and allows the user to select between them at boot time using a menu. Which we will explain more about it down below.

GRUB2 is the replacement and updated version of grub, in this tutorial we will refer to it just as grub.

Select the default booting Kernel

After the BIOS has done it’s booting process, the GRUB menu will be prompted. This menu allows you to select one of the installed system Kernels to boot with, so if you do not want to boot with the default one, just use the arrow keys up and down and hit Enter.

You will notice that the GRUB menu has a default 5 seconds timeout, after that it will boot the 1st, and also default, Linux Kernel. For instance, If you want to permanent replace the default booting Kernel for your Linux system, please check the following example procedure.

In order list all the menu entries that will be displayed at system boot, you can view them with the following command:

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

0 : CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64
1 : CentOS Linux 7 (Core), with Linux 3.10.0-229.4.2.el7.x86_64
2 : CentOS Linux 7 (Core), with Linux 3.10.0-229.el7.x86_64
3 : CentOS Linux 7 (Core), with Linux 0-rescue-605f01abef43b72ba

From the above example, if we want to set as the default booting kernel the number 2, we would use the following command:

 [lag@core]$ grub2-set-default 2

Now, If you want to list what’s the saved entry use the following command:

 [lag@core]$ grub2-editenv list
 saved_entry=2

So, to apply the new booting order you can just reboot the machine and it will load the newly set to default Linux Kernel.

 [lag@core]$ reboot 

After it comes back, you will notice that it booted with the selected Kernel version:

[lag@core]$ uname -a 

Manual Editing the Grub config file to change the boot order

Above all what we have learned, If you want to manually edit the Grub config file, you must know that it’s located in /etc/default/grub. There are quiet a few options available to modify, this is an example of the default content:

$ cat /etc/default/grub
 GRUB_TIMEOUT=5
 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
 GRUB_DEFAULT=saved
 GRUB_DISABLE_SUBMENU=true
 GRUB_TERMINAL_OUTPUT="console"
 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"
 GRUB_DISABLE_RECOVERY="true"

It’s important to know that If you made any changes, save the file and run grub2-mkconfig to re-create the /boot/grub2/grub.cfg file. Run the following command:

[lag@core]$ grub2-mkconfig –o /boot/grub2/grub.cfg

Some of the grub.cfg parameters are described as follows:

  • GRUB_TIMEOUT: It’s the time in seconds after the menu is displayed to boot the default entry, unless a key is pressed. The default time is 5 seconds. Set to 0 to boot immediately without displaying the menu, or to -1 to wait indefinitely.
  • GRUB_DISTRIBUTOR: Set by distributors of GRUB and is used to generate more informative menu entry titles.
  • GRUB_DEFAULT: The default menu entry to boot. A value of 0 boots the first menu entry. The value of 1 boots the second menu entry. A value of “saved” instructs GRUB 2 to load the last successfully loaded operating system.

Note: The GRUB_DEFAULT value of “saved” also allows you to use the grub2-set-default and grub2-reboot commands to specify the default entry, as we explained before. To clarify this, the two commands are described as follows:

grub2-set-default: Sets the default entry for all subsequent reboots.
grub2-reboot: Sets the default entry for the next reboot only.

  • GRUB_DISABLE_SUBMENU: By default, the grub2-mkconfig command generates a top-level menu entry for the kernel with highest version number and puts all other found kernels or alternative menu entries for recovery mode in a submenu. Setting GRUB_DISABLE_SUBMENU=true disables this.
  • GRUB_TERMINAL_OUTPUT: The terminal output device. When specifying multiple devices, separate the valid terminal output names with spaces.
  • GRUB_CMDLINE_LINUX: Kernel boot parameters. More information on kernel boot parameters is provided at GRUB site.
  • GRUB_DISABLE_RECOVERY: By default, two menu entries are generated for each Linux kernel: one default entry and one entry for recovery mode. Setting GRUB_DISABLE_RECOVERY=“true” disables this.

As you will see, there are many other options available, but we are not listing them all in this tutorial, for more information about the grub config file please refer to the GNU Grub simple configuration handling site.

Conclusion

GRUB2 is the evolution of GRUB, it’s the main bootloader for the major Linux distributions on the market today, because it’s easy to configure and provides us with many tools for debugging or fixing disk and kernel issues.

If you to want learn more about this tutorial or have any questions, feel free to send your comments down below.

Don’t forget to check our other Tutorials, we are constantly submitting new ones every week.

Tags: , , , ,

Buy us a Coffee

Categories

Recent Posts

RSS Other Tutorials