8

This question Error unknown command hwmatch is exactly what I'm asking but was closed as non reproducible. Mine is very reproducible.

Ubuntu 18.04 freshly installed on a 64-bit UEFI machine. Default grub boot options work fine, but I wanted to add a brief countdown (my normal config). After editing /etc/default/grub as normal and running sudo update-grub, the countdown works, but I get the error shown in the question title.

I tried the solution (copying files) in the closed question but it didn't seem to fit my configuration. Frankly I found the answer confusing.

I also tried editing /etc/grub.d/10_linux to comment out the IF-THEN structure that uses hwmatch. After that I did a sudo update-grub but I still got the error.

How can I get my countdown and not see this error?

Edit per comments -

Stock grub as installed (all non-commented-out lines shown)

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

Edited grub to give countdown (all non-commented-out lines shown)

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=countdown
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
17
  • Edit your question and show us cat /etc/default/grub. Tell me what you edited/added to enable countdown.
    – heynnema
    Sep 15, 2019 at 20:17
  • Did you ever add an "insmod hwmatch" anywhere in the grub.d files?
    – ubfan1
    Sep 15, 2019 at 20:46
  • @ubfan1 No, I didn't. Please elaborate. Sep 15, 2019 at 20:46
  • @OrganicMarble show me the other grub lines that are not commented out.
    – heynnema
    Sep 15, 2019 at 20:57
  • hwmatch.mod is a module in the /boot/grub/i386-pc directory, and may need an explicit insmod somewhere before the use of hwmatch command in 10_linux. Pick a location in the executation path (not in a function) before the hwmatch command to add insmod hwmatch..
    – ubfan1
    Sep 15, 2019 at 20:59

2 Answers 2

3

To get rid of the error message, add this line to /etc/default/grub:

GRUB_GFXPAYLOAD_LINUX=keep

Source: #4 comment on https://bugs.launchpad.net/ubuntu/+source/grub2-signed/+bug/1840560

This will let a condition in the code get evaluated in such way that the codeblock referencing hwmatch gets bypassed.

As to how worrying is the missing command (or not): according to mook765's comment, it's part of only grub-pc, and not grub-efi, and is supposedly being referenced as a mistake in the case of a grub-efi install.

A voluntary remark on the countdown / menu:

Using

GRUB_TIMEOUT_STYLE=menu

instead of

GRUB_TIMEOUT_STYLE=countdown

would make the menu visible (while leaving the countdown feature (at the bottom of the screen) and automatic fallback selection intact).

Don't forget to run sudo update-grub after being done with the editing.

2
  • I'm switching the accept to this answer instead of mine because it's the superior approach. I'm not sure why you added the part about displaying the grub menu though, I don't want that. I just want the 5 second countdown, and my config gives me that. Apr 20, 2021 at 15:47
  • 1
    @OrganicMarble Thank you for the accept. I have applied updates :) (I left in a smoothened variant of the menu visibility remark because I think there's still a lot of people after that kind of information.)
    – Levente
    Apr 20, 2021 at 16:00
2

I commented out the if-then structure in /etc/grub.d/10_linux that used hwmatch and that worked.

Note this was a Brute Force and Ignorance fix because I didn't know which of the outcomes in the if-then structure to choose. The one I chose worked for me, it may not for you.

After running sudo update-grub I got the desired result on boot.

# Use ELILO's generic "efifb" when it's known to be available.
# FIXME: We need an interface to select vesafb in case efifb can't be used.
if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then
  echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
else
  cat << EOF
if [ "\${recordfail}" != 1 ]; then
  if [ -e \${prefix}/gfxblacklist.txt ]; then
#    if hwmatch \${prefix}/gfxblacklist.txt 3; then
#      if [ \${match} = 0 ]; then
        set linux_gfx_mode=keep
#      else
#        set linux_gfx_mode=text
#      fi
#    else
#      set linux_gfx_mode=text
#    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
EOF
fi
cat << EOF
export linux_gfx_mode
EOF

Note: at first this didn't work because I copied /etc/grub.d/10_linux to /etc/grub.d/10_linux-backup before editing it. But all executable files in grub.d get picked up so the original one got copied in too. I'm fortunate the system booted. I took the executable setting away from /etc/grub.d/10_linux-backup, re-ran sudo update-grub, and that did it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .