LinuxCommandLibrary

grub-set-default

Set the default GRUB boot entry

TLDR

Set the default boot entry to an entry number, name, or identifier

$ sudo grub-set-default [entry_number]
copy

Set the default boot entry to an entry number, name, or identifier for an alternative boot directory
$ sudo grub-set-default --boot-directory /[path/to/boot_directory] [entry_number]
copy

SYNOPSIS

grub-set-default [OPTION...] NEW_DEFAULT_ENTRY

PARAMETERS

--help
    print this message and exit

--version
    print the version information and exit

DESCRIPTION

The grub-set-default command is a utility from the GRUB 2 bootloader suite used to configure the default boot menu entry. GRUB (GRand Unified Bootloader) is the standard bootloader for most Linux distributions, handling multi-boot environments, kernel selection, and boot parameters.

This command sets the GRUB_DEFAULT or saved_entry variable in the GRUB environment block, typically stored in /boot/grub/grubenv. Users specify the new default using either a zero-based numeric index (e.g., 0 for the first entry) or the exact menu entry title enclosed in double quotes (e.g., "Ubuntu"). Changes persist across reboots, making it ideal for dual-boot systems, kernel switching, or preferring specific OS installations.

To use, run as root: sudo grub-set-default 1 to default to the second entry. List entries first with grep menuentry /boot/grub/grub.cfg. The environment file must exist; create it via grub-editenv create if needed. Supports custom paths via GRUB_ENV variable. Exit status 0 on success, non-zero on errors like invalid entry or permissions.

Common in scripts for automated boot management, but verify grub.cfg matches current menu before applying.

CAVEATS

Requires root privileges (use sudo). GRUB environment block (/boot/grub/grubenv) must exist; create with grub-editenv create. Entry must match current grub.cfg menu exactly, or boot fails. Not for temporary changes (use grub-reboot).

EXAMPLES

sudo grub-set-default 0
Sets first menu entry as default.

sudo grub-set-default "Ubuntu GNU/Linux"
Sets specific titled entry.

ENVIRONMENT

GRUB_ENV: Path to environment file (default: /boot/grub/grubenv). Modifies saved_entry variable.

HISTORY

Introduced in GRUB 2 (2009+), replacing GRUB Legacy methods. Developed by GNU GRUB maintainers for persistent environment storage via non-volatile blocks, integrated in distros like Ubuntu (grub2-common) and Fedora.

SEE ALSO

Copied to clipboard