How to manage EFI boot manager entries on Linux

UEFI is the firmware interface which on modern machines has superseded the legacy BIOS. One of the features of the UEFI firmware is being able to store boot entries in the persistent and editable NVRAM memory (Non Volatile RAM). While installing a Linux distribution (or any other operating system) in UEFI mode makes usually the related boot entry to be written to the NVRAM, in some cases we may want to perform manual operations such as modifying the boot order, creating or deleting a boot entry.

To accomplish such tasks on Linux we can use the efibootmgr utility. In this tutorial we see how to install it on some of the most used Linux distributions, and how to use it to manage NVRAM boot entries.

In this tutorial you will learn:

  • How to install efibootmgr on some of the most used Linux distributions
  • How to list EFI boot manager entries
  • How to change entries order
  • How to delete a boot entry
  • How to create a boot entry
  • How to set the EFI boot manager timeout interval
How to manage EFI boot manager entries on Linux
How to manage EFI boot manager entries on Linux

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distribution-independent
Software efibootmgr
Other Root permissions to perform administrative tasks
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

Installation

The efibootmgr utility can be easily installed with the package manager of the most used Linux distributions, since it is included in their official repositories. Let’s start from Fedora. On this and other distributions of the Red Hat family, the package manager is called dnf. To install the “efibootmgr” package, all we have to do is to run the following command:

$ sudo dnf install efibootmgr



On recent versions of Debian, and of the many distributions which are based on it, such as Ubuntu or Linux Mint, the package can be installed by using the apt wrapper:

$ sudo apt install efibootmgr

On Archlinux the package is included in the “core” repository, and can be installed by using the pacman package manager:

$ sudo pacman -Sy efibootmgr

Once the utility is installed on our system, we can use it do manage boot manager entries. Let’s see how.

Listing EFI boot manager entries

On system which uses the UEFI firmware, EFI boot manager entries are stored in the non-volatile RAM. To list the existing boot entries using efibootmgr, all we have to do is to invoke the utility without any option or argument. Here is the output of the command on my system:

$ efibootmgr
BootCurrent: 0000
Timeout: 2 seconds
BootOrder: 0000,0010,0011,0012,0013,0017,0018,0019,001A,001B,001C,001D,001E
Boot0000* Fedora
Boot0010 Setup
Boot0011 Boot Menu
Boot0012 Diagnostic Splash Screen
Boot0013 Lenovo Diagnostics
Boot0014 Startup Interrupt Menu
Boot0015 Rescue and Recovery
Boot0016 MEBx Hot Key
Boot0017* USB CD
Boot0018* USB FDD
Boot0019* NVMe0
Boot001A* ATA HDD0
Boot001B* USB HDD
Boot001C* PCI LAN
Boot001D Other CD
Boot001E Other HDD
Boot001F* IDER BOOT CDROM
Boot0020* IDER BOOT Floppy
Boot0021* ATA HDD
Boot0022* ATAPI CD
Boot0023* PCI LAN

In the above output we can notice a series of information, corresponding to boot variables. First of all we can see the BootCurrent: the value of this key reports what entry in the list was used to launch the current operating system (in this case you can see how I am using Fedora).

The second entry we found in the output is Timeout: this indicates the amount of time after which an entry is automatically selected on the boot menu, in this case 2 seconds. Next, we have BootOrder: the value of this key is the comma separated list of entry numbers and shows the order in which the related entries are displayed in the EFI boot menu.

After the entries we mentioned above, the command reports the list of the available boot entries. Each entry is reported with its number and name. On the list, we can clearly see the active entries because their are marked with the ‘*’ sign.

Changing the EFI boot manager entries order

We can use the efibootmgr utility to change the current boot order. If that is the task we want to perform, all we have to do is to run efibootmgr with administrative privileges, with the -o option (which is the short version of --bootorder) and pass the list of the boot entries ordered according to our will. In the previous example we saw how the current boot order on my machine is the following:

0000,0010,0011,0012,0013,0017,0018,0019,001A,001B,001C,001D,001E



According to the list reported by the program, this means the first entry which will appear on the menu is “Fedora”, and the second one is that relative to the “Setup”. Suppose we want to swap those entries, so that “Setup” becomes the first one. All we have to do is to run the following command:

$ sudo efibootmgr -o 0010,0000,0011,0012,0013,0017,0018,0019,001A,001B,001C,001D,001E

All we did was reporting the list of entries, as argument to the -o option, just with the first two entries in the inverted order. The command will respond by printing the same output we saw in the previous example. In it, we can clearly see how the boot order is now what we set with the command (The “Setup” entry is not the first one):

BootCurrent: 0000
Timeout: 2 seconds
BootOrder: 0010,0000,0011,0012,0013,0017,0018,0019,001A,001B,001C,001D,001E
Boot0000* Fedora
Boot0010 Setup
Boot0011 Boot Menu
Boot0012 Diagnostic Splash Screen
Boot0013 Lenovo Diagnostics
Boot0014 Startup Interrupt Menu
Boot0015 Rescue and Recovery
Boot0016 MEBx Hot Key
Boot0017* USB CD
Boot0018* USB FDD
Boot0019* NVMe0
Boot001A* ATA HDD0
Boot001B* USB HDD
Boot001C* PCI LAN
Boot001D Other CD
Boot001E Other HDD
Boot001F* IDER BOOT CDROM
Boot0020* IDER BOOT Floppy
Boot0021* ATA HDD
Boot0022* ATAPI CD
Boot0023* PCI LAN

Deleting a boot entry

We can use efibootmgr to delete existing boot entries. A typical case in which we may want to perform such an action, is to remove an entry for an operating system which doesn’t exist anymore. To delete a boot entry with efibootmgr, all we have to do is to use the -b option (short for --bootnum) to select the boot entry we want to remove by passing its index as argument, and then use -B (short for --delete-bootnum) to actually delete it.

To delete index 0000, which in our case is  related to Fedora, for example, we would run:

$ sudo efibootmgr --delete-bootnum --bootnum 0

Notice that when passing the boot entry number we are not requested to include the padding 0s. The removal of a boot entry is an operation which should be performed with care: always make sure you delete the appropriate one!

Creating a boot entry

The efibootmgr utility can be used to create new entries in the EFI boot manager menu. To create a boot entry we must know the location of the EFI system partition and the path of the EFI image to boot.



The option which must be used to create a new entry is -c (short for --create). Suppose we, by mistake, removed the “fedora” entry from the boot menu and we want to re-create it. Supposing the EFI partition is the first one of the /dev/sda disk, and the path (relative to the EFI partition) of the image to boot is EFI/fedora/shimx64.efi, we would run the following command:

$ sudo efibootmgr --create --disk=/dev/sda --part=1 --label="fedora" --loader='EFI\fedora\shimx64.efi'

In the above example we invoked efibootmgr with the -c option, to declare that we want to create a new entry. We used --disk (-d) to specify the disk on which the EFI system partition is located, and --part (-p) to specify which partition on that disk is the EFI partition (by standard, the EFI partition should always be the first one, formatted in FAT32).

We also used the --label option  (-L) to provide the name to be used for the entry in the menu, and finally --loader (-l) to pass the path of the image to boot. One important thing to notice is that when passing the path of the EFI image, backslashes must be used as directory separator. For the backslashes to be escaped, the path should be either provided in single quotes (recommended), or each backslash should be escaped with another one (the path would become: EFI\\fedora\\shimx64.efi).

The created boot entry will be automatically put at the top of the boot order list.

Changing the EFI boot manager timeout

As we previously saw, we can set the timeout interval after which the default entry in the EFI boot manager is automatically selected. Reported in the output of the efibootmgr command, we saw that in this case the timeout value is set to 2 seconds. Suppose we want to increase it, and set it to 4 seconds. Here is the command we would run:

$ sudo efibootmgr --timeout=4

As you can see in the example, we used the --timeout option (-t) and provided the timeout value in seconds.

Conclusions

Machines with support for the UEFI firmware stores boot entries in the non-volatile RAM called NVRAM. When we install a Linux distribution, an entry for it is automatically added in the EFI boot manager menu, which can be further customized by using the efibootmgr utility. In this tutorial we saw how to install the latter in some of the most used Linux distributions and how to use it to change the boot order, to delete and create new menu entries and to change the timeout value.



Comments and Discussions
Linux Forum