165

Grub2 - Community Ubuntu Documentation says the following:

Saving an OS can be achieved by running sudo grub-set-default if DEFAULT=saved is set in /etc/default/grub. It may also be saved if GRUB_SAVEDEFAULT=true is also set in /etc/default/grub. In this case, the default OS remains until a new OS is manually selected from the GRUB 2 menu or the grub-set-default command is executed.

I put the lines DEFAULT=saved AND GRUB_SAVEDEFAULT=true in /etc/default/grub, and ran sudo grub-set-default. Here is the output:

$ sudo grub-set-default
entry not specified.
Usage: grub-set-default [OPTION] entry
Set the default boot entry for GRUB.

  -h, --help              print this message and exit
  -v, --version           print the version information and exit
  --boot-directory=DIR    expect GRUB images under the directory DIR/grub
                          instead of the /boot/grub directory

ENTRY is a number or a menu item title.

Report bugs to <bug-grub@gnu.org>.

Am I not following the documentation correctly? What's the correct way to do this?

Lucio
  • 18,843
Jay Sullivan
  • 1,989

5 Answers5

253

The documentation in this case is wrong. All variables in /etc/default/grub start with GRUB_, so the correct syntax is GRUB_DEFAULT=saved, not DEFAULT=saved. I've corrected the Ubuntu wiki to reflect that.

The official grub manual describes this correctly.
Put the following in /etc/default/grub (command line: gedit admin:///etc/default/grub):

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

Then run:

sudo update-grub
zx485
  • 2,426
Jordan Uggla
  • 4,565
  • 7
    +1 for the link, I've edited your answer with the solution that worked for me (which I derived from the link you provided) – Jay Sullivan Jun 18 '12 at 17:47
  • 1
    should I remove existing line GRUB_DEFAULT=0 ? – user25 Jun 02 '18 at 14:01
  • 3
    @user25 yes remove GRUB_DEFAULT=0, the line should read GRUB_DEFAULT=saved – ctrl-alt-delor Jan 02 '19 at 21:14
  • I reboot into windows from linux using the above command. But now when i reboot from Windows, it defaults to windows and I cannot reboot from Windows into Linux – revolutionary Nov 16 '19 at 23:15
  • @revolutionary You can change it from boot options (F12) during boot. – VidathD Jun 10 '20 at 14:23
  • If it's still not working for you double check you have GRUB_SAVEDEFAULT and not GRUB_SAVEDDEFAULT (notice the extra 'D', it's not "saved_default", it's "save_default"). Been wondering why this wasn't working for me. – GrayedFox Sep 15 '21 at 17:16
  • If you are using Ubuntu Studio, the package 'ubuntustudio-lowlatency-settings' forces the prioritization of the lowlatency kernel over the generic kernel, so you might be seeing that. If you uninstall that, it'll fix that, but you'll also lose "threadirqs" and other lowlatency optimizations.

    My solution has been to use GRUB_DEFAULT=1, for example, instead of saved. I can't use the saved function without uninstalling this package

    – semitones Apr 20 '23 at 21:11
13

In my case it was not working for entries defined via /etc/grub.d/40_custom which were missing the savedefault line.

menuentry "Chameleon" {
    savedefault ### <<<< this must be added
    set root="(hd1)"
    chainloader +1
}
ccpizza
  • 1,452
  • 17
  • 18
5

savedefault will not work, if there is no proper header in auto generated grub.cfg

To generate proper header you need set in /etc/default/grub

GRUB_DEFAULT=saved

and make grub-mkconfig to substitute your copy of grub.cfg

grub-mkconfig -o /boot/grub.cfg

savedefault from Grub 2.02 don't require any additional arguments

You could see source of savedefault in grub.cfg

Dblmok
  • 51
4

You are forgetting the number (ie. the "ENTRY is a number or a menu item title." in your text).

sudo grub-set-default 1

for option 1 to be the default.

Always run sudo update-grub after modifying the /etc/default/grub file to apply the changes.

ish
  • 139,926
Rinzwind
  • 299,756
  • 7
    This did not work for me, it just sets the GRUB menu to point to entry #1, not the last choice – Jay Sullivan Jun 18 '12 at 17:47
  • If your menu option would be buried in a submenu, like within 'Advanced options for ubuntu', the format is 'submenu-index>submenu-item-index'. So you'd need to specify 1>'index-of-your-choice'. You are also supposed to be able to specify by string name for each selection. – Epu Nov 30 '15 at 20:29
2

Thanks to ccpizza I figured out, that my Windows-menuentry in /etc/grub.d/40_custom was missing the savedefault Attribute:

menuentry 'Windows 10' {
    savedefault    # <<<<<<<<<<<< THIS Attribute was missing!
    insmod ntfs
    insmod ntldr
    insmod part_msdos
    insmod search_fs_uuid
    search --fs-uuid --no-floppy --set=root <WINDOWS_SSD_UUID>
    ntldr /bootmgr
}

In my case (Arch Linux, not Ubuntu ;) ) I found pacman -S grub-customizer (from this Post on StackOverflow of matt-u) which is a nice GUI Tool for customizing GRUB-Menu!

PS: I could neither upvote nor comment on ccpizza's answer because of missing credits in this forum, so I decided to give another answer :(

Pokulo
  • 21
  • While the accepted answer is probably more relevant, this is what got my config running properly. Thanks! – SPRBRN Feb 15 '21 at 11:45