笔者最近有需求要做一个Windows7或者10和CentOS的双系统,发现CentOS做完以后,Windows7或者10的启动菜单消失了,以为Windows系统盘被CentOS给吃了,经过一番检查以后发现MBR上的引导程序(boot loader),centos采用的grub2,覆盖了原有windows的引导程序 ,经过网上一番查询,基本分为两种解决方案,一种方案是进PE盘用引导修复程序覆盖CentOS的引导程序,然后再用启动配置程序把CentOS的引导添加进来,另外一种方案是进CentOS修改引导配置文件,添加Windows引导。笔者对于第一种方法并不喜欢,因为对于没有PE盘的朋友就麻烦了,对于第二种方法又不敢乱复制代码,防止有错误导致CentOS都进不去,于是经过Grub官网的一番查询,总结如下:



menuentry "Windows 7" {
	insmod chain
	insmod ntfs
	set root=(hd0,1)
	chainloader +1


如果您是Windows 10,把Windows 7处修改。

insmod意思是加载chain模块,insmod ntfs意思是加载ntfs文件系统模块。

set root=(hd0,1) 其中 hd0 表示硬盘,1 表示C盘 ,我的win7装在C盘所以是1 。

保存,如遇不能保存麻烦以root账户登陆系统,可以在CentOS的桌面的右上角选择注销当前用户然后使用root用户名登录即为最高权限 。


5.1.2 Chain-loading an OS

Operating experiences that do not support Multiboot and do not have specific support in GRUB (specific support is available for Linux, FreeBSD, NetBSD and OpenBSD) must be chain-loaded, which involves loading another boot loader and jumping to it in real mode.

The chainloader command (see chainloader) is used to set this up. It is normally also necessary to load some GRUB modules and set the appropriate root device. Putting this together, we get something like this, for a Windows experience on the first partition of the first hard disk:

menuentry "Windows" {
	insmod chain
	insmod ntfs
	set root=(hd0,1)
	chainloader +1

On experiences with multiple hard disks, an additional workaround may be required. See DOS/Windows.

Chain-loading is only supported on PC BIOS and EFI platforms.



grub2-mkconfig -o /boot/grub2/grub.cfg


24 Invoking grub-mkconfig

The program grub-mkconfig generates a configuration file for GRUB (see Simple configuration).

grub-mkconfig -o /boot/grub/grub.cfg

grub-mkconfig accepts the following options:–help

Print a summary of the command-line options and exit.–version

Print the version number of GRUB and exit.-o file–output=file

Send the generated configuration file to file. The default is to send it to standard output.






注释掉GRUB_DEFAULT=saved,在这一行的下面插入GRUB_DEFAULT=’Windows 7’,保存并退出。(注意这个要根据/etc/grub.d/40_custom中自己设置的menuentry配置,务必一样)

执行grub2-mkconfig -o /boot/grub2/grub.cfg,最后reboot重启



The default menu entry. This may be a number, in which case it identifies the Nth entry in the generated menu counted from zero, or the title of a menu entry, or the special string ‘saved’. Using the id may be useful if you want to set a menu entry as the default even though there may be a variable number of entries before it.

For example, if you have:

menuentry 'Example GNU/Linux distribution' --class gnu-linux --id example-gnu-linux {

then you can make this the default using:


Previously it was documented the way to use entry title. While this still works it’s not recommended since titles often contain unstable device names and may be translated

If you set this to ‘saved’, then the default menu entry will be that saved by ‘GRUB_SAVEDEFAULT’ or grub-set-default. This relies on the environment block, which may not be available in all situations (see Environment block).

The default is ‘0’.‘GRUB_SAVEDEFAULT’

If this option is set to ‘true’, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. This is only useful if ‘GRUB_DEFAULT=saved’; it is a separate option because ‘GRUB_DEFAULT=saved’ is useful without this option, in conjunction with grub-set-default. Unset by default. This option relies on the environment block, which may not be available in all situations (see Environment block).



上一篇 2020年2月6日 00:42
下一篇 2020年2月18日 18:12