How to get grub2 to remember last choice?

Solution 1:

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

The official grub manual describes this correctly: http://www.gnu.org/software/grub/manual/grub.html#Simple-configuration

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

Solution 2:

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
}

Solution 3:

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