Using the grub-reboot command (with examples)
- Linux
- November 5, 2023
Set the default boot entry for the next boot
The grub-reboot
command is used to set the default boot entry for GRUB, but only for the next boot. This allows you to choose a different boot entry for the next time your system restarts. In this article, we’ll explore different use cases of the grub-reboot
command and provide code examples for each one.
Use Case 1: Set the default boot entry to an entry number
sudo grub-reboot 2
Motivation: This use case is useful if you want to choose a specific boot entry by its number. For example, if you have multiple operating systems installed and you want to boot into the second entry, you can use this command.
Explanation: The grub-reboot
command takes an argument which specifies the boot entry to set. In this case, we are setting the default boot entry to entry number 2.
Example output: The default boot entry for the next boot will be set to the second entry.
Use Case 2: Set the default boot entry to an entry name
sudo grub-reboot Ubuntu
Motivation: If you prefer referencing entries by their name instead of number, you can use this use case. This is particularly useful when the boot menu displays the entries with their names rather than numbers.
Explanation: The grub-reboot
command can take an argument that specifies the boot entry by its name. In this case, we are setting the default boot entry to an entry named “Ubuntu”.
Example output: The default boot entry for the next boot will be set to the entry named “Ubuntu”.
Use Case 3: Set the default boot entry to an entry identifier
sudo grub-reboot UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72
Motivation: Every boot entry has a unique identifier associated with it. This use case allows you to set the default boot entry using its identifier.
Explanation: The grub-reboot
command can also take an argument that specifies the boot entry by its identifier. In this case, we are setting the default boot entry to an entry with the identifier “UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72”.
Example output: The default boot entry for the next boot will be set to the entry with the identifier “UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72”.
Use Case 4: Set the default boot entry using an alternative boot directory
sudo grub-reboot --boot-directory /mnt/boot 1
Motivation: Sometimes you may have multiple boot directories on your system, especially when dealing with dual-boot configurations or separate partitions for different operating systems. This use case allows you to specify an alternative boot directory when setting the default boot entry.
Explanation: The grub-reboot
command can take the --boot-directory
option followed by the path to the alternative boot directory. In this case, we are setting the default boot entry to entry number 1 using the alternative boot directory “/mnt/boot”.
Example output: The default boot entry for the next boot, using the alternative boot directory “/mnt/boot”, will be set to the first entry.
Use Case 5: Set the default boot entry using an alternative boot directory and an entry name
sudo grub-reboot --boot-directory /mnt/boot Ubuntu
Motivation: Similar to the previous use case, this is useful when you have an alternative boot directory and prefer referencing entries by their name rather than number.
Explanation: In this use case, we are combining the --boot-directory
option with the entry name argument. The --boot-directory
option specifies the alternative boot directory ("/mnt/boot"), and the entry name (“Ubuntu”) indicates which boot entry to set as the default.
Example output: The default boot entry for the next boot, using the alternative boot directory “/mnt/boot”, will be set to the entry named “Ubuntu”.
Use Case 6: Set the default boot entry using an alternative boot directory and an entry identifier
sudo grub-reboot --boot-directory /mnt/boot UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72
Motivation: This use case is a combination of the previous two use cases. It allows you to specify both an alternative boot directory and the boot entry by its identifier.
Explanation: Similar to the previous example, we’re using the --boot-directory
option to specify an alternative boot directory ("/mnt/boot"). Additionally, we’re using the entry identifier (“UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72”) to set the default boot entry.
Example output: The default boot entry for the next boot, using the alternative boot directory “/mnt/boot”, will be set to the entry with the identifier “UUID=bae5a647-1bef-45f7-9c84-6e3effa8cd72”.
Use Case 7: Setting the default boot entry for a non-standard GRUB installation
sudo grub-reboot --boot-directory=/mnt/boot /dev/sda2
Motivation: If your GRUB installation is not in the default location (e.g., running on a separate partition), you can use this use case to specify the boot directory and the device where GRUB is installed.
Explanation: In this use case, we’re using the --boot-directory
option followed by the path to the alternative boot directory ("/mnt/boot"). We’re also specifying the device where GRUB is installed ("/dev/sda2") as the boot entry.
Example output: The default boot entry for the next boot, using the alternative boot directory “/mnt/boot” and the device “/dev/sda2”, will be set to the specified boot entry.
Use Case 8: Setting the default boot entry to the current one
sudo grub-reboot
Motivation: This use case is useful when you want to set the default boot entry to the current one, without specifying any specific entry.
Explanation: In this use case, we’re not providing any arguments to the grub-reboot
command. It will automatically set the default boot entry to the current one without any additional input.
Example output: The default boot entry for the next boot will be set to the current boot entry.