How to do it…
Let’s run the df -h command to view the partitions in the system. Please notice that /boot/efi is mounted on the /dev/sda1 partition in this example:

Figure 3.10 – df -h command
If you run the ls -l /boot/efi/EFI/redhat command, this directory contains a first-stage bootloader called shimx64.efi, a GRUB 2 bootloader called grubx64.efi, and a GRUB 2 configuration file called grub.cfg. The location of the grub.cfg file is different in BIOS mode as it resides in /boot/grub2:
[root@demo2 ~]# ls -l /boot/efi/EFI/redhat
total 4112
-rwx——.
1 root root 134 Aug 27 15:51 BOOTX64.CSV
drwx——.
2 root root 4096 Oct 15 19:59 fonts
-rwx——.
1 root root 6545 Feb 14 20:45 grub.cfg
-rwx——.
1 root root 1024 Feb 14 22:31 grubenv
-rwx——.
1 root root 1024 Feb 14 21:15 grubenvRvxfzJ
-rwx——.
1 root root 2288320 Oct 15 19:59 grubx64.efi
-rwx——.
1 root root 905400 Aug 27 15:51 mmx64.efi
-rwx——.
1 root root 984688 Aug 27 15:51 shimx64.efi
[root@localhost falvarez]#
The /etc/default/grub file is responsible for containing the user settings for the grub.cfg file. Note that this file is also located in the same location when in BIOS mode. Furthermore, if you make any changes to this file, the grub.cfg file will need to be rebuilt:
[root@demo2 ~]# 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 resume=/dev/mapper/ol-swap rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet”
GRUB_DISABLE_RECOVERY=”true”
GRUB_ENABLE_BLSCFG=true
To rebuild the grub.cfg file, please use the grub2-mkconfig command specifying the output file, using the -o option, such as /boot/efi/EFI/redhat/grub.cfg:
[root@demo2 ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
Generating grub configuration file …
Adding boot menu entry for EFI firmware configuration
done
The utility used to manage the UEFI boot process is called efibootmgr (it provides a boot menu showing the boot entries). It also allows us to manipulate boot entries by doing the following:
- Altering the boot order
- Creating boot entries
- Removing boot entries
- Specifying the boot entry for the next boot
How it works…
You can view a summary of boot entries by running the efibootmgr command with no options. For more details, add the -v option to it:
[root@demo2 ~]# efibootmgr -v
BootCurrent: 0004
Timeout: 0 seconds
BootOrder: 0004,0000,0001,0002,0003
Boot0000* UiApp
Boot0001* UEFI VBOX CD-ROM VB2-01700376
Boot0002* UEFI VBOX HARDDISK VB2d5be0c5-80049c5d
Boot0003* EFI Internal Shell
Boot0004* Oracle Linux
[root@demo2 ~]# efibootmgr -v
BootCurrent: 0004
Timeout: 0 seconds
BootOrder: 0004,0000,0001,0002,0003
Boot0000* UiApp FvVol(7cb8bdc9-f8eb-4f34-aaea-3ee4af6516a1)/FvFile(462caa21-7614-4503-836e-8ab6f4662331)
Boot0001* UEFI VBOX CD-ROM VB2-01700376 PciRoot(0x0)/Pci(0x1,0x1)/Ata(1,0,0)N…..YM….R,Y.
Boot0002* UEFI VBOX HARDDISK VB2d5be0c5-80049c5d PciRoot(0x0)/Pci(0xd,0x0)/Sata(0,65535,0)N…..YM….R,Y.
Boot0003* EFI Internal Shell FvVol(7cb8bdc9-f8eb-4f34-aaea-3ee4af6516a1)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
Boot0004* Oracle Linux HD(1,GPT,dff50c5d-96ed-406c-9823-212649b405bd,0x800,0x12c000)/File(\EFI\redhat\shimx64.efi)
As you can see in the preceding example, boot 0004 (Oracle Linux) is the boot entry used to start the currently running system, called BootCurrent. BootOrder is the boot order used in the boot manager; consequently, the boot manager will boot the first active entry in the list. If it’s not successful, it will try the next entry, and so on. If you’re using UEFI on your system, efibootmgr is a handy command-line tool that enables you to manage your EFI boot entries. With this utility, you can easily view, create, modify, and delete boot entries in the EFI boot manager.
If you want to delete a boot entry, you can use the -B option. In this case, we will delete the CDROM record (0001) option using the following command:
efibootmgr -b 0001 -B
You can also change the boot order with the -o option. In the following command, we will change the boot order to make the UFEI shell the default boot:
efibootmgr -o 0003,0004,0002,0003
Please use the man command to learn more about the efibootmgr command.
Warning
Be very careful when changing the config. Accidentally changing the boot order to a device that is not bootable can put you in a situation where you are recovering the system. This is even more important if you are running in an environment where you do not have access to the console.