UEFI启动模式安装的服务器出现多个启动项的清理方法

UEFI启动模式安装的服务器,每安装一次,就会出现1个启动项,多次安装以后就会出现多个启动项,实际上只有最后一个有用,本文讲解如何清除无效的启动项。

  1. 手动清理

  1. 执行以下命令查看当前启动EFI硬盘的UUID

[root@openeuler ~]# blkid |grep EFI
/dev/sda1: UUID="0AFD-AB3E" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="596ff23c-ded3-4b84-8660-2169990f5c3b"

本例中的UUID即为596ff23c-ded3-4b84-8660-2169990f5c3b

  1. 查看系统引导菜单

[root@openeuler ~]# efibootmgr
BootCurrent: 000A
BootOrder: 000A,0009,0008,0007,0006,0005,0003,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0003* openEuler     HD(3,GPT,c386ab88-89b0-4b05-8193-fb42c652be36,0x1ed3800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0005* openEuler     HD(1,GPT,88d93c99-f885-4b6f-888c-c4326e220995,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0006* openeuler     HD(1,GPT,82b909b2-5646-458d-b69f-c0df1f01ec54,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0007* openEuler     HD(1,GPT,21ba65ee-4f4d-4f93-8230-6ebe6302bb27,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0008* openEuler     HD(1,GPT,f5b837aa-b840-4391-90d3-476139de09fc,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)

本例中有多个openEuler的系统启动选单,过滤显示更直观

通过UUID即可确定当前有效的是哪一个,通常是最后一个在用。返回信息的第一列为启动项id,以Boot和*字符中的为准。

  1. 通过“efibootmgr -b ${unusedUUID} -B”手动逐个删除即可。

二、脚本清理

如果启动项太多,且有固定标识字符串,则可通过shell脚本清理

以上例主机为例,重复的启动项均包含“openEuler”字串,可通过以下脚本,一次运行即可清理全部的无效启动项(同时备份当前启动项为脚本目录下的efibootmgr.running文件):

#!/bin/bash
##__author__='daigjianbing'

checkinfo="openEuler"
usedUUID=`blkid |grep EFI|awk -F '"' '{print $10 }'`
echo $usedUUID
efibootmgr |grep ${checkinfo}|grep $usedUUID |tee efibootmgr.running
unusedUUID=`efibootmgr |grep openEuler|grep -v $usedUUID|awk '{print $1}'`
for i in $unusedUUID
do
    id=`echo ${i:4:4}`
    echo "###########################"
    echo "cleaning boot menu $id:"
    echo "efibootmgr -b $id -B"
    efibootmgr -b $id -B
    echo "###########################"
done 

执行结果

[root@openeuler tmp]# sh clearUEFImenu.sh 
596ff23c-ded3-4b84-8660-2169990f5c3b
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
cleaning boot menu 0003:
efibootmgr -b 0003 -B
BootCurrent: 000A
BootOrder: 000A,0009,0008,0007,0006,0005,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0005* openEuler     HD(1,GPT,88d93c99-f885-4b6f-888c-c4326e220995,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0006* openeuler     HD(1,GPT,82b909b2-5646-458d-b69f-c0df1f01ec54,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0007* openEuler     HD(1,GPT,21ba65ee-4f4d-4f93-8230-6ebe6302bb27,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0008* openEuler     HD(1,GPT,f5b837aa-b840-4391-90d3-476139de09fc,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
###########################
cleaning boot menu 0005:
efibootmgr -b 0005 -B
BootCurrent: 000A
BootOrder: 000A,0009,0008,0007,0006,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0006* openeuler     HD(1,GPT,82b909b2-5646-458d-b69f-c0df1f01ec54,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0007* openEuler     HD(1,GPT,21ba65ee-4f4d-4f93-8230-6ebe6302bb27,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0008* openEuler     HD(1,GPT,f5b837aa-b840-4391-90d3-476139de09fc,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
###########################
cleaning boot menu 0006:
efibootmgr -b 0006 -B
BootCurrent: 000A
BootOrder: 000A,0009,0008,0007,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0007* openEuler     HD(1,GPT,21ba65ee-4f4d-4f93-8230-6ebe6302bb27,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0008* openEuler     HD(1,GPT,f5b837aa-b840-4391-90d3-476139de09fc,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
###########################
cleaning boot menu 0007:
efibootmgr -b 0007 -B
BootCurrent: 000A
BootOrder: 000A,0009,0008,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0008* openEuler     HD(1,GPT,f5b837aa-b840-4391-90d3-476139de09fc,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
###########################
cleaning boot menu 0008:
efibootmgr -b 0008 -B
BootCurrent: 000A
BootOrder: 000A,0009,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot0009* openEuler     HD(1,GPT,a0b4ba34-0b56-4952-ade5-bf208902a0b6,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################
###########################
cleaning boot menu 0009:
efibootmgr -b 0009 -B
BootCurrent: 000A
BootOrder: 000A,0000,0001,0002,0004
Boot0000* EFI Virtual disk (0.0)        PciRoot(0x0)/Pci(0x15,0x0)/Pci(0x0,0x0)/SCSI(0,0)
Boot0001* EFI VMware Virtual IDE CDROM Drive (IDE 0:0)  PciRoot(0x0)/Pci(0x7,0x1)/Ata(0,0,0)
Boot0002* EFI Network   PciRoot(0x0)/Pci(0x16,0x0)/Pci(0x0,0x0)/MAC(005056ad3eb7,1)
Boot0004* EFI Internal Shell (Unsupported option)       MemoryMapped(11,0xefcb018,0xf3f7017)/FvFile(c57ad6b7-0515-40a8-9d21-551652854e37)
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)
###########################

再次验证,硬盘启动项只有正确的一项了:

[root@openeuler tmp]# efibootmgr |grep openEuler
Boot000A* openEuler     HD(1,GPT,596ff23c-ded3-4b84-8660-2169990f5c3b,0x800,0x12c000)/File(\EFI\openEuler\shimx64.efi)

至此,启动项修复完成。

你可能感兴趣的:(openeuler系统,运维,linux,运维,自动化)