grub-reboot
Reboot into a different GRUB entry
TLDR
Set the default boot entry to an entry number, name or identifier for the next boot
Set the default boot entry to an entry number, name or identifier for an alternative boot directory for the next boot
SYNOPSIS
grub-reboot [OPTION...] MENU_ENTRY
PARAMETERS
MENU_ENTRY
The title or numerical index of the GRUB menu entry to boot into for the next restart. For titles, the string must exactly match an entry in 'grub.cfg'.
-h, --help
Display a help message and exit.
-V, --version
Display version information and exit.
--boot-directory=DIR
Use 'DIR' as the boot directory instead of the default '/boot'.
DESCRIPTION
The `grub-reboot` command is a utility for the GRand Unified Bootloader (GRUB) that allows a user to specify the default menu entry for the next boot. Unlike `grub-set-default`, which makes a permanent change to GRUB's default boot entry, `grub-reboot`'s effect is temporary, applying only to the immediate subsequent system restart. After the system reboots once into the specified entry, GRUB reverts to its normal default boot behavior (as defined by `GRUB_DEFAULT` in `/etc/default/grub`).
This command is particularly useful for tasks such as testing a new kernel version, booting into a recovery mode, or temporarily switching to a different operating system installed on the same machine without having to manually select the entry at the GRUB menu or modify persistent configuration files. It operates by writing the chosen menu entry's index or title to the `next_entry` variable within GRUB's environment block, typically located at `/boot/grub/grubenv`. When GRUB starts, it checks for this variable and uses it to determine the boot entry for that specific session. Root privileges are required to execute `grub-reboot` successfully.
CAVEATS
Root Privileges Required: This command must be run with superuser (root) privileges, typically using `sudo`.
Temporary Effect: `grub-reboot` only affects the very next boot. After that, GRUB reverts to its regular default setting.
No Automatic Reboot: This command only configures GRUB; it does not initiate a system reboot. You must manually issue a `reboot` command afterwards.
GRUB Configuration Dependency: For `grub-reboot` to function correctly, GRUB must be configured to utilize the environment block and check for the `next_entry` variable. This is usually the case if `GRUB_DEFAULT` in `/etc/default/grub` is set to `0` or `saved`. If `GRUB_DEFAULT` is set to a specific fixed number greater than `0`, `grub-reboot` might not behave as expected as it tries to override the default for the next boot, but the permanent fixed default might take precedence or cause confusion.
Exact Menu Entry Match: When using a menu entry title, it must be an exact string match (case-sensitive) to an entry found in your `grub.cfg` file. Minor discrepancies will lead to failure. Numeric indices are fragile as they can change after kernel updates or GRUB configuration changes.
HOW IT WORKS
The `grub-reboot` command operates by writing the `MENU_ENTRY` value into a special GRUB environment block file, typically located at `/boot/grub/grubenv`. This file stores a set of key-value pairs that GRUB can read during the boot process. Specifically, `grub-reboot` sets the `next_entry` variable within this file. When GRUB initializes, it checks for the presence and value of `next_entry`. If found, GRUB uses this value to determine which menu item to boot into for that specific session, overriding the system's default `GRUB_DEFAULT` setting. After the system successfully boots using `next_entry`, GRUB (or the `grub-editenv` utility called during the boot process) automatically clears or decrements this variable, ensuring that on subsequent reboots, the normal `GRUB_DEFAULT` configuration is honored.
USAGE EXAMPLES
Here are a few common examples of using `grub-reboot`:
Reboot into the first GRUB menu entry (index 0):
sudo grub-reboot 0 && sudo reboot
Reboot into a specific kernel version (assuming an 'Advanced options' submenu):
sudo grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-52-generic" && sudo reboot
Note: The exact string 'Ubuntu, with Linux 5.15.0-52-generic' might vary based on your system. You can inspect your `grub.cfg` or use the `grub-customizer` tool to find exact entry names.
Reboot into a different operating system, e.g., Windows Boot Manager:
sudo grub-reboot "Windows Boot Manager" && sudo reboot
To see available GRUB menu entries, you can inspect `/boot/grub/grub.cfg` (look for `menuentry` lines) or use tools like `grub-customizer`.
HISTORY
The `grub-reboot` command is an integral part of the GRUB2 (GRand Unified Bootloader version 2) project. It was introduced to provide a convenient, programmatic way to manage the boot sequence for a single restart, leveraging GRUB2's improved environment block capabilities. Prior to such a command, temporarily changing the boot entry might have involved manual editing of configuration files or interaction with the GRUB prompt during boot, which was less user-friendly and more error-prone. Its development reflects a focus on enhancing usability and automation for system administrators and power users.
SEE ALSO
reboot(8), grub-set-default(8), grub-mkconfig(8), grub-install(8), update-grub(8)