之后sudo apt upgrade
,grub-install
失败了,所以我不得不在 Live Ubuntu 18.04 USB 上重新启动。
将、、、、、/proc
安装到之后,我chroot 到我的 ubuntu并重新运行:/dev
/dev/pts
/run
/sys
/sys/firmware/efi/efivars
/mnt/destinationVGDir/
/dev/sda
grub-install
ubuntu@ubuntu:~$ sudo chroot /mnt/destinationVGDir/
root@ubuntu:/# mount -a # Mounts all other filesystems including /boot/efi
root@ubuntu:/# grub-install
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 18151: grub-install
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 18151: grub-install
Could not prepare Boot variable: Invalid argument
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
如果执行grub-install -v
,则可以看到这efibootmgr
是这里失败的一个:
root@ubuntu:/# grub-install -v 2>&1 | uniq | tail
grub-install: info: copying `/usr/lib/shim/BOOTX64.CSV' -> `/boot/efi/EFI/ubuntu/BOOTX64.CSV'.
grub-install: info: copying `/boot/grub/x86_64-efi/load.cfg' -> `/boot/efi/EFI/ubuntu/grub.cfg'.
grub-install: info: copying `/usr/lib/shim/shimx64.efi.signed' -> `/boot/efi/EFI/Boot/bootx64.efi'.
grub-install: info: copying `/usr/lib/shim/fbx64.efi' -> `/boot/efi/EFI/Boot/fbx64.efi'.
grub-install: info: Registering with EFI: distributor = `ubuntu', path = `\EFI\ubuntu\shimx64.efi', ESP at hostdisk//dev/sda,gpt1.
grub-install: info: executing efibootmgr --version </dev/null >/dev/null.
grub-install: info: executing modprobe -q efivars.
grub-install: info: executing efibootmgr -c -d /dev/sda -p 1 -w -L ubuntu -l \EFI\ubuntu\shimx64.efi.
Could not prepare Boot variable: Invalid argument
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
root@ubuntu:/# efibootmgr -c -d /dev/sda -p 1 -w -L ubuntu -l \EFI\ubuntu\shimx64.efi
Could not prepare Boot variable: Invalid argument
root@ubuntu:/# efibootmgr -v -v -c -d /dev/sda -p 1 -w -L ubuntu -l \EFI\ubuntu\shimx64.efi
Could not prepare Boot variable: Invalid argument
error trace:
efivarfs.c:351 efivarfs_set_variable(): write failed: Invalid argument
lib.c:81 _efi_set_variable_mode(): ops->set_variable() failed: Invalid argument
efibootmgr.c:323 make_var(): efi_set_variable failed: Invalid argument
efibootmgr.c:333 make_var(): Could not set variable Boot0000: Invalid argument
root@ubuntu:/#
我的固态硬盘 (SSD) 很好:
ubuntu@ubuntu:~$ sudo smartctl -A /dev/sda
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-5.4.0-42-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 1947
12 Power_Cycle_Count 0x0032 099 099 000 Old_age Always - 673
177 Wear_Leveling_Count 0x0013 099 099 000 Pre-fail Always - 1
179 Used_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 0
181 Program_Fail_Cnt_Total 0x0032 100 100 010 Old_age Always - 0
182 Erase_Fail_Count_Total 0x0032 100 100 010 Old_age Always - 0
183 Runtime_Bad_Block 0x0013 100 100 010 Pre-fail Always - 0
187 Uncorrectable_Error_Cnt 0x0032 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0032 069 049 000 Old_age Always - 31
195 ECC_Error_Rate 0x001a 200 200 000 Old_age Always - 0
199 CRC_Error_Count 0x003e 100 100 000 Old_age Always - 0
235 POR_Recovery_Count 0x0012 099 099 000 Old_age Always - 30
241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 1179332232
EDIT0:这是我在 chroot 之前挂载的特殊文件系统:
root@ubuntu:/# mount | grep -v ext4
proc on /proc type proc (rw,relatime)
tmpfs on /run type tmpfs (rw,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=2947064k,nr_inodes=736766,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
/dev/sda1 on /boot/efi type vfat (rw,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
root@ubuntu:/#
--no-nvram
EDIT1:感谢@SamyAbdellatif,通过向命令添加选项不会出现此错误grub-install
:
root@ubuntu:~# grub-install --no-nvram
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 6065: grub-install
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 6065: grub-install
Installation finished. No error reported.
root@ubuntu:~#
现在,如果我重新安装grub-efi-amd64-signed
来模拟更新,则不会使用--no-nvram
选项grub-install
,并且 pb 会重新出现:
root@ubuntu:~# apt install --reinstall grub-efi-amd64-signed
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
grub-efi-amd64-signed
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/300 kB of archives.
After this operation, 3459 kB of additional disk space will be used.
Selecting previously unselected package grub-efi-amd64-signed.
(Reading database ... 475217 files and directories currently installed.)
Preparing to unpack .../grub-efi-amd64-signed_1.93.22+2.02-2ubuntu8.20_amd64.deb ...
Unpacking grub-efi-amd64-signed (1.93.22+2.02-2ubuntu8.20) ...
Setting up grub-efi-amd64-signed (1.93.22+2.02-2ubuntu8.20) ...
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 6191: grub-install
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 6191: grub-install
Could not prepare Boot variable: Invalid argument
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
dpkg: error processing package grub-efi-amd64-signed (--configure):
installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
grub-efi-amd64-signed
E: Sub-process /usr/bin/dpkg returned an error code (1)
编辑2:当我重新启动时,只有一个黑屏。使用 Live USB 重新检查后,我看不到 Ubuntu 的 EFI 启动项:
root@ubuntu:~# efibootmgr | grep -i ubuntu
root@ubuntu:~#
EDIT3:我删除了该grub-efi-amd64-signed
包,因为mokutil --sb-state
说This system doesn't support Secure Boot
并重新安装
grub-efi-amd64
:
root@ubuntu:~# apt install --reinstall -V grub-efi-amd64
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/47.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 475223 files and directories currently installed.)
Preparing to unpack .../grub-efi-amd64_2.02-2ubuntu8.20_amd64.deb ...
Unpacking grub-efi-amd64 (2.02-2ubuntu8.20) over (2.02-2ubuntu8.20) ...
Setting up grub-efi-amd64 (2.02-2ubuntu8.20) ...
Installing for x86_64-efi platform.
File descriptor 3 (pipe:[189443]) leaked on vgs invocation. Parent PID 16137: grub-
install
File descriptor 5 (/dev/sda1) leaked on vgs invocation. Parent PID 16137: grub-inst
all
File descriptor 3 (pipe:[189443]) leaked on vgs invocation. Parent PID 16137: grub-
install
File descriptor 5 (/dev/sda1) leaked on vgs invocation. Parent PID 16137: grub-inst
all
Could not prepare Boot variable: Invalid argument
grub-install: error: efibootmgr failed to register the boot entry: Input/output err
or.
Failed: grub-install --target=x86_64-efi --no-extra-removable
WARNING: Bootloader is not properly installed, system may not be bootable
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-42-generic
Found initrd image: /boot/initrd.img-5.4.0-42-generic
Found linux image: /boot/vmlinuz-4.15.0-128-generic
Found initrd image: /boot/initrd.img-4.15.0-128-generic
Found linux image: /boot/vmlinuz-4.15.0-122-generic
Found initrd image: /boot/initrd.img-4.15.0-122-generic
done
仍然有WARNING: Bootloader is not properly installed, system may not be bootable
错误因此我grub-install
使用以下--no-nvram
选项手动运行:
root@ubuntu:~# grub-install --no-nvram
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 20234: grub-install
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 20234: grub-install
Installation finished. No error reported
grub-install --no-nvram
没有报告错误但不会创建任何 ubuntu EFI 启动项:
root@ubuntu:~# efibootmgr | grep -i ubuntu
root@ubuntu:~#
EDIT3.1:grub-install --removable
没有报告错误,但也没有创建任何 ubuntu EFI 启动项。
EDIT4:我的/etc/fstab
:
root@ubuntu:~# grep -v ^# /etc/fstab
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/rootFS / ext4 errors=remount-ro 0 1
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/boot /boot ext4 defaults,noatime 0 2
UUID=9ADF-05E5 /boot/efi vfat defaults,noatime 0 1
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/home /home ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/opt /opt ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/tmp /tmp ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/usr /usr ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/usr_local /usr/local ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/var /var ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/var_cache /var/cache ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/var_lib_snapd /var/lib/snapd ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/var_mail /var/mail ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/var_tmp /var/tmp ext4 defaults,noatime 0 2
/dev/VG_ALL_Samsung_SSD_850_EVO_500GB/photos /photos ext4 defaults,noatime 0 2
root@ubuntu:~#
输出如下lsblk
:
root@ubuntu:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 2G 1 loop
loop1 7:1 0 29.9M 1 loop
loop2 7:2 0 55M 1 loop
loop3 7:3 0 255.6M 1 loop
loop4 7:4 0 62.1M 1 loop
loop5 7:5 0 49.8M 1 loop
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 256M 0 part /boot/efi
└─sda2 8:2 0 465.5G 0 part
├─VG_ALL_Samsung_SSD_850_EVO_500GB-boot 253:0 0 1G 0 lvm /boot
├─VG_ALL_Samsung_SSD_850_EVO_500GB-opt 253:1 0 7G 0 lvm /opt
├─VG_ALL_Samsung_SSD_850_EVO_500GB-rootFS 253:2 0 2G 0 lvm /
├─VG_ALL_Samsung_SSD_850_EVO_500GB-var_lib_snapd 253:3 0 10G 0 lvm /var/lib/snapd
├─VG_ALL_Samsung_SSD_850_EVO_500GB-tmp 253:4 0 10G 0 lvm /tmp
├─VG_ALL_Samsung_SSD_850_EVO_500GB-usr_local 253:5 0 7G 0 lvm /usr/local
├─VG_ALL_Samsung_SSD_850_EVO_500GB-usr 253:6 0 20G 0 lvm /usr
├─VG_ALL_Samsung_SSD_850_EVO_500GB-var_cache 253:7 0 5G 0 lvm /var/cache
├─VG_ALL_Samsung_SSD_850_EVO_500GB-var_mail 253:8 0 20G 0 lvm /var/mail
├─VG_ALL_Samsung_SSD_850_EVO_500GB-var_tmp 253:9 0 2G 0 lvm /var/tmp
├─VG_ALL_Samsung_SSD_850_EVO_500GB-var 253:10 0 6G 0 lvm /var
├─VG_ALL_Samsung_SSD_850_EVO_500GB-VMs 253:11 0 75.5G 0 lvm
├─VG_ALL_Samsung_SSD_850_EVO_500GB-.q 253:12 0 90G 0 lvm
├─VG_ALL_Samsung_SSD_850_EVO_500GB-home 253:13 0 100G 0 lvm /home
├─VG_ALL_Samsung_SSD_850_EVO_500GB-datas 253:14 0 60G 0 lvm
└─VG_ALL_Samsung_SSD_850_EVO_500GB-photos 253:15 0 50G 0 lvm
sdc 8:32 1 28.9G 0 disk
├─sdc1 8:33 1 28.9G 0 part
│ └─ventoy 253:16 0 2.6G 1 dm
└─sdc2 8:34 1 32M 0 part
sr0 11:0 1 1024M 0 rom
root@ubuntu:~#
要在我的系统上重新安装 grub,我是否需要使用较新的 grub2-common 包或较新的 efibootmgr 包?
答案1
确保以 UEFI 模式启动,并在 BIOS 中禁用安全启动
在挂载分区并将 chroot 到系统后尝试
grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi --no-nvram --removable