Liv*_*eBT 5 grub2 bash uefi windows-8
此处发布的答案应:
- 避免要求用户下载和安装额外的软件包或 PPA。
- 尽可能快速和简单。(我尝试过引导修复,但不符合条件。)
- 可能为对终端没有太多经验的用户提供脚本。
类似的问题已多次发布到该网站:
efibootmgr -v
显示/efi/ubuntu/shimx64.efi
已注册为ubuntu
. (这些新的引导条目通常以最高优先级添加。另请参阅使用 efibootmgr 更改引导顺序)Windows Boot Manager
显示操作系统(如),只有设备。\EFI\BOOT\
在(!)备份之前完全删除目录。这通常表示默认引导加载程序或引导进程在某种程度上硬编码以引导 Windows 存在问题。在大多数情况下,这可以通过替换\EFI\BOOT\BOOTx64.EFI
为另一个允许启动其他操作系统的文件来轻松解决。
您可以bootx64.efi
使用grub-mkimage从 Ubuntu 实时媒体中创建一个二进制文件,并编写一个自定义grub.cfg
来链加载您不想启动的加载程序,并将两个文件复制到 EFI 系统分区 (ESP) 到目录中\EFI\BOOT\
。
如果您不知道在终端中的操作方式,本答案以下部分中可用的脚本将为您完成此操作。有关更多详细信息,请查看较长答案中的技术详细信息部分。
关于这个脚本:
grub-efi-amd64
在它运行的地方安装包,因此会破坏旧的 MBR 安装。如果可能,可能只从实时媒体运行它。/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条目依托地方-电脑主板-启动一个特定的操作系统是不可能的。当前定义的值arch
都x64
针对AMD64,ia32
i386和ARM
或A64
用于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驱动器是短短的编辑了。此外,你可以很容易地更换ubuntu
与fedora
创建另一个菜单条目靴子的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)
我已经发布了类似的东西在过去并没有什么错,只要我能看到。它甚至适用于安全启动。如果它对您有用,那很好,但是包括手动下载、创建和提取多个文件在内的用户体验并不是很理想,对于普通用户来说也相当困难。
从实时媒体运行脚本的示例输出:
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)