关于Centos使用grub无法引导Windows的解决办法
今天在给小组同学装系统时,按惯例,都使用的是linux来引导windows的,因此就先将win 7安装了,后来,就来配置windowns的相关设置,配完后,就开始装Centos了,期间在分盘的时候,还失败了两次,显示的都是由于安装器出现bug了,这都是小插曲,最后还是装成功了,但是,使用命令grub2-mkconfig却无法找到win 7的引导,于是我就着急了,最后通过我的摸索,终于找到了解决方法,下面分享一下:
[root@localhost:~]$ grub2-mkconfig
Generating grub configuration file ...
#
# 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 ###
set pager=1
if [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi
export menuentry_id_option
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
terminal_output console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=5
fi
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
### END /etc/grub.d/00_tuned ###
### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
fi
### END /etc/grub.d/01_users ###
### BEGIN /etc/grub.d/10_linux ###
Found linux image: /boot/vmlinuz-3.10.0-327.10.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.10.1.el7.x86_64.img
menuentry 'CentOS Linux (3.10.0-327.10.1.el7.x86_64) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.10.1.el7.x86_64-advanced-dfffd217-84d7-40cc-8ab9-83f43218c6a6' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos10'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos10 --hint-efi=hd0,msdos10 --hint-baremetal=ahci0,msdos10 --hint='hd0,msdos10' f15778cb-939a-4179-beeb-62e5c3dc07db
else
search --no-floppy --fs-uuid --set=root f15778cb-939a-4179-beeb-62e5c3dc07db
fi
linux16 /vmlinuz-3.10.0-327.10.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
initrd16 /initramfs-3.10.0-327.10.1.el7.x86_64.img
}
Found linux image: /boot/vmlinuz-3.10.0-327.3.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.3.1.el7.x86_64.img
menuentry 'CentOS Linux (3.10.0-327.3.1.el7.x86_64) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.3.1.el7.x86_64-advanced-dfffd217-84d7-40cc-8ab9-83f43218c6a6' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos10'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos10 --hint-efi=hd0,msdos10 --hint-baremetal=ahci0,msdos10 --hint='hd0,msdos10' f15778cb-939a-4179-beeb-62e5c3dc07db
else
search --no-floppy --fs-uuid --set=root f15778cb-939a-4179-beeb-62e5c3dc07db
fi
linux16 /vmlinuz-3.10.0-327.3.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
initrd16 /initramfs-3.10.0-327.3.1.el7.x86_64.img
}
Found linux image: /boot/vmlinuz-3.10.0-229.20.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.20.1.el7.x86_64.img
menuentry 'CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.20.1.el7.x86_64-advanced-dfffd217-84d7-40cc-8ab9-83f43218c6a6' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos10'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos10 --hint-efi=hd0,msdos10 --hint-baremetal=ahci0,msdos10 --hint='hd0,msdos10' f15778cb-939a-4179-beeb-62e5c3dc07db
else
search --no-floppy --fs-uuid --set=root f15778cb-939a-4179-beeb-62e5c3dc07db
fi
linux16 /vmlinuz-3.10.0-229.20.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
initrd16 /initramfs-3.10.0-229.20.1.el7.x86_64.img
}
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
menuentry 'CentOS Linux (3.10.0-229.el7.x86_64) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.el7.x86_64-advanced-dfffd217-84d7-40cc-8ab9-83f43218c6a6' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos10'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos10 --hint-efi=hd0,msdos10 --hint-baremetal=ahci0,msdos10 --hint='hd0,msdos10' f15778cb-939a-4179-beeb-62e5c3dc07db
else
search --no-floppy --fs-uuid --set=root f15778cb-939a-4179-beeb-62e5c3dc07db
fi
linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
}
Found linux image: /boot/vmlinuz-0-rescue-98a0f723fa374bccae65d892478a1677
Found initrd image: /boot/initramfs-0-rescue-98a0f723fa374bccae65d892478a1677.img
menuentry 'CentOS Linux (0-rescue-98a0f723fa374bccae65d892478a1677) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-98a0f723fa374bccae65d892478a1677-advanced-dfffd217-84d7-40cc-8ab9-83f43218c6a6' {
load_video
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos10'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos10 --hint-efi=hd0,msdos10 --hint-baremetal=ahci0,msdos10 --hint='hd0,msdos10' f15778cb-939a-4179-beeb-62e5c3dc07db
else
search --no-floppy --fs-uuid --set=root f15778cb-939a-4179-beeb-62e5c3dc07db
fi
linux16 /vmlinuz-0-rescue-98a0f723fa374bccae65d892478a1677 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
initrd16 /initramfs-0-rescue-98a0f723fa374bccae65d892478a1677.img
}
if [ "x$default" = 'CentOS Linux (3.10.0-327.10.1.el7.x86_64) 7 (Core)' ]; then default='Advanced options for CentOS Linux 7 (Core)>CentOS Linux (3.10.0-327.10.1.el7.x86_64) 7 (Core)'; fi;
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f ${config_directory}/custom.cfg ]; then
source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
done
仔细查看一下,并没有win 7的引导出现,我突然想到了,centos默认无法识别ntfs格式的磁盘,于是,就想着能不能将C盘挂载后不就可以找到了吗?也许吧。
网上查了一下,可以使用ntfs-3g来在centos下面挂载ntfs格式的磁盘,于是,就去百度ntfs的下在链接,注意,戳这里:ntfs-3g下载,然后:
[zhoupan@localhost:~]$ tar -zvx -f ntfs-3g-1.328.tgz -C .
ntfs-3g-1.328/
ntfs-3g-1.328/AUTHORS
ntfs-3g-1.328/CREDITS
ntfs-3g-1.328/Makefile.am
ntfs-3g-1.328/NEWS
ntfs-3g-1.328/README
ntfs-3g-1.328/autogen.sh
.....信息较多,下面省略
[zhoupan@localhost:~]$ cd ntfs-3g-1.328/
[zhoupan@localhost:~/ntfs-3g-1.328]$ ls
aclocal.m4 autogen.sh compile config.h.in configure COPYING depcomp INSTALL libntfs-3g Makefile.am missing README
AUTHORS ChangeLog config.guess config.sub configure.ac CREDITS include install-sh ltmain.sh Makefile.in NEWS src
我去,原来是源码,许多人到这里估计就崩溃了,这要咋办呢?自己编译吧!
[zhoupan@localhost:~/ntfs-3g-1.328]$ ./configure prefix=PATH
PATH指的是你要安装的目录,默认安装在/usr/local/ 下面,可以随便改,输出的信息较多,这里就不贴代码啦,过程中可能出现错误,根据信息自己手动解决吧!
如果过程中没有出现错误信息,那就可以看见在当前目录下,有个Makefile文件,了解过make的同仁应该都知道,自己离成功只差两条命令的距离了!
[zhoupan@localhost:~/ntfs-3g-1.328]$ make
执行完这句命令之后,你将会拥有无比的成就感,因为输出的信息整个刷屏了,趁这个机会将周围的人叫来装一下B吧,立即,因为持续时间并不会很长。
[zhoupan@localhost:~/ntfs-3g-1.328]$ make install
然后,此输出的信息又刷屏了,心里暗喜,又可以装一波B了。顺利不出错误的话,你就已经将ntfs-3g安装到你的centos里面了,一切发生的就是那么快。
[zhoupan@localhost:~/ntfs-3g-1.328]$ ntfs-3g
ntfs-3g: No device is specified.
ntfs-3g 2014.2.15 integrated FUSE 27 - Third Generation NTFS Driver
Configuration type 1, XATTRS are on, POSIX ACLS are off
Copyright (C) 2005-2007 Yura Pakhuchiy
Copyright (C) 2006-2009 Szabolcs Szakacsits
Copyright (C) 2007-2012 Jean-Pierre Andre
Copyright (C) 2009 Erik Larsson
Usage: ntfs-3g [-o option[,...]] <device|image_file> <mount_point>
Options: ro (read-only mount), windows_names, uid=, gid=,
umask=, fmask=, dmask=, streams_interface=.
Please see the details in the manual (type: man ntfs-3g).
Example: ntfs-3g /dev/sda1 /mnt/windows
News, support and information: http://tuxera.com
出现这些信息,就表明,你已成功将ntfs-3g安装成功了,下面进行挂载C盘操作:
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$ fdisk /dev/sda
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x6f292550
Device Boot Start End Blocks Id System
/dev/sda1 * 63 167782859 83891398+ 7 HPFS/NTFS/exFAT
Partition 1 does not start on physical sector boundary.
/dev/sda2 167782921 1953520064 892868572 f W95 Ext'd (LBA)
Partition 2 does not start on physical sector boundary.
/dev/sda3 1953521664 1953523711 1024 83 Linux
/dev/sda5 167782923 251690354 41953716 7 HPFS/NTFS/exFAT
Partition 5 does not start on physical sector boundary.
/dev/sda6 587270207 1187074047 299901920+ 7 HPFS/NTFS/exFAT
Partition 6 does not start on physical sector boundary.
/dev/sda7 1187075043 1953520064 383222511 7 HPFS/NTFS/exFAT
Partition 7 does not start on physical sector boundary.
/dev/sda8 447940608 579256319 65657856 83 Linux
/dev/sda9 407941120 447938559 19998720 83 Linux
/dev/sda10 251693056 252667903 487424 83 Linux
/dev/sda11 252669952 407937023 77633536 8e Linux LVM
Partition table entries are not in disk order
Command (m for help): q
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$
可以看到,我的磁盘全部信息都出现了,记着,fdisk只能是root适用哟,我的C盘是磁盘的第一个分区,大部分人的都是,所以,需要挂载的就是/dev/sda1,你的电脑就按实际情况推测吧,好了,下面就来挂载:
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$ mkdir /media/sda1
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$ mount -t ntfs-3g /dev/sda1 /media/sda1/
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$
没有消息就是最好的消息,表明你的C盘已经挂载成功了,下面继续:
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$ grub2-mkconfig > /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.10.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.10.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.3.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.3.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-229.20.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.20.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found linux image: /boot/vmlinuz-0-rescue-98a0f723fa374bccae65d892478a1677
Found initrd image: /boot/initramfs-0-rescue-98a0f723fa374bccae65d892478a1677.img
Found Windows 7 (loader) on /dev/sda1
done
[root@localhost:/home/zhoupan/ntfs-3g-1.328]$
yes,win 7的引导已经找到了,免得你去纠结的自己动手去写了,还有就是部分人的配置文件在/boot/grub/下面,自己就去查看grub.cfg文件的路径吧,OK,谢谢。