grub choose default: Step-by-Step Guide for Beginners

Fixing Boot Order with grub choose default — Commands & ExamplesGRUB (GRand Unified Bootloader) is the most widely used bootloader on Linux systems. When you have multiple kernels, operating systems, or recovery entries listed in the GRUB menu, choosing which entry the system boots by default is an important routine task. This article explains how to inspect GRUB entries, use the grub choose default tool and related commands, and automate changes so your chosen entry persists across updates.


What “grub choose default” refers to

There isn’t a single standard utility packaged across every distribution named exactly “grub choose default.” The phrase typically refers to the process of selecting and setting the default GRUB menu entry. Common utilities and methods include:

  • Using grub-set-default and grub-reboot (from the grub2 tools) to set the persistent or one-time default.
  • Editing /etc/default/grub and regenerating the GRUB configuration.
  • Using tools like grub-customizer (graphical) or directly manipulating the GRUB env file (usually /boot/grub/grubenv).
  • Distribution-specific GRUB wrappers or scripts; some distros ship small helper scripts named similarly.

Throughout this article I’ll use the common GRUB tools present on most modern distributions (grub2 / grub-install / grub-mkconfig / grub-set-default / grub-reboot) and explain how the “choose default” workflow works.


Key files and concepts

  • /boot/grub/grub.cfg — The generated configuration read by GRUB at boot. Do not edit this file directly; it is auto-generated.
  • /etc/default/grub — Settings used by the generator (GRUB_TIMEOUT, GRUB_DEFAULT, etc.).
  • /boot/grub/grubenv — A small file used to store environment variables such as saved_entry; updated by grub-set-default and grub-reboot.
  • GRUB_DEFAULT — A setting in /etc/default/grub. Can be a numeric index (0 is first menu entry), a quoted exact menu entry string, or the special value saved to use the value in grubenv (e.g., GRUB_DEFAULT=saved).
  • grub-set-default — Sets the saved default entry (persistent).
  • grub-reboot — Sets the default for the next boot only.
  • grub2-mkconfig (or grub-mkconfig) — Generates grub.cfg from script snippets.

Inspect current GRUB menu entries

  1. View grub.cfg to list menu entries and their indices:

    grep -E "menuentry '.*' --class" /boot/grub/grub.cfg | nl -ba 

    This prints numbered lines, where the first listed entry is index 0. Note: submenu structures (e.g., “Advanced options for …”) affect indexing; entries inside a submenu are still counted sequentially in the file, but referencing them by index can be confusing.

  2. A clearer way to list top-level entries and sub-entries:

    awk -F"'" '/menuentry /{print NR-1 ": " $2}' /boot/grub/grub.cfg 

    Replace NR-1 with a suitable counter if you need zero-based indexing. Manual inspection is often necessary to match the textual menu entry names.


Set the persistent default

Method A — Using a numeric index:

  1. Edit /etc/default/grub to set a static index:
    
    sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=2/' /etc/default/grub 
  2. Regenerate grub.cfg:
    
    sudo grub-mkconfig -o /boot/grub/grub.cfg 

    Note: If GRUB entries change (kernel updates add/remove entries), the index may no longer point to the desired entry.

Method B — Using a menu entry string (more robust):

  1. Find the exact menu entry title from /boot/grub/grub.cfg (include the full string).
  2. Edit /etc/default/grub:
    
    sudo sed -i "s@^GRUB_DEFAULT=.*@GRUB_DEFAULT='Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-xx-generic'@" /etc/default/grub 
  3. Regenerate grub.cfg:
    
    sudo grub-mkconfig -o /boot/grub/grub.cfg 

    Quoting and matching must be exact; mismatches will fall back to index behavior or default 0.

Method C — Use GRUB’s saved mechanism (recommended for dynamic setups):

  1. Tell GRUB to use the saved entry:

    
    sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub 

  2. Regenerate grub.cfg:

    
    sudo grub-mkconfig -o /boot/grub/grub.cfg 

  3. Set the saved entry by name or index:

    sudo grub-set-default 'Ubuntu, with Linux 5.15.0-xx-generic' # or sudo grub-set-default 2 

    This writes the selection into /boot/grub/grubenv so GRUB will boot it by default until you change it.


Set the default for the next boot only

Use grub-reboot to choose a one-time option (handy for testing kernels or recovery):

sudo grub-reboot 'Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-xx-generic' sudo reboot 

This sets grubenv’s next_entry variable; after that boot, GRUB reverts to the saved default.


Examples: common workflows

Example 1 — Make a specific kernel the default persistently:

  1. List entries and copy exact title:
    
    grep -n "menuentry '" /boot/grub/grub.cfg 
  2. Enable saved defaults and set it:
    
    sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub sudo grub-mkconfig -o /boot/grub/grub.cfg sudo grub-set-default 'Ubuntu, with Linux 6.1.0-xx-generic' 

Example 2 — Use index when menu structure is stable:

# Set third entry (index 2) sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=2/' /etc/default/grub sudo grub-mkconfig -o /boot/grub/grub.cfg 

Example 3 — One-off boot to recovery:

sudo grub-reboot 'Advanced options for Ubuntu>Ubuntu, with Linux 6.1.0-xx-generic (recovery mode)' sudo reboot 

Troubleshooting

  • If grub-set-default or grub-reboot seems ignored:
    • Confirm /boot/grub/grubenv is writable and not a symlink to a read-only location.
    • Ensure the string exactly matches the menuentry in grub.cfg, including commas, parentheses, and whitespace.
    • On EFI systems with separate EFI partitions, confirm you’re updating the GRUB used by the firmware (some distros install multiple GRUBs).
  • If using numeric indices, kernel updates may change ordering; prefer saved-by-name when possible.
  • If grub-mkconfig reports errors, inspect /etc/grub.d/* scripts for syntax errors or unexpected output.

Automation tips

  • When deploying across many machines, use grub-set-default with exact titles in a script after kernel upgrades.
  • Use a short-lived cron or systemd timer that checks for a preferred kernel presence and runs grub-set-default accordingly.
  • Store preferred kernel version in a single config file and reference it in your upgrade hooks.

Security and recovery notes

  • Keep a live USB or rescue image handy in case GRUB misconfiguration prevents boot.
  • Be careful when modifying /etc/default/grub and regenerating grub.cfg; a malformed GRUB configuration can block boot.
  • On encrypted systems, changing entries usually only affects the kernel/initramfs selection — unlocking passphrase processes remain the same.

Quick command reference

  • List entries:
    
    grep -n "menuentry '" /boot/grub/grub.cfg 
  • Set persistent default by name:
    
    sudo grub-set-default 'Your exact menuentry string' 
  • Set persistent default by index:
    
    sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=2/' /etc/default/grub sudo grub-mkconfig -o /boot/grub/grub.cfg 
  • Set one-time default:
    
    sudo grub-reboot 'Your exact menuentry string' sudo reboot 

If you want, I can:

  • produce a script that reads the currently installed kernels and sets the newest/stable one as default, or
  • tailor instructions for a specific distribution (Ubuntu, Fedora, Debian, Arch).

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *