栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Ubuntu Boot Failed

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ubuntu Boot Failed

apt upgrade后,再启动电脑变无法进入grub,记录一些遇到的问题

背景

两个硬盘 root:sdb5 boot:sdb6 efi:sda2
双系统 win8.1 + ubuntu18.06,UEFI启动

安装grub

按照这篇博文的排查流程https://www.howtogeek.com/196740/how-to-fix-an-ubuntu-system-when-it-wont-boot/ 能否进入GRUB boot loader,我的不能便按照第二个文章进行GRUB安装。因为电脑直接显示Ubuntu Boot Failed [OK]然后直接进入Windows系统,没有进入紫色界面。
第二篇文章https://www.howtogeek.com/114884/how-to-repair-grub2-when-ubuntu-wont-boot/ 可使用boot-repair这个工具进行修复,或者使用命令行安装grub,这两个我都试了:

boot-repair
sudo apt-add-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install -y boot-repair
boot-repair

启动后直接点点就行,但是我在粘贴它提示的命令后,即卸载旧grub,但是它仍然提示旧grub2未卸载,提示说新开个terminal输入命令就行我估计是卸载了PE的grub,但是我也把挂载的boot中的grub重命名了,仍然未成功,此路终结。

命令行

把那三个分区全部按序挂载,然后输入文章的命令:
sudo grub-install --boot-directory=/mnt/ubuntu/boot /dev/sdX我的系统在第二个磁盘即sdb,输入sda执行会提示跨硬盘安装
但是又报错:

root@ubuntu:/mnt/ubuntu/boot# sudo grub-install --boot-directory=/mnt/ubuntu/boot /dev/sdb
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won’t be possible.
grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged…
grub-install: error: will not proceed with blocklists.
root@ubuntu:/mnt/ubuntu/boot# sudo grub-install --boot-directory=/mnt/ubuntu/boot /dev/sda
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won’t be possible.
grub-install: error: embedding is not possible, but this is required for cross-disk install.

上面说说GPT分区标签没有BIOS Boot 分区,什么意思呢?搜索一番都说是要开辟一个新分区,并给打上标记(bios_grub);
但是这个回答解释了更清楚,不是无脑创建分区:https://superuser.com/questions/903112/grub2-install-this-gpt-partition-label-contains-no-bios-boot-partition 【建议精读】

To install GRUB, you should first be sure that you’ve installed the correct GRUB package. I’m not sure of naming in all distributions, but in Ubuntu, it would be grub-pc for BIOS/CSM/legacy mode and grub-efi-amd64 for EFI/UEFI mode. An EFI-mode installation will also require booting whatever you’re using to install GRUB (a live CD/USB, presumably) in EFI mode. Doing this may require using your computer’s built-in boot manager, which is typically accessed via a function key, but the details vary from one computer to another.

说得很清楚,BIOS启动或lagacy用grub-pc,需要额外的分区;EFI/UEFI用 grub-efi-amd64,并且需要电脑内建的启动管理器,GRUB2 并不需要额外的分区,我再次核实了我是用UEFI启动,所以我不需要创建分区。
回过头来看,i386-pc一般指32位,GRUB中给BIOS使用,而x86_64-efi是64位,GURB中给UEFI使用,https://unix.stackexchange.com/questions/524622/what-is-the-relation-between-uefi-and-grub 和上面那个回答的引用对应:grub-pc for BIOS and grub-efi for EFI/UEFI
grub-install默认安装的是i386-pc

–target=TARGET
install GRUB for TARGET platform [default=i386-pc]; available targets: arm-efi, arm-uboot, arm64-efi, i386-coreboot, i386-efi,
i386-ieee1275, i386-multiboot, i386-pc, i386-qemu, i386-xen, ia64-efi, mips-arc, mips-qemu_mips, mipsel-arc, mipsel-loongson,
mipsel-qemu_mips, powerpc-ieee1275, sparc64-ieee1275, x86_64-efi, x86_64-xen

但是我指定--target=x86_64-efi又说不存在/usr/lib/grub/x86_64-efi/modinfo.sh USE的PE文件系统里确实没有这个,只有i386-pc,那怎么得来x86_64-efi呢? apt即可获得,同样有

root@ubuntu:~# apt search grub | grep bin

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

grub-coreboot-bin/bionic-security,bionic-updates 2.02-2ubuntu8.23 amd64
GRand Unified Bootloader, version 2 (Coreboot binaries)
grub-efi-amd64-bin/xenial-updates,bionic-security,bionic-updates,now 2.04-1ubuntu44.1.2 amd64 [installed,automatic]
grub-efi-ia32-bin/bionic-security,bionic-updates 2.02-2ubuntu8.23 amd64
GRand Unified Bootloader, version 2 (EFI-IA32 binaries)
grub-ieee1275-bin/bionic-security,bionic-updates 2.02-2ubuntu8.23 amd64
GRand Unified Bootloader, version 2 (Open Firmware binaries)
grub-pc-bin/bionic-security,bionic-updates 2.02-2ubuntu8.23 amd64
GRand Unified Bootloader, version 2 (PC/BIOS binaries)
grub-xen-bin/bionic-security,bionic-updates 2.02-2ubuntu8.23 amd64
GRand Unified Bootloader, version 2 (Xen binaries)

可以看到有grub-efi-amd64-bin,也有 grub-pc-bin,grub-install手册的–target描述的就是这些

mkdir grub-efi-amd64-bin
apt download grub-efi-amd64-bin    # 得grub-efi-amd64-bin_2.04-1ubuntu44.1.2_amd64.deb
dpkg-deb -R grub-efi-amd64-bin_2.04-1ubuntu44.1.2_amd64.deb grub-efi-amd64-bin

这样就得到了x86_64-efi文件夹,里面都是一些mod文件,复制至cp grub-efi-amd64-bin/usr/lib/grub/x86_64-efi/ usr/lib/grub/ -r于是再次安装
grub-install --target=x86_64-efi --boot-directory=/mnt/ubuntu/boot --boot-directory=/mnt/ubuntu/boot/efi(注意我前面说了我root、boot、esp在不同的分区,已经提前按序挂载好),但是又提示说/mnt/ubuntu/boot/efi/EFI/xxx无法写入,尝试往这个分区写文件,只有很小的配置文件才能写入,efi文件(1.6M大)写不进去,所以命令安装也失败了

老工具Boot-Repair镜像

Boot-Repair是个万能工具,但是我没卸载旧的grub成功,打算重新安装操作系统,旧的文件全会被清理掉(准备重新安装时我的前两种安装方式都是报红警告,即会清理用户文件,正常情况下只有第二个是红的,提示清理全盘文件。。。)
于是翻到之前DiskGenuine制作的另一个BootRepair备份镜像,老外把BootRepair专门做了个ISO便于启动恢复,就不用在PE上再安装BootRepair了,我之前做过并且备份了U盘镜像,最后一搏,U盘复制这个备份镜像进行恢复,叮,重新安装GRUB成功。
镜像地址:https://sourceforge.net/projects/boot-repair-cd/files/
以后得记得用这个了。

编辑GRUB启动列表

重新配置好后,reboot多次分别进入Ubuntu和windows,表现正常,但是grub启动列表中有多个EFI,如何去除不需要的?https://askubuntu.com/questions/823514/remove-useless-entries-from-messed-up-grub
grep -i EFI /etc/grub.d*.EFI */*.efi | sort 02b611e62d8a6ca3e730c468d88cf70f grub/shimx64.efi 4dc205f9b8b7c72708fb49706e2d83e9 grub/grubx64.efi 621356d82b109cd860ad92cdf241c58b Boot/BOOTX64.EFI # 重点 621356d82b109cd860ad92cdf241c58b ubuntu/grubx64.efi # 重点 958ceee3668f4eff01fb29d03518b49e Boot/bkpbootx64.efi d41d8cd98f00b204e9800998ecf8427e Boot/fbx64.efi # 空文件 d41d8cd98f00b204e9800998ecf8427e ubuntu/mmx64.efi d41d8cd98f00b204e9800998ecf8427e ubuntu/shimx64.efi # 安全启动时,用来启动GRUB

https://askubuntu.com/questions/342365/what-is-the-difference-between-grubx64-and-shimx64
虽然解决了问题,基本熟悉了一些概念,并未深入其中的概念与作用关系;计算机启动这一套流程不少,都已经是成文标准了。
基本达成目标,不重装系统。
元旦假,断断续续两天,干了个这。

正常时的快照 /boot/efi/EFI/grub.cfg

jimmy@ubuntu:/boot/efi/EFI$ cat grub/grub.cfg
search.fs_uuid fcbe35eb-89f4-4ac2-b799-5556e999d5ca root hd1,gpt6
set prefix=($root)’/grub’
configfile $prefix/grub.cfg

参考链接
  1. https://superuser.com/questions/1293793/grub-install-error-usr-lib-grub-i386-pc-modinfo-sh-doesnt-exist、
  2. https://superuser.com/questions/1293793/grub-install-error-usr-lib-grub-i386-pc-modinfo-sh-doesnt-exist
  3. https://www.howtogeek.com/114884/how-to-repair-grub2-when-ubuntu-wont-boot/
  4. https://askubuntu.com/questions/831216/how-can-i-reinstall-grub-to-the-efi-partition
  5. https://unix.stackexchange.com/questions/524622/what-is-the-relation-between-uefi-and-grub
  6. https://unix.stackexchange.com/questions/538562/how-do-i-edit-grub-cfg-and-save-it
  7. https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf 第5章介绍了GPT
  8. Boot-Repair镜像制作 https://sourceforge.net/projects/boot-repair-cd/files/
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693522.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号