安装linux没有引导程序,Windows7或10安装Centos双系统无法引导最佳解决方案(根据Grub官方文档)...

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

1.添加Windows引导配置

打开/etc/grub.d/40_custom,添加以下代码:

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.

2.使刚刚编辑的配置文件生效。

打开CentOS终端,运行以下代码:

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.

细心的网友会发现怎么我们多了一个数字2,因为现在已经是Grub2了,所以我们我们用Grub2这个。

重启,您就会发现成功了。

3.设置默认引导的操作系统

有些网友表示,平常CentOS不怎么使用,用Windows的频次多,不想让CentOS占了默认启动项。

打开/etc/default/grub

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

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

官方文档如下:

‘GRUB_DEFAULT’

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:

GRUB_DEFAULT=example-gnu-linux

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).

至此全部完成配置,恭喜您成功了。

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/experience/linux/923.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值