Use efibootmgr to manage UEFI boot items and add missing boot items


UEFI is used to replace the traditional BIOS to boot the operating system. It is also very important to learn to modify the UEFI boot items. The full name of UEFI is: "Unified Extensible Firmware Interface" (Unified Extensible Firmware Interface). Currently, newly purchased computers support UEFI firmware. , if you need to start the traditional MBR device, you need to enable the CSM (Compatibility Support Module). Turning off CSM becomes pure UEFI boot, and fully supports secure boot. Secure Boot, Secure Boot is only available for operating systems that use UEFI to boot. If the computer wants to boot a device that does not fully support UEFI, you must turn off Secure Boot and then turn on CSM. Such as Win7 system, the CSM compatibility mode must be turned on. Windows8 and above can support UEFI very well, and in order to set the system boot, it is necessary to manage UEFI boot items.

When the Linux system is directly installed on the domestic personal physical machine, a Windows system is generally installed to achieve dual systems, so that sometimes the system startup items are lost. The

solution for Linux systems is to use the efibootmgr command to add startup items. EasyUEFI software can be used under Windows.

1. If the system loses the Linux boot item, if it is a dual system, you can only enter Windows, but I don’t like to use EasyUEFI, then you can choose a Linux liveCD system, such as Ubuntu, and
burn the Ubuntu liveCD into a U disk to boot. The CD-ROM will start the system very slowly.

2. I use the efibootmgr command under Ubuntu (non-liveCD), the display is as follows:

pipci@ubuntu:~$ efibootmgr
BootCurrent: 0012
Timeout: 0 seconds
BootOrder: 0012,0010,0011,000F,000B,000A,0006,0007,0008,0009,000C,000D,000E
Boot0000  Setup
Boot0001  Boot Menu
Boot0002  Diagnostic Splash Screen
Boot0003  Lenovo Diagnostics
Boot0004  Rescue and Recovery
Boot0005  Startup Interrupt Menu
Boot0006* USB CD
Boot0007* USB FDD
Boot0008* ATAPI CD0
Boot0009* ATAPI CD1
Boot000A* ATA HDD0
Boot000B* ATA HDD1
Boot000C* ATA HDD2
Boot000D* USB HDD
Boot000E* PCI LAN
Boot000F* Windows Boot Manager
Boot0010* ubuntu
Boot0011* ubuntushim
Boot0012* opensuse-secureboot
pipci@ubuntu:~$


The list is still very intuitive to display the current boot items, boot timeout, EFI boot order, 0012 is the first boot item corresponds to the opensuse system, 0011 is the second boot item corresponds to the ubuntu system This is manually added by me,
000F is the fourth boot The corresponding Windows system of the item.

3. Find the system startup file, each system will create its own startup file in the EFI partition.

pipci@ubuntu:~$ sudo fdisk -l #Product look at the partition

device where EFI is located at the end of Start sector Size type
/dev/sdb1 2048 206847 204800 100M EFI System #The partition where EFI is located                  
/dev/sdb2 206848 468991 262144 128M Microsoft reserved
/dev/ 468 992 83,888,127 83,419,136 39.8 g of in the Microsoft sdb3 the Data Basic
/ dev / sdb4 4G in the Microsoft Basic 83,888,128 92,276,735 8388608 the Data
/ dev / sdb5 40G in the Microsoft Basic 83,892,224 92,276,736 176 168 959 the Data
/ dev / sdb6 176.16896 million 254 294 015 78,125,056 37.3 g Linux filesystem
/dev/sdb7  254294016 262682623   8388608    4G Linux filesystem
/dev/sdb8  262682624 468860927 206178304 98.3G Microsoft basic data
pipci@ubuntu:~$

4、挂在EFI分区

pipci@ubuntu:~$ sudo mount /dev/sdb1 /mnt/      #挂载EFI分区到/mnt目录

5、进入EFI分区
pipci@ubuntu:~$ cd /mnt/
bash: cd: /mnt/: 权限不够
pipci@ubuntu:~$ sudo -i                #以root用户身份运行一个登录 shell
root@ubuntu:~# cd /mnt/

6、产出EFI分区
root@ubuntu:/mnt# ls
EFI

7、进入EFI目录,查看

root@ubuntu:/mnt# cd EFI/
root@ubuntu:/mnt/EFI# ls
Boot  Microsoft  opensuse  ubuntu           #可以看出安装的系统
root@ubuntu:/mnt/EFI#

8、查看EFI下各目录内容:
root@ubuntu:/mnt/EFI# ls Boot/
bootx64.efi
root@ubuntu:/mnt/EFI# ls Microsoft/
Boot
root@ubuntu:/mnt/EFI# ls opensuse/
boot.csv  grub.cfg  grub.efi  grubx64.efi  MokManager.efi  shim.efi
root@ubuntu:/mnt/EFI# ls ubuntu/
fw  fwupx64.efi  grub.cfg  grubx64.efi  mmx64.efi  shimx64.efi
root@ubuntu:/mnt/EFI#

9、添加启动项

root@ubuntu:~# efibootmgr -c -w -L "BootOptionName" -d /dev/sda -p 1 -l \\EFI\\Boot\\bootx64.efi

其中BootOptionName替换成你设定的名字,-d后面是启动分区所在的硬盘(默认为/dev/sda),-p后面是分区位置(默认为1),-l是启动efi文件的路径。
这样就添加了EFI启动项。
举例:
root@ubuntu:~# efibootmgr -c -w -L "BootOptionName" -d /dev/sdb -p 1 -l \\EFI\\Boot\\bootx64.efi    #我的启动分区所在的硬盘为/dev/sdb
BootCurrent: 0012
Timeout: 0 seconds
BootOrder: 0013,0012,0010,0011,000F,000B,000A,0006,0007,0008,0009,000C,000D,000E
Boot0000  Setup
Boot0001  Boot Menu
Boot0002  Diagnostic Splash Screen
Boot0003  Lenovo Diagnostics
Boot0004  Rescue and Recovery
Boot0005  Startup Interrupt Menu
Boot0006* USB CD
Boot0007* USB FDD
Boot0008* ATAPI CD0
Boot0009* ATAPI CD1
Boot000A* ATA HDD0
Boot000B* ATA HDD1
Boot000C* ATA HDD2
Boot000D* USB HDD
Boot000E* PCI LAN
Boot000F* Windows Boot Manager
Boot0010* ubuntu
Boot0011* ubuntushim
Boot0012* opensuse-secureboot
Boot0013* BootOptionName

通过上面的操作可以看出已经添加了 BootOptionName这个启动项,编号是0013,BootOrder:处可以看出已经成为第一启动项。

如果是Linux系统启动项丢失不要添加/EFI/Boot/bootx64.efi这个启动项,因为这个文件可能被Windows系统替换,添加后会直接进入Windows系统,
不能进入GRUB引导程序,可以尝试添加/EFI/opensuse/ 目录下的grubx64.efi  grub.efi  shim.efi MokManager.efi 等文件,每个Linux发行版
对应的目录下的文件可能不一样,根据实际情况添加,我的电脑安装了3个系统,安装顺序为Windows Ubuntu openSUSE,所以要添加最后安装的那个
系统对应的启动文件,因为最后安装的系统的GRUB才会把前面系统添加进去,才可以通过一个GRUB管理多个系统。

10、删除启动项的命令为:

root@ubuntu:~# efibootmgr -b 0013 -B      #删除刚才添加的BootOptionName启动项,对应的编号为0013
BootCurrent: 0012
Timeout: 0 seconds
BootOrder: 0012,0010,0011,000F,000B,000A,0006,0007,0008,0009,000C,000D,000E
Boot0000  Setup
Boot0001  Boot Menu
Boot0002  Diagnostic Splash Screen
Boot0003  Lenovo Diagnostics
Boot0004  Rescue and Recovery
Boot0005  Startup Interrupt Menu
Boot0006* USB CD
Boot0007* USB FDD
Boot0008* ATAPI CD0
Boot0009* ATAPI CD1
Boot000A* ATA HDD0
Boot000B* ATA HDD1
Boot000C* ATA HDD2
Boot000D* USB HDD
Boot000E* PCI LAN
Boot000F* Windows Boot Manager
Boot0010* ubuntu
Boot0011* ubuntushim
Boot0012* opensuse-secureboot

11、删除多余的启动项从新查看启动项:
root@ubuntu:~# efibootmgr
BootCurrent: 0012
Timeout: 0 seconds
BootOrder: 0012,0010,0011,000F,000B,000C,000D
Boot0000  Setup
Boot0001  Boot Menu
Boot0002  Diagnostic Splash Screen
Boot0003  Lenovo Diagnostics
Boot0004  Rescue and Recovery
Boot0005  Startup Interrupt Menu
Boot000B* ATA HDD1
Boot000C* ATA HDD2
Boot000D* USB HDD
Boot000F* Windows Boot Manager
Boot0010* ubuntu
Boot0011* ubuntushim
Boot0012* opensuse-secureboot

12、修改boot 顺序
root@ubuntu:~# efibootmgr -o 0012,0010,0011,000F,000D,000C,000B    
BootCurrent: 0012
Timeout: 0 seconds
BootOrder: 0012,0010,0011,000F,000D,000C,000B
Boot0000  Setup
Boot0001  Boot Menu
Boot0002  Diagnostic Splash Screen
Boot0003  Lenovo Diagnostics
Boot0004  Rescue and Recovery
Boot0005  Startup Interrupt Menu
Boot000B* ATA HDD1
Boot000C* ATA HDD2
Boot000D* USB HDD
Boot000F* Windows Boot Manager
Boot0010* ubuntu
Boot0011* ubuntushim
Boot0012* opensuse-secureboot
root@ubuntu:~#

通过efibootmgr -o 命令将000B和000D调换,如果要设置第一启动,把相应的编号放到命令后的最前面,如上面的0012

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324493073&siteId=291194637