Managing UEFI with Efibootmgr (with examples)
- Linux
- December 17, 2024
Efibootmgr is a powerful command-line utility used for managing UEFI boot entries on a Linux system. It allows system administrators to inspect, modify, and update the boot settings stored in the UEFI firmware, thus facilitating a more flexible and controlled boot process. Proper use of efibootmgr can help resolve boot-related issues, set preferred boot orders, and maintain multiple operating systems more efficiently.
Use case 1: List all boot options with their numbers
Code:
efibootmgr -u
Motivation: Listing all boot options is essential for understanding the current boot configuration of your system. It allows you to see which boot entries are available, their associated numbers, and helps identify the default boot order. This information is crucial for troubleshooting boot issues or when planning to rearrange the boot sequence.
Explanation:
efibootmgr
: This invokes the efibootmgr utility.-u
: Stands for “unicode” which ensures proper handling of Unicode characters in boot entries. This is particularly useful if the system uses non-ASCII characters in its boot entries or descriptions.
Example Output:
BootCurrent: 0001
Timeout: 1 seconds
BootOrder: 0001,0002,0003
Boot0001* Linux
Boot0002* Windows Boot Manager
Boot0003* UEFI Shell
This output lists all available boot entries, their numbers, and the order in which they will be attempted during startup.
Use case 2: Add UEFI Shell v2 as a boot option
Code:
sudo efibootmgr -c -d /dev/sda -p 1 -l "\path\to\shell.efi" -L "UEFI Shell"
Motivation: Adding UEFI Shell as a boot option allows system administrators to have a versatile tool for low-level system diagnosis and scripting at their disposal. This environment can be invaluable for system recovery, testing, or managing UEFI variables directly.
Explanation:
sudo
: This command must be run with superuser privileges, as it changes system boot settings.-c
: Creates a new boot option.-d /dev/sda
: Specifies the disk where the UEFI shell is located.-p 1
: Indicates the partition number where the .efi executable is stored.-l "\path\to\shell.efi"
: Specifies the path to the UEFI Shell executable file.-L "UEFI Shell"
: Sets a human-readable label for this boot option.
Example Output:
BootCurrent: 0001
Timeout: 1 seconds
BootOrder: 0001,0002,0003,0004
Boot0001* Linux
Boot0002* Windows Boot Manager
Boot0003* UEFI Shell
Boot0004* UEFI Shell
This example output shows the newly added UEFI Shell boot option with its own entry number.
Use case 3: Add Linux as a boot option
Code:
sudo efibootmgr --create --disk /dev/sda --part 1 --loader "\vmlinuz" --unicode "kernel_cmdline" --label "Linux"
Motivation: Manually adding a Linux boot option can be necessary in dual-boot or multi-boot systems where booting from new or experimental kernels is required. It provides a way to manage multiple kernel versions or distributions.
Explanation:
sudo
: Required to modify system boot entries.--create
: Initializes the creation of a new boot entry.--disk /dev/sda
: Designates the disk containing the Linux kernel.--part 1
: Specifies the partition containing the kernel.--loader "\vmlinuz"
: Points to the Linux kernel image to use as the boot loader.--unicode "kernel_cmdline"
: Mentions any kernel parameters necessary during boot time using Unicode encoding.--label "Linux"
: Provides an easy-to-identify name for this boot entry.
Example Output:
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0002,0003,0004
Boot0001* Linux
Boot0002* Windows Boot Manager
Boot0003* UEFI Shell
Boot0004* Linux
This output shows the newly created Linux boot option alongside existing ones, with its own unique entry number.
Use case 4: Change the current boot order
Code:
sudo efibootmgr -o 0002,0008,0001,0005
Motivation: Changing the boot order is crucial when you want your system to prioritize booting from a particular operating system or device. This is useful in dual-boot setups or when troubleshooting by prioritizing boot from recovery or diagnostic media.
Explanation:
sudo
: Grants administrative privileges to alter boot configurations.-o
: Allows explicit specification of the boot order sequence.0002,0008,0001,0005
: Represents the desired sequence of boot entries, with the numbers corresponding to boot options listed when you run efibootmgr without additional arguments.
Example Output:
BootCurrent: 0001
Timeout: 3 seconds
BootOrder: 0002,0008,0001,0005
Boot0001* Linux
Boot0002* Windows Boot Manager
Boot0003* UEFI Shell
The updated boot order is displayed, which reflects the sequence specified in the command.
Use case 5: Delete a boot option
Code:
sudo efibootmgr -b 0008 -B
Motivation: Removing unnecessary or redundant boot entries helps prevent confusion and potential boot conflicts. This is particularly useful when an operating system is no longer installed or needed, or if multiple boot entries were created by mistake.
Explanation:
sudo
: Required to execute changes in system boot configuration.-b 0008
: Specifically targets the boot entry number to be deleted.-B
: Instructs efibootmgr to delete the specified boot entry.
Example Output:
BootCurrent: 0001
Timeout: 5 seconds
BootOrder: 0002,0001,0003
Boot0001* Linux
Boot0002* Windows Boot Manager
The example output confirms the removal of the specified boot entry showing a streamlined boot list.
Conclusion:
The efibootmgr utility is an indispensable tool for those managing Linux systems with UEFI firmware. Whether you need to list, create, modify, or delete boot options, efibootmgr offers the flexibility to tailor the boot process to your specific needs. Understanding and applying these commands can empower you to maintain a robust and efficient multi-boot environment.