How to set the Grub2 default boot entry

AIO Boot supports users to set the Grub2 default boot entry directly from the menu. This article will guide you how to do that.

By default, Grub2 will select the first menu and will automatically boot into that menu entry if the user does not take any action within the timeout period. If you want Grub2 to automatically boot into another, just set it as the default.

How to

Because some entry only support Legacy or UEFI, you need to set them separately for each mode.

  1. Boot into the Grub2 menu of AIO Boot.
  2. Go to the menu entry that you want to set as the default. Press “e” key to temporarily modify this entry. For example below, I will set the Grub4dos entry as the default.
    Grub2 default boot entry
  3. Insert the following code into the second line (blank line):
    setdefault "$1"

    Grub2 default menu entry

  4. Press “F10“. Now that entry has been set as default.

If you are not using AIO Boot’s Grub2, add or modify (grub.cfg) the following code (grub.cfg):

if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   if [ x"${saved_entry}" = x ] ; then
      set default="0"
   else
      set default="${saved_entry}"
   fi
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

Add “savedefault” to the menuentry that you want to set as the default:

menuentry "Windows" {
   savedefault ### <<<< this must be added
   set root="(hd1,msdos1)"
   chainloader +1
}

Timeout

By default when booting Grub2, it will automatically boot into the default entry after 15 seconds if there is no action from you. You can change it by changing the value of timeout.

Grub2 timeout

  1. From Grub2 main menu, choose Help, then Timeout.
  2. Enter the number of seconds (0 = immediately).

 

Leave a Reply

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