[Bug 1840560] Re: "error: can't find command hwmatch" during grub

Mauricio Faria de Oliveira 1840560 at bugs.launchpad.net
Thu Dec 2 19:57:49 UTC 2021


Changes tested for SRU to Impish, Hirsute, and Focal.
(Let's skip Bionic unless there's a strong necessity.)

The results are equivalent on Impish/Hirsute/Focal.
(hwmatch error line no longer present.)

...

Since the changes are low impact and low priority,
let's just stage them instead of pushing SRUs now.

Only the MR for Focal could be submitted since MRs
in LP can't create new branches / need an existing
branch, and both Impish and Hirsute would need new
branch in the package's git repo so only Focal has
a MR proposed (that mentions this + pull requests.)

...

- https://code.launchpad.net/~mfo/grub/+git/grub/+ref/lp1840560-impish

- https://code.launchpad.net/~mfo/grub/+git/grub/+ref/lp1840560-hirsute

- https://code.launchpad.net/~mfo/grub/+git/grub/+ref/lp1840560-focal
- https://code.launchpad.net/~mfo/grub/+git/grub/+merge/412712

cheers,
Mauricio

...

Steps:

$ lxc launch ubuntu:impish impish-vm --vm
$ while true; do lxc console impish-vm; done
To detach from the console, press: <ctrl>+a 

BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " ...
BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " ...
error: can't find command `hwmatch'.
GRUB_FORCE_PARTUUID set, attempting initrdless boot.
EFI stub: UEFI Secure Boot is enabled.
...

$ sudo dpkg -i grub-common_*.deb && sudo update-grub && sudo reboot
...

To detach from the console, press: <ctrl>+a 
BdsDxe: loading Boot0007 "ubuntu" ...
BdsDxe: starting Boot0007 "ubuntu" ...
GRUB_FORCE_PARTUUID set, attempting initrdless boot.
EFI stub: UEFI Secure Boot is enabled.

** Changed in: grub2 (Ubuntu Bionic)
       Status: In Progress => Won't Fix

** Tags added: block-proposed-focal block-proposed-hirsute block-
proposed-impish

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to grub2 in Ubuntu.
https://bugs.launchpad.net/bugs/1840560

Title:
  "error: can't find command hwmatch" during grub

Status in grub2 package in Ubuntu:
  Fix Released
Status in grub2-signed package in Ubuntu:
  Invalid
Status in grub2 source package in Bionic:
  Won't Fix
Status in grub2-signed source package in Bionic:
  Invalid
Status in grub2 source package in Focal:
  In Progress
Status in grub2-signed source package in Focal:
  Invalid
Status in grub2 source package in Groovy:
  Invalid
Status in grub2-signed source package in Groovy:
  Invalid
Status in grub2 source package in Hirsute:
  In Progress
Status in grub2-signed source package in Hirsute:
  Invalid
Status in grub2 source package in Impish:
  In Progress
Status in grub2-signed source package in Impish:
  Invalid
Status in grub2 source package in Jammy:
  Fix Released
Status in grub2-signed source package in Jammy:
  Invalid
Status in grub2 package in Debian:
  New

Bug description:
  [Impact]

   * Users on non-pc/i386 platforms (e.g., efi/amd64) may observe
     the message "error: can't find command `hwmatch'" every boot.

   * Also observed on cloud instances, generating support tickets
     asking for clarification/impacts. (which could be deflected.)

   * There' little or no impact, as hwmatch is only used to check
     hardware device ID against a list for issues w/ graphics/KMS.
     When this error happens, the default is set to keep graphics.

   * This has possibly always happened on non-pc/i386, as hwmatch
     is patched/exists only in 'grub-core/commands/_i386/pc_' dir,
     thus there doesn't seem to be any serious issues as a result.

  [Fix]

   * Check for `$grub_platform != pc` then do not call hwmatch;
     just keep current behavior (ie, keep graphics/framebuffer.)

  [Test Plan]

   * Boot a VM with EFI (LXD or multipass/libvirt/ovmf) and see
     the serial console show the error message (or not, w/ fix.)

   - lxd:

    $ lxc launch ubuntu:impish impish-vm --vm --console
    Creating impish-vm
    Starting impish-vm
    To detach from the console, press: <ctrl>+a q
    BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from ...
    BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from ...
    error: can't find command `hwmatch'.
    ...

   - multipass/libvirt/ovmf:

   sudo snap install multipass
   sudo multipass set local.driver=libvirt
   sudo snap connect multipass:libvirt

   multipass launch -c 1 -d 4g -m 1g -n hwmatch-i impish

   sudo apt -y install ovmf
   sudo mkdir -p /var/lib/libvirt/qemu/nvram

   virsh edit hwmatch-i
     # insert in <os> section:
     <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
     <nvram>/var/lib/libvirt/qemu/nvram/hwmatch-i.fd</nvram>

   virsh shutdown hwmatch-i
   virsh start --console hwmatch-i

   * Before:
   ...
   BdsDxe: loading Boot0003 "ubuntu" from ...\shimx64.efi
   BdsDxe: starting Boot0003 "ubuntu" from ...\shimx64.efi
   error: can't find command `hwmatch'.
   [    0.000000] Linux version ...

   * After:
   sudo dpkg -i grub_common_*.deb # test package; g-c is enough.
   sudo update-grub && sudo reboot
   ...
   BdsDxe: loading Boot0003 "ubuntu" from ...\shimx64.efi
   BdsDxe: starting Boot0003 "ubuntu" from ...\shimx64.efi
   [    0.000000] Linux version ...

  [Where problems could occur]

   * Issues with graphics/flickering during boot on systems with
     graphics adapters in use might be hit in case of regression.

   * Theoretically the risk is low, since hwmatch apparently has
     never worked on non-pc/i386, and we replace the broken call
     while keeping current behavior observed with it ("no change".)

  [Other Info]

   * While it might be interesting to try and enable/fix it for
     other platforms, let's have a trivial fix to be considered
     to backport to stable releases, at this time (less changes.)

   * The same behavior is linux_gfx_mode=keep, despite the error.
     This happens because in the error case, grub shell evaluates
     if hwmatch ...; then` to true, and `if [ $match = 0 ]; then`
     to true too (as it's undefined) so `set linux_gfx_mode=keep`.

     Before/After in grub shell (same behavior):

      grub> hwmatch
      error: can't find command `hwmatch'.

      grub> echo $grub_platform
      efi

      grub> echo $linux_gfx_mode
      keep

   * Other details in Debian bug 990836 [1].

   * It looks like grub2-unsigned follows grub2 automatically,
     so not providing debdiffs to it/just grub2.

  [Links]
   * [1] https://bugs.debian.org/990836

  [Original Description]
  Upon disabling my grub menu using grub-customizer, I've noticed that just before the system boots and goes into the crypto password prompt the following error message appears on the display:

  ```
  error: can't find command hwmatch
  ```

  Looks like this command is referenced from /boot/grub/grub/cfg

  ```
      if hwmatch ${prefix}/gfxblacklist.txt 3; then
  ```
  However, the mod doesn't exist on grub's mod folder:

  ```
  ~ ls -la /boot/grub/x86_64-efi/*.mod|wc -l
  269

  ~ ls -la /boot/grub/x86_64-efi/hw*
  fish: No matches for wildcard “/boot/grub/x86_64-efi/hw*”

  ```

  ProblemType: Bug
  DistroRelease: Ubuntu 19.04
  Package: grub-efi-amd64-signed 1.115+2.02+dfsg1-12ubuntu2
  ProcVersionSignature: Ubuntu 5.0.0-25.26-generic 5.0.18
  Uname: Linux 5.0.0-25-generic x86_64
  ApportVersion: 2.20.10-0ubuntu27.1
  Architecture: amd64
  CurrentDesktop: Unity
  Date: Sun Aug 18 00:22:41 2019
  InstallationDate: Installed on 2019-08-17 (0 days ago)
  InstallationMedia: Ubuntu 19.04 "Disco Dingo" - Release amd64 (20190416)
  SourcePackage: grub2-signed
  UpgradeStatus: No upgrade log present (probably fresh install)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1840560/+subscriptions




More information about the foundations-bugs mailing list