0

It is possible for an entry in the EFI boot table to pass arguments to the stub that it loads. For example, this is commonly used to identify the system root when using the EFI-stub of a Linux Kernel.

Such a boot entry might be created with the efibootmgr command, thus:

efibootmgr --create --disk /dev/nvme2n1 --part 1 --label "gentoo (test)" --loader "\EFI\Gentoo\bzImage-test.efi" --unicode "root=PARTUUID=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709"

Normally, entries that load GRUB do not supply any arguments and GRUB's menu-timeout is configured in /boot/grub/grub.cfg. A typical entry for GRUB can be seen in the following output, produced by efibootmgr --unicode:

BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0002,0000,0003
...
Boot0001* gentoo    HD(1,GPT,c12a7328-f81f-11d2-ba4b-00a0c93ec93b,0x800,0x100000)/File(\EFI\gentoo\grubx64.efi)

Can an EFI boot entry supply arguments to GRUB and could one use such an argument to override the timeout?

My reason for doing so would be for convenience: if this is possible, one might configure an infinite timeout in GRUB's /boot/grub/grub.cfg and write two entries to the EFI table:

  1. one with no arguments that applied that infinite timeout (or whatever was set in /boot/grub/grub.cfg)
  2. one that overrode it with a very short timeout, achieving a faster startup time.

This latter could be set as the default boot option but, in the event that a problem occurred, one could use the motherboard's firmware to boot from the former.

2 Answers 2

2

Can an EFI boot entry supply arguments to GRUB and could one use such an argument to override the timeout?

No; GRUB does not look at them. (Not that I could find in grub-core/kern/efi/, at least.)

It only looks at the path that it has been called by, so you could in theory have two copies of grubx64.efi in different folders and each would use a different grub.cfg (which may set different parameters and source the "shared" grub.cfg), but not directly through the load options field.

This latter could be set as the default boot option but, in the event that a problem occurred, one could use the motherboard's firmware to boot from the former.

You can already have that in other ways; e.g. GRUB is able to parse the systemd-boot configuration format, so you could use systemd-boot as the main loader (with a zero timeout) and fall back to GRUB which then uses the bls command to import the systemd-boot menu entries.

(You can use systemd-boot without systemd-init, it's a fairly generic EFI boot manager.)

For that matter, you could use systemd-boot as the only boot manager, with a zero timeout, and just hold spacebar to interrupt the process whenever you need it to stop at the menu.

(GRUB also has a similar mechanism that can be activated through /etc/default/grub; it didn't work for me the last time I tried, but that was 10+ years ago, so maybe it works better on newer firmwares.)

1

The proper answer to this question was provided by @grawity-u1686, above, but it is worth noting that my intention behind the question is better served otherwise.

It is possible to configure GRUB 2 to hide its boot menu and boot the default entry unless escape or F4 are pressed or shift is held down during boot[^1], achieving my aims from the original question without needing to get fancy with the EFI table or maintain multiple GRUB instances or configs in /boot.

To do so, set GRUB_TIMEOUT_STYLE=hidden and set GRUB_TIMEOUT to a short duration in /etc/default/grub as documented in the GNU GRUB 2 manual:

GRUB_TIMEOUT_STYLE
If this option is set to countdown or hidden, then, before displaying the menu, GRUB will wait for the timeout set by GRUB_TIMEOUT to expire. If ESC or F4 are pressed, or SHIFT is held down during that time, it will display the menu and wait for input. If a hotkey associated with a menu entry is pressed, it will boot the associated menu entry immediately. If the timeout expires before either of these happens, it will boot the default entry.

Regenerate grub.cfg by invoking grub-mkconfig -o ... as usual.

I tested on Gentoo, with grub-2.12-r4, and it worked as expected. The salient lines of my /etc/default/grub file were ultimately:

# Hide the GRUB Menu and boot the default entry after a second
# unless `escape` or `F4` are pressed or `shift` is held down.
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=1

[^1]: This is likely the feature to which @grawity-u1686 alluded in their final paragraph. Incidentally, I too have a vague memory of the existence of such a feature and that it never really worked. However, I did test GRUB_TIMEOUT_STYLE=hidden with GRUB 2.12 and it worked perfectly.

You must log in to answer this question.

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