grub-reboot command with the exact name of the desired boot option. This utility sets a one-time flag in the GRUB environment that forces the bootloader to select that entry on the next startup only.
Understanding the Problem
When running dual-boot systems or multiple kernel versions, the GRand Unified Bootloader (GRUB) typically displays a menu allowing manual selection. While this flexibility is useful, it adds unnecessary delay during automated processes, remote administration, or when you know exactly which operating system or kernel you need. Manually navigating the menu via keyboard interrupts the flow of automation scripts and slows down routine reboots. The standard behavior waits for user input or times out, which is inefficient for headless servers or power users who want deterministic boot outcomes.
Identifying Available Entries
Before issuing a reboot command, you must identify the precise string used by GRUB to reference the target entry. These strings are case-sensitive and include spaces as they appear in the menu. You can retrieve this list using the grep command against the GRUB configuration file.
grep menuentry /boot/grub/grub.cfg | cut -d "'" -f2
This command filters the configuration file to show only menu entries and extracts the text between single quotes. Common entries might look like "Ubuntu", "Windows Boot Manager", or "Advanced options for Ubuntu". Note that some entries may contain special characters or numbers, such as "Ubuntu, with Linux 5.4.0-42-generic". Copy the exact string for the entry you wish to boot into.
Using grub-reboot Command
The primary tool for this task is grub-reboot. It accepts the exact menu entry string as an argument. For example, if your desired entry is named "Windows Boot Manager", you would run:
sudo grub-reboot "Windows Boot Manager"
After executing this command, initiate a normal reboot using sudo reboot. GRUB will read the temporary flag set by grub-reboot and automatically select the specified entry, bypassing the interactive menu. Once the system boots into the selected OS, the flag is cleared, and subsequent reboots will return to the default behavior unless grub-reboot is called again.
Verifying the Configuration
To ensure the command was accepted correctly, you can check the GRUB environment block. Although not always necessary, verifying the setting helps debug issues where the wrong entry is selected. Use the following command to inspect the current GRUB settings:
sudo grub-editenv list
If the saved_entry variable matches the string you provided, the configuration is active. If it does not appear or shows an empty value, double-check the spelling and spacing of the entry name from the grep output. Discrepancies often arise from trailing spaces or incorrect capitalization.
Alternative Methods
While grub-reboot is the most direct method, other approaches exist depending on your needs. You can modify the default entry in /etc/default/grub by changing the GRUB_DEFAULT variable. However, this change persists across reboots, making it unsuitable for temporary switches. Another alternative involves scripting the selection process, but this adds complexity compared to the single-command solution provided here. For users managing complex environments, integrating grub-reboot into automation tools like Ansible or cron jobs ensures consistent boot behavior.
Common Pitfalls
One frequent error is using the index number instead of the entry name. While older versions of GRUB supported numeric indices, modern distributions prefer names due to dynamic menu generation. Using an index may result in selecting the wrong entry if the menu order changes after a kernel update. Always use the string name to guarantee accuracy. Additionally, ensure that the GRUB package is installed and updated, as outdated versions may not support grub-reboot correctly.
For more information on related Linux administrative tasks, you might find these articles helpful:
- Run Programs with Elevated Privileges: A Comprehensive Guide covers how to manage permissions effectively, which is relevant when running
grub-rebootwith sudo. - How to Clear Recent Files History in Linux without Deleting Actual Files? provides insights into maintaining system cleanliness alongside boot optimizations.
Frequently Asked Questions
What happens if I reboot without using grub-reboot?
If you do not specify a new entry, the system will boot using the default entry defined in GRUB configuration. The one-time flag set by grub-reboot is consumed during the next boot cycle and does not persist beyond that. Subsequent reboots will ignore any previous grub-reboot commands unless issued again.
Can I use grub-reboot with kernel parameters?
No, grub-reboot only selects the menu entry; it does not allow passing additional kernel parameters. To add parameters, you must edit the GRUB configuration file or use the GRUB menu interface manually at boot time. The command strictly controls which predefined entry is chosen.
Why does my entry name have spaces or special characters?
GRUB menu entries are generated dynamically based on installed kernels and operating systems. Names often include version numbers, separators, or descriptions added by the distribution's bootloader script. These characters are part of the identifier and must be included exactly as shown in the grep output to ensure correct selection.
Is grub-reboot available on all Linux distributions?
Yes, grub-reboot is part of the standard GRUB utilities package found in most major Linux distributions, including Ubuntu, Debian, Fedora, and Arch Linux. However, the availability depends on having GRUB installed as the bootloader. Systems using UEFI bootloaders like systemd-boot or rEFInd require different methods.
How do I revert to the default boot entry?
Simply rebooting normally without invoking grub-reboot restores the default behavior. The temporary override is cleared automatically after the first successful boot. There is no need to manually reset configurations unless you have permanently changed the GRUB_DEFAULT setting in the main config file.