估计阅读时长: 8 分钟

为了能够稳定的使用Ubuntu系统作为我的测试环境,我专门安装了Ubuntu的2404 LTS版本。但是发现虽然是LTS版本,仍然会因为系统更新而出现各种莫名奇妙的BUG。例如,在今天我为了安装软件,使用apt upgrade更新系统环境之后,出现了下面的消息:

Setting up grub-efi-amd64 (2.12-1ubuntu7.3) ...
mount: /var/lib/grub/esp: special device /dev/disk/by-id/nvme-nvme.15ad-564d57617265204e564d455f30303030-564d77617265205669727475616c204e564d65204469736b-00000001-part1 does not exist.
       dmesg(1) may have more information after failed mount system call.
Failed: grub-install --target=x86_64-efi  
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-6.8.0-060800-generic
Found initrd image: /boot/initrd.img-6.8.0-060800-generic
Found memtest86+ 64bit EFI image: /boot/memtest86+x64.efi
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
Setting up update-manager-core (1:24.04.12) ...
Setting up grub-efi-amd64-signed (1.202.5+2.12-1ubuntu7.3) ...
mount: /var/lib/grub/esp: special device /dev/disk/by-id/nvme-nvme.15ad-564d57617265204e564d455f30303030-564d77617265205669727475616c204e564d65204469736b-00000001-part1 does not exist.
       dmesg(1) may have more information after failed mount system call.
dpkg: error processing package grub-efi-amd64-signed (--configure):
 installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 32

大致的意思就是,因为找不到分区设备,所以没有正常的安装grub-efi-amd64,系统在关机或者重启后可能无法被启动。这个消息可吓到我了,我还指望着使用这台Linux服务器跑业务呢,要是不小心断电关机就无法重新启动进入系统,就麻烦了。通过在网上搜索上面的错误消息,找到了一个和我一模一样错误的stackoverflow页面:Error upgrading grub-efi-amd64-signed - special device [old SSD] does not exist。在上面说的一个大致的解决方案是将efi分区打上esp标记。然而这个方案需要使用GParted GUI来完成,例如可以按照下面截图的操作步骤来简单的完成这个操作:

但是不幸的是,我的服务器上并没有安装有这个软件。通过应用商店进行安装,提示因为有未解决的依赖问题无法安装新的软件

在命令行终端上使用apt安装也提示错误信息:

Setting up grub-efi-amd64-signed (1.202.5+2.12-1ubuntu7.3) ...
mount: /var/lib/grub/esp: special device /dev/disk/by-id/nvme-nvme.15ad-564d57617265204e564d455f30303030-564d77617265205669727475616c204e564d65204469736b-00000001-part1 does not exist.
       dmesg(1) may have more information after failed mount system call.
dpkg: error processing package grub-efi-amd64-signed (--configure):
 installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 32
dpkg: dependency problems prevent processing triggers for shim-signed:
 shim-signed depends on grub-efi-amd64-signed (>= 1.191~) | grub-efi-arm64-signed (>= 1.191~) | base-files (<< 12.3); however:
  Package grub-efi-amd64-signed is not configured yet.
  Package grub-efi-arm64-signed is not installed.
  Version of base-files on system is 13ubuntu10.2.
 shim-signed depends on grub-efi-amd64-signed (>= 1.187.2~) | grub-efi-arm64-signed (>= 1.187.2~); however:
  Package grub-efi-amd64-signed is not configured yet.
  Package grub-efi-arm64-signed is not installed.

dpkg: error processing package shim-signed (--configure):
 dependency problems - leaving triggers unprocessed
Errors were encountered while processing:
 grub-efi-amd64-signed
 shim-signed
E: Sub-process /usr/bin/dpkg returned an error code (1)

似乎陷入了一个死循环了:需要安装GParted GUI来解决grub-efi-amd64的安装问题,但是grub-efi-amd64的安装失败阻止了GParted GUI的安装。只能够放弃了么?不过还好还可以通过命令行来做对应的分区标记,上面的问题主要是因为grub配置文件中没有相关的信息导致的。所以我们只需要修改好我们的grub配置文件就可以了。下面是对应的问题解决步骤:

在 Ubuntu 上,要将 /boot/efi 标记为 ESP(EFI System Partition),我们需要在 GRUB 配置中指定这一设置。首先我们需要先确认efi分区的设备路径,可以通过df -h /boot/efi来完成,例如:

可以看得到,在我的服务器上的设备为/dev/nvme0n1p1。那现在记下这个路径,现在开始编辑grub的配置文件。通过cat /etc/default/grub发现配置文件中并没有GRUB_EFI_PARTITION的信息,所以我们现在可以通过vim工具来编辑一下这个配置文件,在文件的最末尾添加上:

GRUB_EFI_PARTITION="/dev/nvme0n1p1"

然后wq保存一下。接着sudo update-grub,进行更新:

输出了上面的信息,说明 update-grub 命令成功执行,并生成了 GRUB 引导配置文件。

  • Sourcing file '/etc/default/grub':这是 GRUB 配置文件的位置。GRUB 从该文件中读取默认设置,例如启动超时、默认启动项等。
  • Generating grub configuration file ...:GRUB 正在根据系统状态和配置文件生成最终的启动配置文件。
  • Found linux image: /boot/vmlinuz-6.8.0-060800-generic:GRUB 发现了 Linux 内核镜像文件,这是 Ubuntu 系统启动所需的内核文件。
  • Found initrd image: /boot/initrd.img-6.8.0-060800-generic:GRUB 发现了初始 RAM 磁盘镜像文件,这是启动过程中用于加载驱动和初始化设备的临时文件系统。
  • Found memtest86+ 64bit EFI image: /boot/memtest86+x64.efi:GRUB 发现了 Memtest86+ 内存测试工具的 EFI 镜像文件。
  • Warning: os-prober will not be executed to detect other bootable partitions. Systems on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry.:这是一个警告信息,表示 GRUB 不会检测其他可启动的操作系统(如 Windows)。如果你希望 GRUB 自动检测其他操作系统,可以检查并修改 GRUB_DISABLE_OS_PROBER 参数。
  • Adding boot menu entry for UEFI Firmware Settings ...:GRUB 正在添加一个启动菜单项,用于进入 UEFI 固件设置界面。
  • done:表示 GRUB 配置文件生成完成。

这些输出表明 GRUB 配置更新成功,系统可以正常启动了。赶紧保存一下服务器上的东西,然后reboot一下。问题解决。

重启服务器后已经可以正常的安装上grub-efi-amd64这个东西了。

谢桂纲
Latest posts by 谢桂纲 (see all)

Attachments

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *

博客文章
June 2025
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930  
  1. […] 在上面的工具调用消息数据结构中,我们可以清楚的看见有需要进行调用的工具名称,以及参数列表。当我们拿到这样子的调用信息后,就可以基于一定的规则找到需要执行的运行时中的函数来完成功能的实现。对于.NET平台上,我们一般是使用自定义属性加反射操作来解析相关的名称绑定结果。在.NET平台上对于这样子的一个根据调用信息来进行运行时解析和调用的方法,可以稍微参考《【Darwinism】Linux平台上的VisualBasic高性能并行计算应用的开发》的反射代码方法。 […]