grub-set-default
Set the default GRUB boot entry
TLDR
Set the default boot entry to an entry number, name or identifier
Set the default boot entry to an entry number, name or identifier for an alternative boot directory
SYNOPSIS
grub-set-default entry
PARAMETERS
entry
The target boot entry to set as the default. This can be:
1. A zero-based numeric index corresponding to the position of the entry in the GRUB boot menu (e.g., 0
for the first entry).
2. A full title string of the entry as it appears in the GRUB boot menu (e.g., "Ubuntu, with Linux 5.15.0-78-generic"
). Enclose titles with spaces in quotes.
3. The special keyword saved
, which instructs GRUB to remember the last manually selected entry and use it as the default for subsequent boots. This requires GRUB_DEFAULT=saved
to be set in /etc/default/grub
, which this command can facilitate.
DESCRIPTION
grub-set-default
is a utility used to persistently change the default operating system or kernel entry that GRUB (Grand Unified Bootloader) will boot into. Unlike grub-reboot
, which sets a default for the next boot only, grub-set-default
modifies the GRUB_DEFAULT
variable in the /etc/default/grub
configuration file. This change ensures that the specified entry becomes the permanent default choice for all subsequent reboots until it is changed again. After using grub-set-default
, it is crucial to run update-grub
(or grub-mkconfig -o /boot/grub/grub.cfg
) to generate a new grub.cfg
file that incorporates the modified GRUB_DEFAULT
value. This command is particularly useful for users who frequently switch between multiple operating systems or different kernel versions and wish to set a specific one as their primary boot option. The argument can be a zero-based index of the desired entry, a full title string of the entry as it appears in the GRUB menu, or the special value "saved" to use the last chosen entry.
CAVEATS
- Changes made by
grub-set-default
are not effective immediately. You must runupdate-grub
(orgrub-mkconfig -o /boot/grub/grub.cfg
) after executing this command to generate a new GRUB configuration file and apply the changes. - This command requires root privileges to modify the
/etc/default/grub
file. - If you set the default to
saved
, GRUB will remember the last chosen entry. However, to change that saved entry without rebooting, you would typically usegrub-editenv
(e.g.,grub-editenv set default index_or_title
).grub-set-default
sets the initial or fallback default in the configuration file.
HOW IT WORKS:
The grub-set-default
script primarily modifies the GRUB_DEFAULT
line within the /etc/default/grub
file. For example, if you run grub-set-default 1
, it changes the line from GRUB_DEFAULT=0
to GRUB_DEFAULT=1
(or similar). This file is then read by update-grub
to generate the final /boot/grub/grub.cfg
configuration.
EXAMPLES:
- To set the first entry in your GRUB menu as the default:
sudo grub-set-default 0
- To set a specific operating system by its title as the default:
sudo grub-set-default "Ubuntu, with Linux 5.15.0-78-generic"
- To make GRUB remember the last manually selected entry as the default:
sudo grub-set-default saved
- After any of the above, always run:
sudo update-grub
HISTORY
The grub-set-default
command, as a distinct utility, became prominent with the advent of GRUB2. While the concept of a default boot entry existed in GRUB Legacy, GRUB2's modular configuration and the introduction of /etc/default/grub
as a central point for user-defined variables led to the creation of helper scripts like this. Its purpose is to simplify the modification of the GRUB_DEFAULT
variable, abstracting away the direct editing of configuration files for users, and ensuring the change is persisted across reboots by modifying the primary GRUB configuration source.
SEE ALSO
update-grub(8), grub-reboot(8), grub-mkconfig(8), grub-editenv(8), grub(8), grub.cfg(5)