Change GRUB2 default boot target

      2 Comments on Change GRUB2 default boot target

In GRUB, the default boot menu entry was determined by the order of entries in /boot/grub/menu.lst, the default one being the n-th specified by the default=n parameter.

In GRUB2 the main configuration file /boot/grub2/grub.cfg isn’t usually altered manually any more but automatically generated by invoking grub2-mkconfig. You can change the default boot target by changing the GRUB_DEFAULT paramater in /etc/default/grub. It takes three different values:

GRUB_DEFAULT=n specifies the n-th entry in /boot/grub2/grub.cfg. The first entry is selected with GRUB_DEFAULT=0, just like in GRUB.

GRUB_DEFAULT="String" chooses an entry by name (e.g. “Fedora (3.5.3-1.fc17.x86_64)”)

GRUB_DEFAULT=saved chooses the boot target specified in /boot/grub/grubenv regardless whether the order of entries has changed (e.g. due to a kernel update).

To manipulate /boot/grub/grubenv, you can list all possible entries

grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2

and specify the desired one with

grub2-set-default <menu entry title>

To verify the default menu entry, use

grub2-editenv list

Note that you have to run

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

if you make any changes to /etc/default/grub (e.g. change the GRUB_DEFAULT parameter). You don’t have to invoke it, if you just change the default target with grub2-set-default since this just alters grubenv but doesn’t make any changes to grub.cfg.

Resources:
http://fedoraproject.org/wiki/GRUB_2
http://www.linuxreaders.com/2011/11/fedora-16-how-to-change-boot-sequence-grub2.html

2 thoughts on “Change GRUB2 default boot target

  1. avatarShem

    This is really helpful, thank you! GRUB2 sometimes behaves quite strangely with its default behaviour, so the two commands to directly edit and update the settings makes testing straightforward.

  2. Pingback: GRUB2 ! My cheat sheet |

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.