30 grub2
我在 Gentoo Linux 系统上运行 GRUB 2.00。
我手动编译自己的内核,然后/boot
使用make install
. 我目前有以下内核/boot
:
# ls -1 /boot/vmlinuz*
/boot/vmlinuz-3.7.4-gentoo-5
/boot/vmlinuz-3.7.4-gentoo-first
/boot/vmlinuz-3.7.4-gentoo-fourth
/boot/vmlinuz-3.7.4-gentoo-third
Run Code Online (Sandbox Code Playgroud)
运行grub2-mkconfig
结果如下:
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.7.4-gentoo-third
Found linux image: /boot/vmlinuz-3.7.4-gentoo-fourth
Found linux image: /boot/vmlinuz-3.7.4-gentoo-first
Found linux image: /boot/vmlinuz-3.7.4-gentoo-5
done
Run Code Online (Sandbox Code Playgroud)
如果我现在阅读生成的/boot/grub2/grub.cfg
文件,我会注意到已创建以下条目:
vmlinuz-3.7.4-gentoo-third
grub2-mkconfig
命令相同问题是在启动时我想默认加载内核的第五个修订版 ( vmlinuz-3.7.4-gentoo-5
),而不是第三个 ( vmlinuz-3.7.4-gentoo-third
)。我也不想访问子菜单来选择要加载的正确内核。
我怎样才能改变这种行为?我如何告诉 GRUB 我想默认运行内核的第五个修订版而不是旧的第三个修订版?一般来说,如何更改默认输入行以匹配我想要的内核而不是 GRUB 选择的看似随机的内核?
我还尝试将以下几行放入/etc/default/grub
:
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
Run Code Online (Sandbox Code Playgroud)
这并没有按照我想要的方式解决问题。但至少 GRUB 似乎记住了我从中启动的最新内核并自动从子菜单中选择它。只是我不喜欢访问子菜单。
小智 14
要选择子菜单“高级选项”下的菜单项,请设置 GRUB_DEFAULT="1>3"。您现在可以运行 grub2-mkconfig 来生成 grub 配置文件。下次重启时 vmlinuz-3.7.4-gentoo-5 应该会启动。
注意:这不会更改 grub 菜单中的默认条目,即默认条目仍会指示您现在拥有的相同条目。但是默认启动的映像将是“高级选项”下的第 4 个映像。要使 vmlinuz-3.7.4-gentoo-5 作为 grub 菜单中的默认条目,图像的顺序应该是 vmlinuz-3.7.4-gentoo-5 应该是您运行 grub2-mkconfig 时的第一个图像.
Ast*_*erg 10
如果您的 grub.cfg 中有一个子菜单,您应该使用这样的两位数字:
grub-reboot '1>3'
Run Code Online (Sandbox Code Playgroud)
第一个是菜单索引,第二个是子菜单索引。
例如,从配置启动最后一个条目,如下所示:
grep menu /boot/grub/grub.cfg
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 4.6.0-0.bpo.1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.6.0-0.bpo.1-amd64-advanced-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 4.6.0-0.bpo.1-amd64 (sysvinit)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.6.0-0.bpo.1-amd64-init-sysvinit-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 4.6.0-0.bpo.1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.6.0-0.bpo.1-amd64-recovery-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 3.16.0-4-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.16.0-4-amd64-advanced-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 3.16.0-4-amd64 (sysvinit)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.16.0-4-amd64-init-sysvinit-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
menuentry 'Debian GNU/Linux, with Linux 3.16.0-4-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.16.0-4-amd64-recovery-1ffa16a9-fda2-43b5-91b9-c91a08ff190f' {
Run Code Online (Sandbox Code Playgroud)
你应该使用:
grub-reboot '1>5'
Run Code Online (Sandbox Code Playgroud)
并重新启动。
小智 8
使用centos7(或RHEL7)和grub2:
grub 使用 grubenv 中的“saved_entry”条目作为默认引导,来自 /boot/grub2/grub.cfg 的片段:
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi
Run Code Online (Sandbox Code Playgroud)
检查“saved_entry”现在是什么我的构建:
grub2-editenv list
Run Code Online (Sandbox Code Playgroud)
saved_entry=CentOS Linux (3.10.0-693.2.2.el7.ari.x86_64) 7 (Core)
将其更改为我的调试版本:
grub2-editenv - set saved_entry='CentOS Linux 3.10.0-693.2.2.el7.ari.x86_64.debug) 7 (Core)'
Run Code Online (Sandbox Code Playgroud)
小智 5
你也可以使用GRUB_DEFAULT=saved
. 在这种情况下,你会使用
$ grub2-set-default -h
Usage: grub2-set-default [OPTION] MENU_ENTRY
Set the default boot menu 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/grub2
instead of the /boot/grub2 directory
MENU_ENTRY is a number, a menu item title or a menu item identifier.
Run Code Online (Sandbox Code Playgroud)
或者如果它仅用于下次启动:
$ grub2-reboot -h
Usage: grub2-reboot [OPTION] MENU_ENTRY
Set the default boot menu entry for GRUB, for the next boot only.
-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/grub2
instead of the /boot/grub2 directory
MENU_ENTRY is a number, a menu item title or a menu item identifier.
Run Code Online (Sandbox Code Playgroud)
您可以通过数值设置默认选择。如果你设置
`GRUB_DEFAULT=3`
Run Code Online (Sandbox Code Playgroud)
您/etc/default/grub
将把默认值设置为 gentoo-5 条目。
GRUB_DEFAULT
是零偏移,因此 3 将根据需要选择第四个条目。
归档时间: |
|
查看次数: |
83822 次 |
最近记录: |