grub-pc fails to install on the last of multiple devices

Bug #1803805 reported by Richard Laager
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
grub2 (Debian)
Fix Released
Unknown
grub2 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

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

Tags: patch
Changed in grub2 (Debian):
status: Unknown → New
Revision history for this message
Paul White (paulw2u) wrote :

Richard, as you didn't use 'apport' or 'ubuntu-bug' when creating this bug report I'm unsure if what you are reporting applies to me or not as your report doesn't include any version information.

I have Ubuntu 18.04 and Ubuntu 19.04 installed on this laptop which has two disks /dev/sda and /dev/sdb. Using Ubuntu 18.04 I can install grub, update grub and boot to either installation without any problem.

From Ubuntu 18.10 (now upgraded to Ubuntu 19.04) any attempt to update grub seemed to fail as I could only boot to the existing kernel and not to the newly installed kernel. I have seen this on more than one occasion.

If this is an example of what you are reporting and something that has been an issue since the 18.04 release then I can confirm the bug report.

There's a reference to my issue at: https://ubuntuforums.org/showthread.php?t=2403574&p=13808168&viewfull=1#post13808168

Revision history for this message
Richard Laager (rlaager) wrote :

I'm using Ubuntu 18.04. My issue is about installing GRUB, not about running update-grub or booting particular entries, so it sounds like your issue is something else.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in grub2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Anthony Fok (foka) wrote :

Thank you for reporting this, Richard!

I ran into this exact same error while upgrading to grub-pc (2.02+dfsg1-12ubuntu2.1) on Ubuntu 19.04. After given choices of "/dev/sda", "/dev/sda5" and "/dev/sdb", I selected /dev/sda and /dev/sda5 on the "GRUB Install devices" page, leaving "/dev/sdb" unchecked. Then this error appears:

    Installing for i386-pc platform.
    grub-install: error: cannot find a GRUB drive for /,. Check your device.map

and, running "ps auxwww | grep grub" shows this:

    grub-install --target=i386-pc --force --no-floppy /,

just as what you have observed!

Thank you for providing the fix too!
I'll try to make merge request of your patch at https://salsa.debian.org/grub-team/grub

Cheers,
Anthony

Changed in grub2 (Debian):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.