Friday, July 8, 2016

How To Change The EFI Boot Order With efibootmgr

Introduction

A large number of people like to dual boot Windows and Linux.
Some people do this because they are keen to take a look at Linux but
aren't ready to cut the parachute cord that Windows provides them whilst
others just have a couple of Windows applications they still need.
A common issue when installing Linux as a dual boot operating system is the Extensible Firmware Interface (EFI) Boot Manager which comes as standard on a large number of modern computers and laptops.
Users find that despite installing Linux the computer still boots straight to Windows with no option for booting Linux.
If you can boot to a live version of Linux
(which you must be able to do since you installed from it) then you can
install the EFI Boot Manager (efibootmgr) application which lets you
manipulate the boot order so that you can boot into Linux and Windows.
This guide will show you how to use EFI Boot Manager and will explain all of the switches.

How To Install EFI Boot Manager

To
install the EFI Boot Manager using a Debian based distribution such as
Debian, Linux Mint or Ubuntu open a terminal window and type the
following apt-get command:

sudo apt-get install efibootmgr

If sudo isn't installed on your computer then you will need to use a Linux user which has permissions to install software.
If you are using a Red Hat based distribution such as Fedora or CentOS then you can use the following yum command:

sudo yum install efibootmgr

For openSUSE you can use the following command:

sudo zypper install efibootmgr

Finally for Arch based distributions such as Arch, Manjaro and Antergos use the following pacman command:

sudo pacman -S efibootmgr

How To Find Out The Current Boot Order

To find out the order in which systems will load type the following command:

So what does this tell us.
The
BootCurrent line shows which of the boot options was used this time
around. In my case it was actually Linux Mint but Linux Mint is a
derivative of Ubuntu and so 0004 = ubuntu.
The Timeout tells you how long the menu appears before the first boot option is chosen and it defaults to 0.
The
BootOrder shows the order in which each option will be loaded. The next
item in the list will only be chosen if it fails to load the preceding
item.
In the example above my system is going to boot 0004 first
which is Ubuntu, then 0001 which is Windows, 0002 network, 0005 hard
drive, 0006 CD/DVD drive and finally 2001 which is the USB drive.
If
the order was 2001,0006,0001 then the system would try to load from a
USB drive and if there weren't any present it would boot from the DVD
drive and finally it would boot Windows.

How To Change The EFI Boot Order

The
most common reason to use the EFI Boot Manager is to change the boot
order. If you have installed Linux and for some reason Windows it
booting first then you will need to find your version of Linux in the
boot list and make it boot before Windows.
For example take this list:

BootCurrent: 0001

Timeout: 0 seconds

BootOrder: 0001,0004,0002,0005,0006,2001

Boot0001 Windows Boot Manager

Boot0002 Network

Boot0004 ubuntu

Boot0005 Hard Drive

Boot0006 CD/DVD/CD-RW Drive

Boot2001 EFI USB Device

You should hopefully be able to see that Windows boots first because it is assigned to 0001 which is first in the boot order.
Ubuntu won't load unless Windows fails to boot because it is assigned to 0004 which comes after 0001 in the boot order list.
To
save messing around I find that it is a good idea to not only place
Linux before Windows but also put the USB drive and DVD drive before
Linux and Windows. That way it is easier to boot from a USB drive.
To change the boot order you would use the following command specifying the boot order that you wish to use.

sudo efibootmgr -o 2001,0006,0004,0001

You can use a shorter notation as follows:

sudo efibootmgr -o 2001,6,4,1

The boot list should now look like this:

BootCurrent: 0001

Timeout: 0 seconds

BootOrder: 2001,0006,0004,0001

Boot0001 Windows Boot Manager

Boot0002 Network

Boot0004 ubuntu

Boot0005 Hard Drive

Boot0006 CD/DVD/CD-RW Drive

Boot2001 EFI USB Device

Note
that if you fail to list all the possible options then they won't be
listed as part of the boot order. This means 0002 and 0005 will be
ignored.

How To Change The Boot Order For The Next Boot Only

If you want to temporarily make it so the next boot of the computer uses a specific option use the following command:

sudo efibootmgr -n 0002

BootCurrent: 0001

Timeout: 0 seconds

BootOrder: 2001,0006,0004,0001

Boot0001 Windows Boot Manager

Boot0002 Network

Boot0004 ubuntu

Boot0005 Hard Drive

Boot0006 CD/DVD/CD-RW Drive

Boot2001 EFI USB Device

Using the above list this would mean the next time the computer boots it will try to boot from the network.
If you change your mind and you want to delete the next boot option then run the following command to cancel it.

sudo efibootmgr -N

Setting A Timeout

If you want to be able to choose from a list each time your computer loads then you can specify a timeout.
To do this enter the following command:

sudo efibootmgr -t 10

The above command will set a timeout of 10 seconds. After the time has run out the default boot option will be chosen.
You can delete the timeout using the following command:

If you have the above boot options and you wanted to remove Ubuntu then you would first change the boot order as follows:

sudo efibootmgr -o 2001,6,1

You would then delete the Ubuntu boot option with the following command:

sudo efibootmgr -b 4 -B

The first -b selects the boot option 0004 and the -B deletes the boot option.
You can use a similar command to make a boot option inactive as follows:

sudo efibootmgr -b 4 -A

You can make the boot option active again by using this command:

sudo efibootmgr -b 4 -a

Further Reading

There
are further commands which would be used by OS installers to create
boot menu options in the first place and for system administrators to
create network boot options.
You can find out more about these by reading the manual pages for EFI Boot Manager using the following command: