导读 GRUB2是Centos7的默认引导加载程序。它可以轻松地加载所有的Linux发行版和其他操作系统。它提供一个菜单显示所有的操作系统。GRUB2具有高级特性以及一些基本特性,使其在所有Linux上都有效。
如何添加Windows 10启动项到GRUB2

装的双系统,第一个系统装的是Windows 10,然后再安装Centos7。装完Centos7发现没有Windows 10的启动项,这时候需要手动添加windows 10的启动项。

# 打开40_custom文件,添加如下内容
[root@localhost ~]# vim /etc/grub.d/40_custom

menuentry 'Windows 10' {
        insmod ntfs
        set root='hd0,1'
        chainloader +1
}
# 修改完成之后,需要导出生成配置文件,这样才能生效。
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

重启电脑,检查一下是否有Windows 10启动项

如何更改默认启动项
列出所有启动项
[root@localhost ~]# grep '^menuentry' /boot/grub2/grub.cfg |cut -d "'" -f 2
CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-2fbe0839e3b3416b960e84dab68c8bb3) 7 (Core)
Windows 10

修改Windows10作为默认启动项
[root@localhost ~]# grub2-set-default "Windows 10"
检查是否设置成功
[root@localhost ~]# grub2-editenv list
saved_entry=Windows 10

保存更改
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-2fbe0839e3b3416b960e84dab68c8bb3
Found initrd image: /boot/initramfs-0-rescue-2fbe0839e3b3416b960e84dab68c8bb3.img
done

如何更改grub2菜单的超时时间

打开/etc/default/grub文件,修改GRUB_TIMEOUT变量值,变量的值是秒数。

[root@localhost ~]# vim /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_BACKGROUND=/boot/grub2/background.jpg
GRUB_GFXMODE=1440x900,1024x768,640x480
GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true" 


保存生成配置文件

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-2fbe0839e3b3416b960e84dab68c8bb3
Found initrd image: /boot/initramfs-0-rescue-2fbe0839e3b3416b960e84dab68c8bb3.img
done

总结

在这片文章中,讲述了如何添加grub引导记录、修改超时时间、修改默认启动项。如果喜欢这篇文章,可以点个赞。

本文原创地址:https://www.linuxprobe.com/centos7-grub2-boot-option.html编辑:倪家兴,审核员:逄增宝