UEFI机器无法通过NVRAM bootcatalog启动Ubuntu。 怎么修?

这里发布的答案应该是:

  • 避免要求用户下载和安装其他软件包或PPA。
  • 尽可能快速和简单。 (我尝试过启动修复,但没有资格。)
  • 可能为没有太多终端使用经验的用户提供脚本。

像这样的类似问题已经多次发布到网站:

  • 最近发布的Ubuntu已成功安装在支持UEFI的计算机上,该计算机预装了Windows 8或更高版本的副本。
    • efibootmgr -v的输出显示/efi/ubuntu/shimx64.efi已注册为ubuntu 。 (这些新引导条目通常以最高优先级添加。另请参阅使用efibootmgr更改引导顺序 )
    • 重新启动后,未显示操作系统选择菜单(GRUB),并且计算机直接启动到Windows。
  • 访问固件设置菜单 (以前称为BIOS)时:
    • 没有任何迹象表明如何更改个别操作系统的引导顺序,或者没有任何操作系统(如Windows Boot Manager )显示在所有设备上。
    • 安全启动function在固件设置中关闭。
  • 通过在UEFI模式下启动实时媒体来安装Ubuntu, 而不是在Windows中运行WUBI -Installer。
  • Windows安装本身未被修改,替换或删除。
    • 该驱动器包含GPT分区表。
    • Windows磁盘管理显示磁盘上至少存在以下3个分区:
      • EFI系统分区
      • Windows分区
      • 一个不可读的RAW分区,可能是Ubuntu安装
  • 您尝试在(!)备份之前完全删除\EFI\BOOT\目录。

这通常表示默认引导加载程序或引导进程在某种程度上被硬编码为启动Windows时出现问题。 在大多数情况下,可以通过将\EFI\BOOT\BOOTx64.EFI为另一个允许引导其他操作系统的文件来轻松修复此问题。

简短的回答

您可以使用grub-mkimage在Ubuntu实时媒体中创建bootx64.efi二进制文件,并编写一个自定义的grub.cfg来链接您要启动的加载器并将这两个文件复制到EFI系统分区(ESP)到目录中\EFI\BOOT\

如果您在终端中不知道自己的方式,本答案的以下部分中提供的脚本将为您完成此操作。 有关详细信息,请参阅 较长答案中的技术详细信息部分。

脚本为方便起见

关于这个脚本:

  • 请注意 ,此脚本会安装运行它的grub-efi-amd64程序包,因此会破坏旧版MBR安装 。 如果可能的话,可能只从现场媒体运行它。
  • 您最好已经知道ESP的设备名称。
  • 您只需将下面的代码粘贴到一个打开的终端Ctrl + Alt + t并运行它Enter
  • 您可以使用Crtl + c取消终端中的脚本和程序。
  • 驱动器上已启动实时媒体的文件可通过/isodevice访问。 GUI:Nautilus / File Manager中的计算机 ➜isodevice
 echo -en "\ec"; \ if [ -e "/boot/efi/EFI" ] && [ $(mount | grep -c "/boot/efi type vfat") -gt 0 ]; then \ esp=$(mount | grep "/boot/efi type vfat" | sed -e 's/ on.*//'); \ echo "The following device appears to be mounted as an EFI System Partition: $esp"; \ read -p "Is that correct \"yes\" or \"no\"? Note, that answering \"no\" will unmount $esp! " correctesp; \ if [ "$correctesp" == "no" ]; then \ sudo umount "$esp"; \ elif [ "x$correctesp" != "xyes" ]; then \ echo "Invalid input, refusing to do anything."; \ fi; \ fi; \ if ! [ -e "/boot/efi/EFI" ] && ! [ $(mount | grep -c "/boot/efi type vfat") -gt 0 ]; then \ echo "Possible EFI System Partitions (ESP) found, but none appear to be mounted:"; \ sudo blkid -t TYPE="vfat"; \ read -p "Please enter the device name of your ESP (/dev/sd[az][1-9]): " esp; \ sudo mkdir -p "/boot/efi"; \ if [ "$(echo $esp | cut -c 1-5)" == "/dev/" ]; then \ sudo mount "$esp" "/boot/efi"; \ else \ echo "Invalid input, refusing to do anything."; \ fi; \ sudo mkdir -p "/boot/efi/EFI"; \ correctesp="yes"; \ fi; \ if [ -e "/boot/efi/EFI" ] && [ $(mount | grep -c "/boot/efi type vfat") -gt 0 ] && [ "$correctesp" == "yes" ]; then \ project="$HOME/uefi-bootfix"; \ mkdir -p "$project"; \ echo "--- Begin installing grub-efi-amd64 package (could throw some dpkg errors) ---"; \ sudo apt-get install -y grub-efi-amd64; \ echo "--- End of installing grub-efi-amd64 ---"; \ echo "--- Installing GRUB EFI image and configuration to ESP ---"; \ grub-mkimage -o "$project/bootx64.efi" -p "/efi/boot" -O x86_64-efi fat iso9660 part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop efi_uga ls search search_label search_fs_uuid search_fs_file exfat ext2 ntfs btrfs hfsplus udf; \ echo -e "set timeout=3\nmenuentry 'Ubuntu' {\n\tchainloader /efi/ubuntu/grubx64.efi\n}\nmenuentry 'Windows' {\n\tchainloader /efi/Microsoft/Boot/bootmgfw.efi\n}\nmenuentry 'Firmware Setup' {\n\tfwsetup\n}\nmenuentry 'ubuntu-14.04.1-desktop-amd64.iso' {\n\tset isofile="/efi/boot/ubuntu-14.04.1-desktop-amd64.iso"\n\tloopback loop $isofile\n\tlinux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noprompt noeject quiet splash\n\tinitrd (loop)/casper/initrd.lz\n}" > "$project/grub.cfg"; \ sudo mkdir -p "/boot/efi/EFI/boot"; \ if [ -e "/boot/efi/EFI/boot/bootx64.efi" ]; then \ sudo cp -v "/boot/efi/EFI/boot/bootx64.efi" "/boot/efi/EFI/boot/bootx64_uefi-bootfix-backup-$(date +%F_%H-%M-%S).efi"; \ fi; \ sudo cp -v "$project/bootx64.efi" "/boot/efi/EFI/boot/bootx64.efi"; \ sudo cp -v "$project/grub.cfg" "/boot/efi/EFI/boot/grub.cfg"; \ echo "--- Done. ---"; \ fi 

答案越长

问题

UEFI规范建议固件实现者通过名为\EFI\BOOT\BOOT{arch}.EFI默认引导加载程序引导,以便从外部介质引导,例如,依赖平台中的NVRAM条目 – 计算机的主板 – 来引导特定的操作系统是不可能的。 目前为arch定义的值为AMD64的x64 ,i386的ia32ARMA64

Windows和Fedora在ESP上安装了这样的引导加载程序,而Ubuntu目前却没有。 某些计算机中的固件(如预算价格的笔记本电脑)显示出这样的行为:这些设备似乎完全忽略了NVRAM bootcatalog中正确注册的UEFI引导加载程序,并默认从\EFI\BOOT\BOOT{arch}.EFI ,这通常会导致Windows而不是Ubuntu启动。

技术细节

此配置目前不支持安全启动,也没有针对Apple计算机进行测试,因为我没有这样的计算机。 (非常感谢帮助。)

如果直到现在还不清楚:这也将允许在另一台支持UEFI的计算机上启动磁盘上的操作系统安装,类似于传统MBR的方式。

使用GRUB生成bootx64.efi映像

 grub-mkimage -o bootx64.efi -p /efi/boot -O x86_64-efi fat iso9660 part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop efi_uga ls search search_label search_fs_uuid search_fs_file exfat ext2 ntfs btrfs hfsplus udf 

创建相应的grub.cfg文件

此配置涵盖了引导Ubuntu,启动Windows和启动固件设置的基本情况。 最后一个条目允许循环安装和启动ISO映像,这可能看起来很奇怪,因为ESP通常只有几百兆字节,并且不能存储这么大的文件,但这两个文件也适用于FAT格式的USB驱动器。 具有多个ISO的多重启动USB驱动器只需几个编辑。 您也可以轻松地用fedora替换ubuntu以创建另一个启动Fedora或任何其他Linux发行版的菜单项,只需查看ESP的内容即可。

 set timeout=3 menuentry 'Ubuntu' { chainloader /efi/ubuntu/grubx64.efi } menuentry 'Windows' { chainloader /efi/Microsoft/Boot/bootmgfw.efi } menuentry 'Firmware Setup' { fwsetup } menuentry 'ubuntu-14.04.1-desktop-amd64.iso' { set isofile="/efi/boot/ubuntu-14.04.1-desktop-amd64.iso" loopback loop $isofile linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noprompt noeject quiet splash initrd (loop)/casper/initrd.lz } 

附录

gummiboot和PreLoader怎么样?

我过去发过类似的东西,据我所知,这没有什么不妥。 它甚至可以与Secure Boot配合使用。 如果它对您有用,那么很好,但是手动下载,创建和提取多个文件的用户体验并不是最佳的,对普通用户来说相当困难。

示例输出

从实时媒体运行脚本的示例输出:

 Possible EFI System Partitions (ESP) found, but none appear to be mounted: /dev/sda1: LABEL="ESP W8" UUID="8AEF-2F66" TYPE="vfat" /dev/sdb1: LABEL="ESP HDD" UUID="CBB5-B769" TYPE="vfat" /dev/sdc1: LABEL="ESP EVO" UUID="288D-5954" TYPE="vfat" /dev/sdd1: LABEL="SANDISK" UUID="B67A-5BFF" TYPE="vfat" Please enter the device name of your ESP (/dev/sd[az][1-9]): /dev/sdb1 --- Begin installing grub-efi-amd64 package (could throw some dpkg errors) --- Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: efibootmgr grub-efi-amd64-bin The following packages will be REMOVED: grub-gfxpayload-lists grub-pc The following NEW packages will be installed: efibootmgr grub-efi-amd64 grub-efi-amd64-bin 0 upgraded, 3 newly installed, 2 to remove and 0 not upgraded. Need to get 0 B/722 kB of archives. After this operation, 2,399 kB of additional disk space will be used. Preconfiguring packages ... (Reading database ... 169555 files and directories currently installed.) Removing grub-gfxpayload-lists (0.6) ... Removing grub-pc (2.02~beta2-9ubuntu1) ... Processing triggers for man-db (2.6.7.1-1) ... Selecting previously unselected package efibootmgr. (Reading database ... 169536 files and directories currently installed.) Preparing to unpack .../efibootmgr_0.5.4-7ubuntu1_amd64.deb ... Unpacking efibootmgr (0.5.4-7ubuntu1) ... Selecting previously unselected package grub-efi-amd64-bin. Preparing to unpack .../grub-efi-amd64-bin_2.02~beta2-9ubuntu1_amd64.deb ... Unpacking grub-efi-amd64-bin (2.02~beta2-9ubuntu1) ... Selecting previously unselected package grub-efi-amd64. Preparing to unpack .../grub-efi-amd64_2.02~beta2-9ubuntu1_amd64.deb ... Unpacking grub-efi-amd64 (2.02~beta2-9ubuntu1) ... Processing triggers for man-db (2.6.7.1-1) ... Setting up efibootmgr (0.5.4-7ubuntu1) ... Setting up grub-efi-amd64-bin (2.02~beta2-9ubuntu1) ... Setting up grub-efi-amd64 (2.02~beta2-9ubuntu1) ... Installing for x86_64-efi platform. grub-install: error: failed to get canonical path of `/cow'. dpkg: error processing package grub-efi-amd64 (--configure): subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: grub-efi-amd64 E: Sub-process /usr/bin/dpkg returned an error code (1) --- End of installing grub-efi-amd64 --- --- Installing GRUB EFI image and configuration to ESP --- '/boot/efi/EFI/boot/bootx64.efi' -> '/boot/efi/EFI/boot/bootx64_uefi-bootfix-backup-2014-11-13_22-39-42.efi' '/home/ubuntu/uefi-bootfix/bootx64.efi' -> '/boot/efi/EFI/boot/bootx64.efi' '/home/ubuntu/uefi-bootfix/grub.cfg' -> '/boot/efi/EFI/boot/grub.cfg' --- Done. --- 

efibootmgr -v的输出显示/efi/ubuntu/shimx64.efi已注册为ubuntu。 (这些新引导条目通常以最高优先级添加。)

如果订单正确,efibootmgr的输出将有助于确定。

因此,根据我的理解,这是一个改变引导顺序的问题,因此grub的条目是默认的。 我也有这个问题。

由于无法启动到ubuntu来解决这个问题或者在UEFI / BIOS中执行此操作,您可以启动Ubuntu的LiveCD,然后放入终端或控制台

你打开一个终端并运行

 # sudo -i # apt-get install efibootmgr # efibootmgr BootCurrent: 0003 Timeout: 0 seconds BootOrder: 0003,0002,0004,2001 Boot0000* UEFI Onboard LAN IPv6 Boot0001* UEFI Onboard LAN IPv4 Boot0002* ubuntu Boot0003* Windows Boot Manager Boot0004* Ubuntu Boot2001* EFI USB Device 

并且您更改了引导条目的顺序

 # efibootmgr -o 0002,0003,0004,2001 

并再次运行efibootmgr来检查更改是否有效。 它应该改变bootnext值,否则你可以运行

 # efibootmgr -n 0002