Linux 引导修复,重建 EFI 分区引导并安装 GRUB 引导程序
在 Linux 系统中,如果遇到 EFI 分区损坏或丢失的情况,可能会导致系统无法启动。本文将通过一步一步的操作,教你如何手动重建 EFI 分区并安装 GRUB 引导程序。这个过程适用于 Ubuntu 等常见的 Linux 发行版。
前提条件:
- 确保你具有 root 权限或能够使用
sudo
。 - 准备好 EFI 分区设备(例如
/dev/nvme1n1p1
和/dev/nvme1n1p3
)。
操作步骤:
- 挂载分区
首先挂载你的主分区以及 EFI 分区。你需要确保能够访问系统文件及 EFI 引导分区。
复制
展开
sudo mount /dev/nvme1n1p1 /mnt
sudo mount /dev/nvme1n1p3 /mnt/boot/efi
- 挂载必需的系统目录
挂载 /dev
, /proc
, /sys
等目录,以便你能够使用一些系统工具如 chroot
。
复制
展开
sudo mkdir -p /mnt/boot/efi
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /run /mnt/run
- 切换到
chroot
环境
使用 chroot
命令切换到已挂载的根文件系统环境,这样你可以直接操作系统,而不需要重新启动。
复制
展开
sudo chroot .
- 安装 GRUB 引导程序
在 chroot
环境中,执行 grub-install
命令来安装 GRUB 引导程序。
复制
展开
grub-install /boot/efi/
如果提示警告,“EFI variables cannot be set on this system”,请继续执行后续操作,手动完成 GRUB 配置。
- 更新 GRUB 配置文件
使用 update-grub
命令更新 GRUB 配置文件,确保引导项正确添加。
复制
展开
update-grub
你会看到以下输出:
复制
展开
Sourcing file `/etc/default/grub`
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/Huohuo/theme.txt
Found linux image: /boot/vmlinuz-6.14.0-29-generic
Found initrd image: /boot/initrd.img-6.14.0-29-generic
Found memtest86+ 64bit EFI image: /boot/memtest86+x64.efi
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
done
- 完成操作并重启
完成后,退出 chroot
环境并重新启动系统:
复制
展开
exit
sudo reboot
小结:
通过上述步骤,你已经成功地重建了 EFI 分区引导,并安装了 GRUB 引导程序。系统应能够正常引导,GRUB 菜单中会显示所有可引导的操作系统。如果你在此过程中遇到任何问题,可以参考 GRUB 官方文档或进行进一步的故障排除。
详细完整过程
复制
展开
ubuntu@ubuntu:~$ sudo mount /dev/nvme1n1p1 /mnt
ubuntu@ubuntu:~$ cd /mnt/
ubuntu@ubuntu:/mnt$
ubuntu@ubuntu:/mnt$ sudo mkdir -p /mnt/boot/efi
ubuntu@ubuntu:/mnt$ sudo mount /dev/nvme1n1p3 /mnt/boot/efi
ubuntu@ubuntu:/mnt$ sudo mount --bind /dev /mnt/dev
ubuntu@ubuntu:/mnt$ sudo mount --bind /dev/pts /mnt/dev/pts
ubuntu@ubuntu:/mnt$ sudo mount --bind /proc /mnt/proc
ubuntu@ubuntu:/mnt$ sudo mount --bind /sys /mnt/sys
ubuntu@ubuntu:/mnt$ sudo mount --bind /run /mnt/run
ubuntu@ubuntu:/mnt$ sudo chroot .
root@ubuntu:/# grub-install /boot/efi/
Installing for x86_64-efi platform.
grub-install: warning: EFI variables cannot be set on this system.
grub-install: warning: You will have to complete the GRUB setup manually.
Installation finished. No error reported.
root@ubuntu:/# update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/Huohuo/theme.txt
Found linux image: /boot/vmlinuz-6.14.0-29-generic
Found initrd image: /boot/initrd.img-6.14.0-29-generic
Found memtest86+ 64bit EFI image: /boot/memtest86+x64.efi
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.\
Adding boot menu entry for UEFI Firmware Settings ...
done
作者:https://blog.xn--rpv331d.com/我不道啊
链接:https://blog.xn--rpv331d.com/我不道啊/blog/107
转载注意保留文章出处...
No data