18.04.5 -> 20.04.1:grub2 配置失败

18.04.5 -> 20.04.1:grub2 配置失败

在 LTS 升级期间,我收到有关 grub2 配置的错误消息,并且升级过程停止。

重新配置重现了错误:

Setting up grub-pc (2.04-1ubuntu26.4) ...
dpkg: error processing package grub-pc (--configure):
 installed grub-pc package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 grub-pc

调试配置脚本后发现错误发生在 /var/lib/dpkg/info/grub-pc.postinst, 第 688 行:

671             if [ -z "$RET" ]; then
672               # Reset the seen flag if the current answer is false, since
673               # otherwise we'll loop with no indication of why.
674               db_get grub-pc/install_devices_empty
675               if [ "$RET" = false ]; then
676                 db_fset grub-pc/install_devices_empty seen false
677               fi
678               if db_input critical grub-pc/install_devices_empty; then
679                 db_go
680                 db_get grub-pc/install_devices_empty
681                 if [ "$RET" = true ]; then
682                   break
683                 else
684                   db_fset "$question" seen false
685                   db_fset grub-pc/install_devices_empty seen false
686                 fi
687               else
688                 exit 1 # noninteractive
689               fi

从脚本代码来看,我猜 grub 没有找到任何要安装的设备。为什么会这样?如何避免这种情况?

答案1

我遇到了同样的问题,至少对我来说,我似乎已经解决了它。

该问题似乎是由于我多年前更换硬盘引起的。

因此,/var/cache/debconf/config.dat 中的 grub-pc/install_devices 条目无效或丢失,所以 grub-pc.postinst 尝试请求它。

不幸的是,grub-pc.postinst 以非交互模式运行;这可能是主要问题。

实际上,我使用 grub-pc.postinst 的临时补丁解决了这个问题,只需将 grub-pc/install_devices 变量设置为我的新硬盘驱动器 ID 即可。但直接编辑 /var/cache/debconf/config.dat 可能就足够了。 当然,这不是一个通用的解决方案,因为我对设备 ID 进行了硬编码。

我的补丁:

--- grub-pc.postinst    2020-10-11 12:50:47.288340305 +0200
+++ /tmp/grub-pc.postinst   2020-10-11 12:47:05.433847886 +0200
@@ -549,6 +549,7 @@
           priority=high
           device_map="$(grub-mkdevicemap -m - | grep -v '^(fd[0-9]\+)' || true)"
           devices="$(echo "$device_map" | cut -f2)"
+          db_set grub-pc/install_devices "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X"
           db_get grub-pc/install_devices
           valid=1
           for device in $RET; do

提取结果 /var/cache/debconf/config.dat:

Name: grub-pc/install_devices
Template: grub-pc/install_devices
Value: /dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X
Owners: grub-pc
Flags: seen
Variables:
 CHOICES = /dev/sda (1000204 MB; Samsung_SSD_850_EVO_mSATA_1TB), - /dev/sda5 (2999 MB; /)
 RAW_CHOICES = /dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X, /dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X-part5

Name: grub-pc/install_devices_disks_changed
Template: grub-pc/install_devices_disks_changed
Value: 
Owners: grub-pc
Flags: seen
Variables:
 CHOICES = /dev/sda (1000204 MB; Samsung_SSD_850_EVO_mSATA_1TB), - /dev/sda5 (2999 MB; /)
 RAW_CHOICES = /dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X, /dev/disk/by-id/ata-Samsung_SSD_850_EVO_mSATA_1TB_S246NWAG406372X-part5

答案2

手动重新配置 grub-pc 包将导致它再次显示可用驱动器列表(然后将 grub 安装到您选择的驱动器上,以及将选择保存到 debconf/config.dat 文件中):

$ sudo dpkg-reconfigure grub-pc
[... some other prompts go by ...]
The GRUB boot loader was previously installed to a disk that is no longer
present, or whose unique identifier has changed for some reason. It is important
to make sure that the installed GRUB core image stays in sync with GRUB modules
and grub.cfg. Please check again to make sure that GRUB is written to the
appropriate boot devices.

If you're unsure which drive is designated as boot drive by your BIOS, it is
often a good idea to install GRUB to all of them.

Note: it is possible to install GRUB to partition boot records as well, and some
appropriate partitions are offered here. However, this forces GRUB to use the
blocklist mechanism, which makes it less reliable, and therefore is not
recommended.
                                    <Ok>

             ---------------- Configuring grub-pc -----------------             
             | GRUB install devices:                              |             
             |                                                    |             
             |    [*] /dev/sda (80000 MB; WDC_WD800AAJS-75M0A0)   |             
             |    [*] /dev/sdb (81964 MB; Maxtor_6V080E0)         |             
             |    [ ] /dev/md0 (9999 MB; ???)                     |             
             |                                                    |             
             |                                                    |             
             |                       <Ok>                         |             
             |                                                    |             
             ------------------------------------------------------             

我通常使用这种方法在更换旧硬盘后立即在新硬盘上安装 grub,因为这可以确保在稍后升级 grub 包时将新驱动器包含在自动安装的引导扇区更新中。

相关内容