Bug#913928: grub-pc fails to install on the last of multiple devices

Richard Laager rlaager at wiktel.com
Sat Nov 17 06:04:40 GMT 2018


Package: grub-pc
Version: 2.02+dfsg1-8
Severity: important
Tags: patch

When installing grub-pc to multiple devices, it fails installing on the
last device. For the failing device, all of the errors show a stray
comma at the end of the device name.

This is occurring because install_devices is a multiselect, and the
results are separated by commas. There is a comma at the end too. This
ends up being interpreted as part of the device name. The package has
code to remove the commas in the middle, but it does not remove the
comma at the end.

To reproduce this after the first failure, I had to do this (where that
device is the _last_ device, on which the install is failing):
grub-install /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3 && DEBCONF_DEBUG=developer dpkg-reconfigure grub-pc

In the installed package's grub-pc.postinst, or the source package's
debian/postinst.in, this is the code in question (indentation reduced 8
spaces):
    failed_devices=
    for i in `echo $RET | sed -e 's/, / /g'` ; do
      real_device="$(readlink -f "$i")"
      if grub-install --target=i386-pc --force --no-floppy $real_device ; then
        # We just installed GRUB 2; then also generate grub.cfg.
        touch /boot/grub/grub.cfg
      else
        failed_devices="$failed_devices $real_device"
      fi
    done

For testing, I added a couple of echo statements:
     failed_devices=
+    echo RET: $RET
     for i in `echo $RET | sed -e 's/, / /g'` ; do
       real_device="$(readlink -f "$i")"
+      echo REAL: $real_device
       if grub-install --target=i386-pc --force --no-floppy $real_device ; then
         # We just installed GRUB 2; then also generate grub.cfg.
         touch /boot/grub/grub.cfg
       else
         failed_devices="$failed_devices $real_device"
       fi
     done

This is the output:

debconf (developer): <-- GET grub-pc/install_devices
debconf (developer): --> 0 /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18FT84, /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GPPQ, /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3,
RET: /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18FT84, /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GPPQ, /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3,
REAL: /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.
REAL: /dev/sdc
Installing for i386-pc platform.
Installation finished. No error reported.
REAL: /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3,
Installing for i386-pc platform.
grub-install: error: cannot find a GRUB drive for /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3,.  Check your device.map.
debconf (developer): <-- SUBST grub-pc/install_devices_failed FAILED_DEVICES  /dev/disk/by-id/ata-ST4000NM0035-1V4107_ZC18GCZ3,

The issue is definitely the comma at the end.

To fix the issue, I changed the sed line to be like this:
    for i in `echo $RET | sed -e 's/,\( \|$\)/ /g'` ; do

This strips the comma at the end, not just those in the middle (commas
followed by spaces).

Alternatively, if you prefer sed -E instead of backslashes for parens,
this also works:
    for i in `echo $RET | sed -E 's/,( |$)/ /g'` ; do
or if -e is important, this also works:
    for i in `echo $RET | sed -Ee 's/,( |$)/ /g'` ; do

-- 
Richard



More information about the Pkg-grub-devel mailing list