如何让grub2记住最后的选择?

Grub2 – 社区Ubuntu文档说明如下:

如果在/ etc / default / grub中设置了DEFAULT = saved,则可以通过运行sudo grub-set-default来保存操作系统。 如果在/ etc / default / grub中也设置了GRUB_SAVEDEFAULT = true,也可以保存它。 在这种情况下,默认操作系统将保留,直到从GRUB 2菜单中手动选择新操作系统或执行grub-set-default命令。

我在/etc/default/grub放置了DEFAULT=saved AND GRUB_SAVEDEFAULT=true行,并运行了sudo grub-set-default 。 这是输出:

 $ 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 . 

我没有正确地遵循文件吗? 这样做的正确方法是什么?

这种情况下的文档是错误的。 /etc/default/grub所有变量都以GRUB_ ,因此它是GRUB_DEFAULT=saved而不是 DEFAULT=saved 。 我已经纠正了Ubuntu维基以反映这一点。

官方grub手册正确描述了这一点: http : //www.gnu.org/software/grub/manual/grub.html#Simple-configuration

将以下内容放在/etc/default/grub

 GRUB_DEFAULT=saved GRUB_SAVEDEFAULT=true 

然后运行:

 sudo update-grub 

您忘记了数字(即文本中的“ENTRY是数字或菜单项标题。”)。

 sudo grub-set-default 1 

选项1是默认值。

始终在修改/etc/default/grub文件后运行sudo update-grub以应用更改。

在我的情况下,它不适用于通过/etc/grub.d/40_custom定义的条目,它们缺少savedefault行。

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

如果自动生成的grub.cfg中没有正确的标头,savedefault将无法工作

要生成正确的标头,您需要在/ etc / default / grub中设置

 GRUB_DEFAULT=saved 

并使grub-mkconfig替换你的grub.cfg副本

 grub-mkconfig -o /boot/grub.cfg 

来自Grub 2.02的savedefault不需要任何其他参数

你可以在grub.cfg中看到savedefault的来源