UEFI 机器不会通过 NVRAM 引导目录引导 Ubuntu。怎么修?

Liv*_*eBT 5 grub2 bash uefi windows-8

此处发布的答案应:

  • 避免要求用户下载和安装额外的软件包或 PPA。
  • 尽可能快速和简单。(我尝试过引导修复,但不符合条件。)
  • 可能为对终端没有太多经验的用户提供脚本。

类似的问题已多次发布到该网站:

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

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

Liv*_*eBT 5

简短的回答

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

如果您不知道在终端中的操作方式,本答案以下部分中可用的脚本将为您完成此操作。有关更多详细信息,请查看较长答案中的技术详细信息部分。

为了您的方便而编写脚本

关于这个脚本:

  • 请注意,此脚本会grub-efi-amd64在它运行的地方安装包,因此会破坏旧的 MBR 安装。如果可能,可能只从实时媒体运行它。
  • 最好您已经知道 ESP 的设备名称。
  • 你刚才下面的代码粘贴到一个开放的终端Ctrl+ Alt+t和运行它Enter
  • 您可以使用Crtl+取消终端中的脚本和程序c
  • 可通过/isodevice. 图形用户界面:计算机?Nautilus/文件管理器中的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[a-z][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
Run Code Online (Sandbox Code Playgroud)

更长的答案

问题

UEFI规范通过建议固件实施者开机默认引导命名\EFI\BOOT\BOOT{arch}.EFI从外部介质进行引导,比如在平台上NVRAM条目依托地方-电脑主板-启动一个特定的操作系统是不可能的。当前定义的值archx64针对AMD64,ia32i386和ARMA64用于ARM。

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

技术细节

这个配置目前不支持安全启动,也没有在苹果电脑上测试过,因为我没有这样的机器。(非常感谢帮助。)

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

bootx64.efi使用 GRUB生成图像

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
Run Code Online (Sandbox Code Playgroud)

创建相应的grub.cfg文件

此配置涵盖了启动 Ubuntu、启动 Windows 和启动固件设置的基本情况。最后一个条目允许循环挂载和启动 ISO 映像,起初这可能看起来很奇怪,因为 ESP 通常只有几百兆字节大并且无法存储如此大的文件,但是这两个文件也适用于 FAT 格式的 USB 驱动器。一个与多个ISO多重USB驱动器是短短的编辑了。此外,你可以很容易地更换ubuntufedora创建另一个菜单条目靴子的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
}
Run Code Online (Sandbox Code Playgroud)

附录

gummiboot 和 PreLoader 怎么样?

我已经发布了类似的东西在过去并没有什么错,只要我能看到。它甚至适用于安全启动。如果它对您有用,那很好,但是包括手动下载、创建和提取多个文件在内的用户体验并不是很理想,对于普通用户来说也相当困难。

示例输出

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

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[a-z][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. ---
Run Code Online (Sandbox Code Playgroud)