KeyError in uefi_find_duplicate_entries

Bug #1969367 reported by Ryan Sommers
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
curtin
New
Undecided
Unassigned
grub2 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I attempted to install Ubuntu 20.04.03 and 22.04 (beta) over the weekend and ran into an issue where part of the Grub install step was causing a KeyError. The specific line that was throwing the error is: https://github.com/canonical/curtin/blob/master/curtin/commands/curthooks.py#L582

After investigations it looks like the "BootCurrent" line returned by efibootmgr was showing '0000' as the current boot. However, that line had not been processed as it was a USB device that doesn't seem to match the expected format in the parse function. That would then lead to the '0000' key not being added to the data structure and throwing a KeyError.

I'm not sure if the solution should be to alter the previous line (https://github.com/canonical/curtin/blob/master/curtin/commands/curthooks.py#L581) to include a check against the keys, or if the regular expression at https://github.com/canonical/curtin/blob/60e076ceae67ac4bdea806062df69d0d25e9c32c/curtin/util.py#L932 should be adjusted to allow for 0-width 'name' fields. (In this case the USB boot device was not given a name and therefore seems like it would fail the regex.)

I wasn't able to figure out how I could test either of these solutions. My workaround was to replace the 'efibootmgr' executable temporarily and change the 'BootCurrent' parameter to '0001' which was in the dictionary and therefore would get past the KeyError. It seems to have worked for the install. Here is a rough script I did to replace it after the package was installed:

sudo -i
mv /target/usr/bin/efibootmgr /target/usr/bin/efibootmgr_orig
echo <<EOF >/target/usr/bin/efibootmgr
#!/bin/sh
/target/usr/bin/efibootmgr_orig $@ | sed -e '/^BootCurrent/ s/0000/0001/'
EOF
chmod o+x /target/usr/bin/efibootmgr

Revision history for this message
Dan Bungert (dbungert) wrote :

Sounds like Curtin could stand some defensive checks.
Is this also something that should be addressed in grub?

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
Nicklas Frahm (nicklasfrahm) wrote (last edit ):
Download full text (88.5 KiB)

Not sure if useful at all, but below you may find the output of a failed deployment using MAAS. For another server (Cisco C220 M4) it works fine. This one has a lot of network cards and hence (I assume) a lot of PXE boot options. Not sure if this is related.

finish: cmd-install/stage-network/builtin/cmd-net-meta: SUCCESS: curtin command net-meta
start: cmd-install/stage-extract/builtin/cmd-extract: curtin command extract
Installing sources: [{'type': 'tgz', 'uri': 'cp:///media/root-ro'}] to target at /tmp/tmp6jtxp_ik/target
start: cmd-install/stage-extract/builtin/cmd-extract: acquiring and extracting image from cp:///media/root-ro
Running command ['sh', '-c', 'mkdir -p "$2" && cd "$2" && rsync -aXHAS --one-file-system "$1/" .', '--', '/media/root-ro', '/tmp/tmp6jtxp_ik/target'] with allowed return codes [0] (capture=False)
finish: cmd-install/stage-extract/builtin/cmd-extract: SUCCESS: acquiring and extracting image from cp:///media/root-ro
Applying write_files from config.
finish: cmd-install/stage-extract/builtin/cmd-extract: SUCCESS: curtin command extract
start: cmd-install/stage-curthooks/builtin/cmd-curthooks: curtin command curthooks
Running curtin builtin curthooks
Configuring target system for distro: ubuntu osfamily: debian
start: cmd-install/stage-curthooks/builtin/cmd-curthooks/writing-apt-config: configuring apt configuring apt
Transferred {'grub2': 'grub2 grub2/update_nvram boolean false', 'maas': 'cloud-init cloud-init/datasources multiselect MAAS\ncloud-init cloud-init/maas-metadata-url string http://10.0.14.254:5248/MAAS/metadata/\ncloud-init cloud-init/maas-metadata-credentials string REDACTED
Running command ['unshare', '--help'] with allowed return codes [0] (capture=True)
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'lsb_release', '--all'] with allowed return codes [0] (capture=True)
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'dpkg', '--print-architecture'] with allowed return codes [0] (capture=True)
got primary mirror: None
got security mirror: None
Apt Mirror info: {'PRIMARY': 'http://archive.ubuntu.com/ubuntu/', 'SECURITY': 'http://security.ubuntu.com/ubuntu/', 'MIRROR': 'http://archive.ubuntu.com/ubuntu/'}
Applying debconf selections
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'debconf-set-selections'] with allowed return codes [0] (capture=True)
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'dpkg-query', '--list'] with allowed return codes [0] (capture=True)
unconfiguring cloud-init
cleaning cloud-init config from: ['/tmp/tmp6jtxp_ik/target/etc/cloud/cloud.cfg.d/90_dpkg.cfg']
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'dpkg-reconfigure', '--frontend=noninteractive', 'cloud-init'] with allowed return codes [0] (capture=True)
Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/tmp/tmp6jtxp_ik/target', 'dpkg-query', '--show', '--showformat', '${Version}', 'cloud-init'] with allowed return codes [0] (capture=True)
Set preserve_sources_list to True in /etc/cloud/cloud.c...

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.