如何使用Grub2在UEFI主板上启动多个驱动器

我在UEFI主板上有SSD和HDD。 我可以通过更改BIOS中的启动顺序来切换操作系统,但如果Grub2只是将Windows7列为启动选项,我会更喜欢它。

解决问题应该可以帮助任何在UEFI主板上拥有多个驱动器的人。 已经看到使用UEFI和rEFInd 从多个磁盘启动多个操作系统看起来是一个不错的选择; 这个问题是关于如何正确配置Grub2以查看Windows7(或任何操作系统)的引导程序,如果可能的话 – 不使用Grub-legacy或其他工具,如rEFInd。

我正在使用Ubuntu 12.10,而Grub2在SSD上,主要启动设备,而Windows7在HDD上,它决定在安装时拆分为三个分区。

引导信息脚本提供了一个冗长的细分:

Boot Info Script 0.61 [1 April 2012] ============================= Boot Info Summary: =============================== => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at sector 1 of the same hard drive for core.img. core.img is at this location and looks in partition 72 for . => No boot loader is installed in the MBR of /dev/sdb. sda1: __________________________________________________________________________ File system: ext4 Boot sector type: - Boot sector info: Operating System: Ubuntu 12.10 Boot files: /boot/grub/grub.cfg /etc/fstab sda2: __________________________________________________________________________ File system: swap Boot sector type: - Boot sector info: sdb1: __________________________________________________________________________ File system: vfat Boot sector type: Windows 7: FAT32 Boot sector info: No errors found in the Boot Parameter Block. Operating System: Boot files: /efi/Boot/bootx64.efi sdb2: __________________________________________________________________________ File system: Boot sector type: - Boot sector info: Mounting failed: mount: unknown filesystem type '' sdb3: __________________________________________________________________________ File system: ntfs Boot sector type: Windows Vista/7: NTFS Boot sector info: No errors found in the Boot Parameter Block. Operating System: Windows 7 Boot files: /Windows/System32/winload.exe ============================ Drive/Partition Info: ============================= Drive: sda _____________________________________________________________________ Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes Partition Boot Start Sector End Sector # of Sectors Id System /dev/sda1 * 2,048 218,439,679 218,437,632 83 Linux /dev/sda2 218,439,680 234,440,703 16,001,024 82 Linux swap / Solaris Drive: sdb _____________________________________________________________________ Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 256 heads, 63 sectors/track, 121126 cylinders, total 1953525168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes Partition Boot Start Sector End Sector # of Sectors Id System /dev/sdb1 1 4,294,967,295 4,294,967,295 ee GPT /dev/sdb1 ends after the last sector of /dev/sdb GUID Partition Table detected. Partition Start Sector End Sector # of Sectors System /dev/sdb1 2,048 206,847 204,800 EFI System partition /dev/sdb2 206,848 468,991 262,144 Microsoft Reserved Partition (Windows) /dev/sdb3 468,992 1,953,523,711 1,953,054,720 Data partition (Windows/Linux) "blkid" output: ________________________________________________________________ Device UUID TYPE LABEL /dev/sda1 e20b187a-c3b0-45e1-98df-c955b3cffdde ext4 /dev/sda2 7663b629-19c9-49fc-a744-2beb2dcdb317 swap /dev/sdb1 F428-FB77 vfat /dev/sdb3 162C36632C363DD5 ntfs ================================ Mount points: ================================= Device Mount_Point Type Options /dev/sda1 / ext4 (rw,errors=remount-ro) =========================== sda1/boot/grub/grub.cfg: =========================== -------------------------------------------------------------------------------- # # DO NOT EDIT THIS FILE # # It is automatically generated by grub-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub # ### BEGIN /etc/grub.d/00_header ### if [ -s $prefix/grubenv ]; then set have_grubenv=true load_env fi set default="0" 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 recordfail { set recordfail=1 if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; 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_input console terminal_output console if [ "${recordfail}" = 1 ]; then set timeout=-1 else set timeout=6 fi ### END /etc/grub.d/00_header ### ### BEGIN /etc/grub.d/05_debian_theme ### set menu_color_normal=white/black set menu_color_highlight=black/light-gray if background_color 44,0,30; then clear fi ### END /etc/grub.d/05_debian_theme ### ### BEGIN /etc/grub.d/10_linux ### function gfxmode { set gfxpayload="${1}" if [ "${1}" = "keep" ]; then set vt_handoff=vt.handoff=7 else set vt_handoff= fi } if [ "${recordfail}" != 1 ]; then if [ -e ${prefix}/gfxblacklist.txt ]; then if hwmatch ${prefix}/gfxblacklist.txt 3; then if [ ${match} = 0 ]; then set linux_gfx_mode=keep else set linux_gfx_mode=text fi else set linux_gfx_mode=text fi else set linux_gfx_mode=keep fi else set linux_gfx_mode=text fi export linux_gfx_mode if [ "${linux_gfx_mode}" != "text" ]; then load_video; fi menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi linux /boot/vmlinuz-3.5.0-27-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro quiet splash $vt_handoff initrd /boot/initrd.img-3.5.0-27-generic } submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-e20b187a-c3b0-45e1-98df-c955b3cffdde' { menuentry 'Ubuntu, with Linux 3.5.0-27-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-27-generic-advanced-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-27-generic ...' linux /boot/vmlinuz-3.5.0-27-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-27-generic } menuentry 'Ubuntu, with Linux 3.5.0-27-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-27-generic-recovery-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-27-generic ...' linux /boot/vmlinuz-3.5.0-27-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-27-generic } menuentry 'Ubuntu, with Linux 3.5.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-26-generic-advanced-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-26-generic ...' linux /boot/vmlinuz-3.5.0-26-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-26-generic } menuentry 'Ubuntu, with Linux 3.5.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-26-generic-recovery-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-26-generic ...' linux /boot/vmlinuz-3.5.0-26-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-26-generic } menuentry 'Ubuntu, with Linux 3.5.0-17-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-17-generic-advanced-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-17-generic ...' linux /boot/vmlinuz-3.5.0-17-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-17-generic } menuentry 'Ubuntu, with Linux 3.5.0-17-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.5.0-17-generic-recovery-e20b187a-c3b0-45e1-98df-c955b3cffdde' { recordfail insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 e20b187a-c3b0-45e1-98df-c955b3cffdde else search --no-floppy --fs-uuid --set=root e20b187a-c3b0-45e1-98df-c955b3cffdde fi echo 'Loading Linux 3.5.0-17-generic ...' linux /boot/vmlinuz-3.5.0-17-generic root=UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.5.0-17-generic } } ### END /etc/grub.d/10_linux ### ### BEGIN /etc/grub.d/20_linux_xen ### ### END /etc/grub.d/20_linux_xen ### ### BEGIN /etc/grub.d/30_os-prober ### ### END /etc/grub.d/30_os-prober ### ### BEGIN /etc/grub.d/30_uefi-firmware ### ### END /etc/grub.d/30_uefi-firmware ### ### 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 ### -------------------------------------------------------------------------------- =============================== sda1/etc/fstab: ================================ -------------------------------------------------------------------------------- # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # #       # / was on /dev/sda1 during installation UUID=e20b187a-c3b0-45e1-98df-c955b3cffdde / ext4 errors=remount-ro 0 1 # swap was on /dev/sda2 during installation UUID=7663b629-19c9-49fc-a744-2beb2dcdb317 none swap sw 0 0 -------------------------------------------------------------------------------- =================== sda1: Location of files loaded by Grub: ==================== GiB - GB File Fragment(s) = boot/grub/grub.cfg 1 = boot/initrd.img-3.5.0-17-generic 1 = boot/initrd.img-3.5.0-26-generic 1 = boot/initrd.img-3.5.0-27-generic 1 = boot/vmlinuz-3.5.0-17-generic 1 = boot/vmlinuz-3.5.0-26-generic 1 = boot/vmlinuz-3.5.0-27-generic 2 = initrd.img 1 = initrd.img.old 1 = vmlinuz 2 = vmlinuz.old 2 =============================== StdErr Messages: =============================== awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in awk: cmd. line:36: Math support is not compiled in 

总之,除了它所在的根分区(sda1)之外,Ubuntu还有一个交换分区(sda2)。 那里一切都很好。 Windows7制作了3个分区,第一个(sdb1)用于EFI,第二个(sdb2)为windows保留,这是不相关的,第三个(sdb3)是实际的Windows安装。

sdb1的文件层次结构是

 > ls -aR .: . .. EFI ./EFI: . .. Boot Microsoft ./EFI/Boot: . .. bootx64.efi ./EFI/Microsoft: . .. Boot ./EFI/Microsoft/Boot: . BCD BCD.LOG1 bootmgfw.efi BOOTSTAT.DAT da-DK el-GR es-ES Fonts hu-HU ja-JP memtest.efi nl-NL pt-BR ru-RU tr-TR zh-HK .. BCD.LOG BCD.LOG2 bootmgr.efi cs-CZ de-DE en-US fi-FI fr-FR it-IT ko-KR nb-NO pl-PL pt-PT sv-SE zh-CN zh-TW etc 

通过使用

 grub-mkdevicemap 

文件“device.map”在“/ boot / grub”中生成,其标识SSD是(hd0)而HDD是(hd1)。 hd0是主要启动设备,Grub2住在这里。

在grub-customizer中,我尝试创建一个将grub2引导到Windows7引导程序的条目:

 set root='(hd1,1)' search-no-floppy-fs-uuid-set F428-FB77 drivemap -s (hd1) ${root} chainloader +1 

但是,在重启时从grub中选择它会产生以下错误:

 error: no such device: F428-FB77. error: invalid signature. Press any key to continue..._ 

我接近了吗?

您的问题是您已经安装了Linux和GRUB的BIOS模式,而您的Windows安装是在EFI模式下。 GRUB无法切换启动模式,因此您无法对当前的 GRUB安装执行任何操作。 您必须添加EFI模式GRUB(或其他一些EFI模式引导程序,例如rEFInd)才能完成这项工作。 不幸的是,从你的工作安装中执行此操作非常棘手,因为它需要使用名为efibootmgr的EFI模式程序,并且这在您当前的BIOS模式Linux启动时无效,因此会产生鸡与蛋的难题。 您可以从在EFI模式下启动的紧急Ubuntu光盘执行此操作 ,但这会使GRUB设置过程变得复杂。 有关EFI引导加载程序的信息,请参阅我的主题网页,以及如果您想尝试这一点,请手动安装它们。 从EFI模式紧急光盘运行的Ubuntu 引导修复工具可以相对轻松地安装EFI模式GRUB,但我不是很确定。 我也不是Boot Repair的粉丝,因为它的变化相当火爆。

另一种选择是放弃GRUB而转而使用rEFInd。 如果你在BIOS模式下启动Linux,在/boot/efi挂载/dev/sdb1 (你的ESP),然后安装rEFInd的Debian软件包版本,它应该自行启动以在下次以EFI模式启动计算机时启动(您可能需要选择“Windows”选项才能启动它)。 这可以通过使用一种解决方法来解决这个问题,但也不像Boot Repair那样糟糕,恕我直言。 一旦你在EFI模式下启动Linux,它也是可逆的:键入sudo mount /dev/sdb1 /boot/efi再次安装ESP(无论你选择什么解决方案,创建/etc/fstab条目都是个好主意)然后键入sudo mvrefind.sh /boot/efi/EFI/Microsoft/Boot /boot/efi/EFI/refind

第三种选择是在BIOS模式下重新安装Windows。 为此,您需要擦除/dev/sdb上的分区表,将其从GPT转换为MBR格式,然后重新安装Windows,确保在BIOS模式下执行此操作。 这是最不优雅的解决方案,但是如果您对Windows安装感到满意并且没有数据需要保留在/dev/sdb ,那么它可能最有可能成功而不会引起并发症。