brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: grub-reboot picks a GRUB entry for the next boot only

Boots and kernel
~/tips/tip-grub-reboot-next-boot-only

sudo grub-reboot MENU_ENTRY

Sets which GRUB menu entry boots once, and the normal default returns after that.

Booting an older kernel on a server I cannot reach is a gamble I only take with a safety net. grub-reboot is that net: the choice lasts for one boot.

sudo grub-reboot MENU_ENTRY
sudo reboot

The man page describes it as setting the default boot entry for GRUB, for the next boot only. MENU_ENTRY is a number, a menu item title or a menu item identifier. The following boot goes back to the normal default, so a bad choice fixes itself with one more power cycle. That matters on a headless machine.

To find the titles, look at the entries in the generated config. The path depends on the distribution:

grep -E "^\s*(menuentry|submenu)" /boot/grub/grub.cfg

The man page has a warning about submenus. For an entry inside a submenu you give the submenu title and the entry title, separated by > with no spaces around it, and depending on your shell the > needs quoting. An entry id also works and avoids the long title.

sudo grub-reboot 'Submenu title>Entry title'

The caveat, from the same man page: when GRUB cannot write to its environment block, for example when it is stored on an MDRAID or LVM device, the chosen entry stays the default even after the reboot. On such a system, check the default before you rely on the safety net.

For a permanent choice there is grub-set-default, which needs GRUB_DEFAULT=saved in /etc/default/grub.

Further reading: grub-reboot man page, GRUB manual: environment block

More Boots and kernel tips disable_poe_fan=1 GRUB_TIMEOUT_STYLE=hidden sudo bootctl set-oneshot ID systemd.unit=rescue.target lsinitramfs /boot/initrd.img-$(uname -r) All Boots and kernel tips (16) All topics

Link