Grub 安装失败

Hun*_*son 15 boot debian grub2 uefi

我有一个很好的 Debian Jessie 安装运行,但后来我运行了apt-get update && apt-get upgrade && apt-get dist-upgrade.

然后重新启动后,它直接进入BIOS。我意识到 Grub 丢失了,所以我运行了一个 live cd 并输入了Rescue mode,挂载了我的根分区,+ 引导分区并运行了这些命令:

Grub 找到 linux 镜像:

root@debian:~# update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-0.bpo.3-amd64
Found initrd image: /boot/initrd.img-4.9.0-0.bpo.3-amd64
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
Found Ubuntu 16.10 (16.10) on /dev/sdb2
Adding boot menu entry for EFI firmware configuration
done
Run Code Online (Sandbox Code Playgroud)

然后grub-install

root@debian:~# grub-install /dev/sda
Installing for x86_64-efi platform.
Could not prepare Boot variable: No such file or directory
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
Run Code Online (Sandbox Code Playgroud)

lsblk

root@debian:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 223.6G  0 disk 
??sda1   8:1    0  92.6G  0 part /
??sda2   8:2    0 130.4G  0 part 
??sda3   8:3    0   573M  0 part /boot/efi
Run Code Online (Sandbox Code Playgroud)

我做错什么了吗?我的/boot/efi分区上的空间是否太小?

root@debian:~# ls -l /boot/efi/EFI/debian/
total 120
-rwx------ 1 root root 121856 Jul 20 20:29 grubx64.efi
Run Code Online (Sandbox Code Playgroud)

efibootmgr 不显示 Debian 安装:

root@debian:~# efibootmgr --verbose | grep debian
Run Code Online (Sandbox Code Playgroud)

编辑 :

每次尝试使用efibootmgr以下命令创建引导加载程序时,我都会收到此错误:

grub-install: info: executing efibootmgr -c -d /dev/sda -p 3 -w -L grub -l \EFI\grub\grubx64.efi.
Could not prepare Boot variable: No such file or directory
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
Run Code Online (Sandbox Code Playgroud)

Hun*_*son 40

通过安装引导变量来修复 efibootmgr 错误efibootmgr

# mount -t efivarfs efivarfs /sys/firmware/efi/efivars
Run Code Online (Sandbox Code Playgroud)

然后efibootmgr给了我关于空间的错误:

Could not prepare Boot variable: No space left on device
Run Code Online (Sandbox Code Playgroud)

通过删除转储文件修复了这个问题:

# rm /sys/firmware/efi/efivars/dump-*
Run Code Online (Sandbox Code Playgroud)

然后运行通常的

update-grub 
grub-install -v --target=x86_64-efi --recheck /dev/sda
Run Code Online (Sandbox Code Playgroud)

它运行成功!