安装windows、centos双系统,先安装windows系统,再安装centos系统,windows 版本为windows8,centos版本为centos8,装上centos后无法找到windows启动项
(1)首先要确保windows 分区存在,安装在硬盘的第一个分区上(误删windows分区的同学漂过……)
在root模式下,使用fdisk -l 查看分区表
Disk /dev/sda:465.8 GiB,500107862016 字节,976773168 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x9bc77989
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sda1 * 2048 251662335 251660288 120G 7 HPFS/NTFS/exFAT
/dev/sda2 251662336 976773119 725110784 345.8G f W95 扩展 (LBA)
/dev/sda5 251664384 461381631 209717248 100G 7 HPFS/NTFS/exFAT
/dev/sda6 461383680 719335423 257951744 123G 7 HPFS/NTFS/exFAT
/dev/sda7 719337472 874168319 154830848 73.8G 7 HPFS/NTFS/exFAT
/dev/sda8 874170368 878075903 3905536 1.9G 83 Linux
/dev/sda9 878077952 917139455 39061504 18.6G 83 Linux
/dev/sda10 917141504 936671231 19529728 9.3G 83 Linux
/dev/sda11 936673280 944484351 7811072 3.7G 82 Linux swap / Solaris
/dev/sda12 944486400 973783039 29296640 14G 83 Linux
从上面可以看到4个NTFS分区,第一个分区后是扩展分区。注意第一个分区是120G的NTFS分区,不是笔记本的100M 保留分区
(2)找寻windows启动项
利用自带的操作系统探针找到硬盘上已存在的操作系统,文件是/etc/grub.d/30_os-prober(有兴趣的同学可以看下如何实现的,版本grub2-mkconfig (GRUB) 2.03)
[root@localhost meng]# grub2-mkconfig -o /boot/grub2/grub.cfg
或者
[root@localhost grub.d]# grub2-mkconfig --output=/boot/grub2/grub.cfg
Generating grub configuration file ...
Found Windows 8 on /dev/sda1
done
从上面输出可以看到,找到的启动项为 Windows 8 on /dev/sda1,此启动项在/boot/grub2/grub.cfg 的位置位于
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
这两行之间
(3)如第二步没有找到启动项,可手动添加
vim /etc/grub.d/40_custom 文件,在末尾追加以下内容:
menuentry 'Windows 8'{
set root='hd0,msdos1'
chainloader +1
}
保存后使用上述两个命令更新grubcfg(版本grub2-mkconfig (GRUB) 2.03)
(4)设置默认启动项:
重启系统,查看启动项个数,一般情况下共有3个(序号从0开始)
Centos Linux(4.18.8-147.e18.x86_64) 8 Core
Centos Linux(0-rescue-d1c351bfd1b64aa58a9dc29f7159a1aa)8 Core
Windows 8 on /dev/sda1
grub2-set-default 2
此步要求 /etc/default/grub 文件下需要有此项:
GRUB_DEFAULT=saved
看grub2-set-default 2备注:
Set the default boot menu entry for GRUB.
This requires setting GRUB_DEFAULT=saved in /etc/default/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.
后面的参数可以是数字,也可以启动项标题或启动项标识符。我们这里使用的数字。
一般情况下/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="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=10a232bf-2bbd-45c1-ab3d-53940ad2314a rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
从文件可以看出第3行即是我们需要的行,第一行是启动时的停留时间。当然也可以直接修改第三行和第一行,修改后一定使用grub2-mkconfig 更新grub.cfg,否则重启无效。
(5)不建议直接修改/boot/grub2/grub.cfg 配置文件
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
备注里有:这个文件是从文件/etc/grub.d和/etc/default/grub的模板使用grub2-mkconfig命令自动生成的。注意:修改这两个目录下的任何文件,都需要使用grub2-mkconfig 更新grub.cfg,否则重启无效
参考资料:
(1)https://blog.csdn.net/shuai9201/article/details/80455648