grub-installer should mount efivarfs

Bug #1880855 reported by Olaf Seibert
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
grub-installer (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I am trying to install Focal 20.04 on an UEFI machine, but it fails at the end when installing grub. Here are messages from syslog:

May 26 11:51:56 grub-installer: info: Running chroot /target grub-install --force "dummy"
May 26 11:51:56 grub-installer: Installing for x86_64-efi platform.
May 26 11:51:57 grub-installer: File descriptor 3 (pipe:[37905]) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 4 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 5 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 6 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 8 (/dev/sdb1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 3 (pipe:[37905]) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 4 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 5 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 6 (/dev/ttyS1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: File descriptor 8 (/dev/sdb1) leaked on vgs invocation. Parent PID 3610: grub-install
May 26 11:51:57 grub-installer: grub-install: warning: Cannot read EFI Boot* variables.
May 26 11:51:57 grub-installer: grub-install: warning: read_file: could not read from file: Input/output error.
May 26 11:51:57 grub-installer: grub-install: warning: vars_get_variable: read_file(/sys/firmware/efi/vars/Boot0001-8be4df61-93ca-11d2-aa0d-00e098032b8c/raw_var) failed: Input/output error.
May 26 11:51:57 grub-installer: grub-install: warning: efi_get_variable: ops->get_variable failed: Input/output error.
May 26 11:51:57 grub-installer: grub-install: error: failed to register the EFI boot entry: Input/output error.
May 26 11:51:57 grub-installer: error: Running 'grub-install --force "dummy"' failed.
May 26 11:51:57 debconf: --> SUBST grub-installer/grub-install-failed BOOTDEV dummy
May 26 11:51:57 debconf: Adding [BOOTDEV] -> [dummy]
May 26 11:51:57 debconf: <-- 0
May 26 11:51:57 debconf: --> INPUT critical grub-installer/grub-install-failed

Note the failed access to /sys/firmware/efi/vars/Boot0001-8be4df61-93ca-11d2-aa0d-00e098032b8c/raw_var

Looking at the EFI boot-related variables also fails with efibootmgr:

~ # mount -t sysfs sys /target/sys
~ # chroot /target efibootmgr
Skipping unreadable variable "Boot0001": Input/output error
BootCurrent: 0005
Timeout: 1 seconds
BootOrder: 0005,0006,0007,0008,0004,0001
Boot0004* UEFI: Built-in EFI Shell
Boot0005* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0006* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0007* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0008* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
MirroredPercentageAbove4G: 0.00
MirrorMemoryBelow4GB: false

Note again the problem with Boot001. Doing the same with a Xenial 18.04 system, there is no such error:

[08:30:21] root@cbk130411:~# efibootmgr
BootCurrent: 0005
Timeout: 1 seconds
BootOrder: 0005,0006,0007,0008,0009
Boot0001 Hard Drive
Boot0004* UEFI: Built-in EFI Shell
Boot0005* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0006* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0007* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0008* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0009* ubuntu
[08:30:07] root@cbk130411:~# efibootmgr -v
BootCurrent: 0005
Timeout: 1 seconds
BootOrder: 0005,0006,0007,0008,0009
Boot0001 Hard Drive BBS(HD,,0x0)/VenHw(5ce8128b-2cec-40f0-8372-80640e3dc858,0200)..GO..NO..........I.N.T.E.L. .S.S.D.S.C.2.K.G.4.8.0.G.8.LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG...LOTS-OF_DATA-THAT-IS-VERY-LONG.....2.B.G.N........BO
Boot0004* UEFI: Built-in EFI Shell VenMedia(5023b95c-db26-429b-a648-bd47664c8012)..BO
Boot0005* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx PciRoot(0x3)/Pci(0x2,0x0)/Pci(0x0,0x0)/MAC(9803xxxxxxxx,1)/IPv4(0.0.0.0:0<->0.0.0.0:0,0,0)..BO
Boot0006* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx PciRoot(0x3)/Pci(0x2,0x0)/Pci(0x0,0x1)/MAC(9803xxxxxxxx,1)/IPv4(0.0.0.0:0<->0.0.0.0:0,0,0)..BO
Boot0007* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx PciRoot(0x3)/Pci(0x2,0x0)/Pci(0x0,0x0)/MAC(9803xxxxxxxx,1)/IPv6([::]:<->[::]:,0,0)..BO
Boot0008* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx PciRoot(0x3)/Pci(0x2,0x0)/Pci(0x0,0x1)/MAC(9803xxxxxxxx,1)/IPv6([::]:<->[::]:,0,0)..BO
Boot0009* ubuntu HD(1,GPT,cd9cb552-6580-4f5d-9804-76166ce0de68,0x800,0x3d0000)/File(\EFI\Ubuntu\shimx64.efi)..BO

The value for Boot001 is very long, longer than 1024 bytes.

I found that there is a problem with long values: https://www.kernel.org/doc/Documentation/filesystems/efivarfs.txt

When I retried (by hand) with Focal 20.04 after mounting efivarfs, things worked better:

(something like this)

~ # mount -t efivarfs efivars /target/sys/firmware/efi/efivars
~ # chroot /target grub-install --target x86_64-efi --force "dummy"
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sdb1) leaked on vgs invocation. Parent PID 9684: grub-install
File descriptor 4 (/dev/sdb1) leaked on vgs invocation. Parent PID 9684: grub-install
Installation finished. No error reported.
~ # chroot /target efibootmgr
BootCurrent: 0005
Timeout: 1 seconds
BootOrder: 0000,0005,0006,0007,0008,0004,000A
Boot0000* ubuntu
Boot0004* UEFI: Built-in EFI Shell
Boot0005* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0006* UEFI: PXE IPv4 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0007* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot0008* UEFI: PXE IPv6 Mellanox Network Adapter - 98:03:9B:xx:xx:xx
Boot000A Hard Drive
MirroredPercentageAbove4G: 0.00
MirrorMemoryBelow4GB: false

The grub-installer takes care to mount /sys into /target (without that you get even more errors about accessing EFI variables, as I discovered), but it should also mount efivarsfs.

if [ "$(udpkg --print-os)" = linux ] && [ -z "$(ls $ROOT/sys)" ]; then
        mount -t sysfs sysfs $ROOT/sys && umount_on_exit /sys
fi

This is especially important since so fat I have found no way to get this done from the preseed file.

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

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

Changed in grub-installer (Ubuntu):
status: New → Confirmed
Revision history for this message
Olaf Seibert (oseibert-sys11) wrote :

Note: if a fix is used to add some more code similar to the bit I quoted above (using `umount_on_exit`): `umount_on_exit` has to be fixed too, to unmount in reverse order. Also, it seems that when the unmounting eventually happens, IFS is not set back to default, so the field splitting doesn't work.

Conceivably there could be a fix in debian/postint to do the mount before even invoking `grub-installer`. But in that case a similar change should be made to `rescue.d/80grub-reinstall`. So it seems better to have it in `grub-install` itself.

I am attaching a patch.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "Mount and unmount $ROOT/sys/firmware/efi/efivars" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
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.