How to Set Default Entry in Grub2 and Grub

Linux booting is usually controlled by Grub or the new Grub2. Setting the default booting entry is a frequent operations. Here, we introduce how to set the default entry in Grub2 and Grub.

Setting the default booting entry in grub2

Note1: With some version of grub2, the grub2-set-default method and the script below may not work. You can check the “Setting default boot entry for grub2 in /etc/default/grub” method below.

The quick method: download the grub2-select.bash and run

# wget https://www.systutorials.com/go/grub2-select.bash/ -O grub2-select.bash && \
bash grub2-select.bash

and choose the boot entry.

To view the script, please check it on github.

Following is the manual way and what the grub2-select.bash script does.

First of all, find out whether your system is in UEFI or BIOS mode and use different config files accordingly:

if [ -d /sys/firmware/efi ]; then
    grubcfg="/etc/grub2-efi.cfg"
else
    grubcfg="/etc/grub2.cfg"
fi

List all the entries in the grub.cfg by:

# grep ^menuentry $grubcfg | cut -d "'" -f2

Select the default entry by the entry’s name.

For example, the command to set the default entry to be ‘Fedora, with Xen hypervisor’ is as follows.

# grub2-set-default 'Fedora, with Xen hypervisor'

Regenerate the Grub2 config file by:

# grub2-mkconfig -o $grubcfg

We also provide a script in https://www.systutorials.com/how-to-regenerate-grub2-config-file-on-linux/ with which you can directly use to regenerate the Grub2 config file.

Last, verify the default entry is what we just set.

# grub2-editenv list

This should print out what we set.

Setting default boot entry for grub2 in /etc/default/grub

We may also want to change the boot option which is stored in ‘/etc/default/grub’. For example, to set the above entry, change the line for setting GRUB_DEFAULT to

GRUB_DEFAULT="Fedora, with Xen hypervisor"

After editing the file, we can generate the new configuration file for grub2 following https://www.systutorials.com/how-to-regenerate-grub2-config-file-on-linux/.

Setting the default booting entry in grub

The quick method: download the grub-select.bash and run

# bash grub-select.bash

and choose the boot entry.

Following is the manual way.

In grub (before version 2, actually it is usually version 0.99), the default entry is stored in /boot/grub/grub.conf. The default entry to boot is specified by the ‘default’ variable such as

default=2

The ‘2’ here is to set the default entry to be the 2nd (start from 0) one.

Update on Apr. 29, 2015: updated posts with support to both BIOS and UEFI based Linux systems; suggest the grub2-regen-cfg.bash script for re-generating grub2 config file.

Similar Posts

  • Where is the source code for the free command on Linux?

    Where can I find the source code for the free command on Linux? The source code for the free commands (and many more, like kill, ps, top, sysctl) can be found in procps-ng: https://gitlab.com/procps-ng/procps procps is a set of command line and full-screen utilities that provide information out of the pseudo-filesystem most commonly located at…

  • Any suggestion on the hosting service

    Any suggestion on the hosting services? Seems Hostgator is great: http://www.warriorforum.com/internet-marketing-product-reviews-ratings/362470-hostgator-bluehost-dreamhost-pair-com.html I was considering moving to Hostgator from Dreamhost. Dreamhost has less limitations after comparing it with others (e.g. the 250k inodes number limitation). I will stick with it. Moreover, with CloudFlare enabled ( https://www.systutorials.com/b/web/3218/cloudflare-with-dreamhost/ ), it looks better. Read more: Shared hosting services with…

  • Systems Conferences

    Which ones are good systems conferences? Top ones by ACM and USENIX: OSDI: https://www.usenix.org/conferences/byname/179 SOSP: http://sosp.org/ Other SIGOPS Events: http://www.sigops.org/conf-sponsored.html EuroSys: http://www.eurosys.org/ SoCC: http://www.socc2013.org/ (SoCC 2013) ASPLOS: http://www.sigplan.org/Conferences/ASPLOS/Main VEE: http://www.sigplan.org/vee.htm USENIX ATC: https://www.usenix.org/conferences/byname/131 NSDI: https://www.usenix.org/conferences/byname/178 IEEE Conferences: ICDCS: http://www.temple.edu/cis/icdcs2013/ (2013) IPDPS: http://www.ipdps.org/ Other related ones and workshops: HPCA: Search HPCA ConferenceSC: http://www.supercomp.org/IEEE CLUSTER: http://www.clustercomp.org/ HotCloud:…

  • How to exclude users from GDM login screen?

    How to exclude users from appearing in the GDM login screen of Gnome 3? There is a long-time bug related to this ( https://bugzilla.redhat.com/show_bug.cgi?id=723708 ) which causes that the /etc/gdm/custom.conf has no effect. The closes workaround I find working on Fedora 20 is to totally disable listing of users (run as root): cat > /etc/dconf/db/gdm.d/01-mysettings…

5 Comments

  1. Pingback: 配置Diskful Server | 撤退的逃兵
  2. To select a submenu in a menu, e.g. “Fedora, with Linux 3.8.3-103.fc17.x86_64” under “Advanced options for Fedora”:

    # grub2-set-default ‘Advanced options for Fedora>Fedora, with Linux 3.8.3-103.fc17.x86_64’

    Note the ‘>’.

  3. Note that the “grub2-set-default ‘Fedora, with Xen hypervisor'” method may not work for some versions of grub2, you will need to use the ‘/etc/default/grub’ method.

    1. Nice theory. Does not work on my system. ASUS A88XM-A x64-bit Ubuntu MATE 20.04.3 booted by UEFI.

Leave a Reply

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