本文共 3299 字,大约阅读时间需要 10 分钟。
grub2设置默认启动项
booting is usually controlled by Grub or the new Grub2. Setting the default booting entry is a frequent operations. Here, we introduce how to set the default entry in Grub2 and Grub.
引导通常由Grub或新的Grub2控制。 设置默认启动项是一项常见的操作。 在这里,我们介绍如何在Grub2和Grub中设置默认条目。
Note1: With some version of grub2, the grub2-set-default method and the script below may not work. You can check the “Setting default boot entry for grub2 in /etc/default/grub” method below.
注意1 :对于某些版本的grub2,grub2-set-default方法和下面的脚本可能不起作用。 您可以检查下面的“在/ etc / default / grub中为grub2设置默认启动项”。
The quick method: download the and run
快速方法:下载并运行
# wget https://www.systutorials.com/go/grub2-select.bash/ -O grub2-select.bash && \bash grub2-select.bash
and choose the boot entry.
并选择启动项。
To view the script, please check it .
要查看脚本,请检查。
Following is the manual way and what the grub2-select.bash
script does.
以下是手动方式以及grub2-select.bash
脚本的作用。
First of all, find out whether your system is in UEFI or BIOS mode and use different config files accordingly:
首先,找出您的系统是处于UEFI还是BIOS模式,并相应地使用不同的配置文件:
if [ -d /sys/firmware/efi ]; then grubcfg="/etc/grub2-efi.cfg"else grubcfg="/etc/grub2.cfg"fi
List all the entries in the grub.cfg by:
通过以下方式列出grub.cfg中的所有条目:
# grep ^menuentry $grubcfg | cut -d "'" -f2
Select the default entry by the entry’s name.
通过条目名称选择默认条目。
For example, the command to set the default entry to be ‘Fedora, with Xen hypervisor’ is as follows.
例如,将默认条目设置为“带有Xen虚拟机管理程序的Fedora”的命令如下。
# grub2-set-default 'Fedora, with Xen hypervisor'
Regenerate the Grub2 config file by:
通过以下方式重新生成Grub2配置文件:
# grub2-mkconfig -o $grubcfg
We also provide a script in with which you can directly use to regenerate the Grub2 config file.
我们还在“ 提供了一个脚本,您可以直接使用该脚本来重新生成Grub2配置文件。
Last, verify the default entry is what we just set.
最后,验证默认条目就是我们刚刚设置的内容。
# grub2-editenv list
This should print out what we set.
这应该打印出我们设置的内容。
We may also want to change the boot option which is stored in ‘/etc/default/grub’. For example, to set the above entry, change the line for setting GRUB_DEFAULT
to
我们可能还想更改存储在“ / etc / default / grub”中的引导选项。 例如,要设置上面的条目,请将用于设置GRUB_DEFAULT
的行更改为
GRUB_DEFAULT="Fedora, with Xen hypervisor"
After editing the file, we can generate the new configuration file for grub2 following .
编辑完文件后,我们可以按照配置文件的方式为grub2生成新的配置文件。
The quick method: download the and run
快速方法:下载并运行
# bash grub-select.bash
and choose the boot entry.
并选择启动项。
Following is the manual way.
以下是手动方式。
In grub (before version 2, actually it is usually version 0.99), the default entry is stored in /boot/grub/grub.conf. The default entry to boot is specified by the ‘default’ variable such as
在grub(版本2之前,实际上通常是0.99版本)中,默认条目存储在/boot/grub/grub.conf中。 引导的默认条目由“ default”变量指定,例如
default=2
The ‘2’ here is to set the default entry to be the 2nd (start from 0) one.
此处的“ 2”将默认条目设置为第二个(从0开始)。
Update on Apr. 29, 2015: updated posts with support to both BIOS and UEFI based Linux ; suggest the grub2-regen-cfg.bash script for re-generating grub2 config file.
2015年4月29日更新:更新了帖子,同时支持基于BIOS和UEFI的Linux ; 建议使用grub2-regen-cfg.bash脚本重新生成grub2配置文件。
翻译自:
grub2设置默认启动项
转载地址:http://uhowd.baihongyu.com/