![如何将 Windows 7 添加到 GRUB 2?](https://linux22.com/image/1375981/%E5%A6%82%E4%BD%95%E5%B0%86%20Windows%207%20%E6%B7%BB%E5%8A%A0%E5%88%B0%20GRUB%202%EF%BC%9F.png)
我在将 Windows 7 添加到 GRUB 2 启动菜单中时遇到了问题。我知道此网站和其他网站上已经有人提出并回答了类似的问题,但这些答案似乎都不适合我。
我的设置:两个硬盘,sda 安装了 Win 7,sdb 安装了 Debian 和 GRUB2。
在我的 BIOS 中,我可以选择从哪个硬盘启动,如果我从第一个硬盘启动,Windows 就会启动,所以我知道它正在运行。现在我想向 GRUB 添加一个菜单项来启动 Windows。
我下载了启动信息脚本并运行它,结果如下RESULTS.txt
:
Boot Info Script 0.61 [1 April 2012]
============================= Boot Info Summary: ===============================
=> Windows is installed in the MBR of /dev/sda.
=> Grub2 (v1.99) is installed in the MBR of /dev/sdb and looks at sector 2048
of the same hard drive for core.img. core.img is at this location and
looks for (,gpt2)/boot/grub on this drive.
sda1: __________________________________________________________________________
File system:
Boot sector type: Windows Vista/7: NTFS
Boot sector info:
Mounting failed: mount: unknown filesystem type ''
sda2: __________________________________________________________________________
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
sdb1: __________________________________________________________________________
File system: BIOS Boot partition
Boot sector type: Grub2's core.img
Boot sector info:
sdb2: __________________________________________________________________________
File system: ext4
Boot sector type: -
Boot sector info:
Mounting failed: mount: unknown filesystem type ''
mount: /dev/sdb2 already mounted or sdb2 busy
sdb3: __________________________________________________________________________
File system: swap
Boot sector type: -
Boot sector info:
============================ Drive/Partition Info: =============================
Drive: sda _____________________________________________________________________
Disk /dev/sda: 256.1 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders, total 500118192 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 206,847 204,800 7 NTFS / exFAT / HPFS
/dev/sda2 206,848 500,115,455 499,908,608 7 NTFS / exFAT / HPFS
Drive: sdb _____________________________________________________________________
Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 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
GUID Partition Table detected.
Partition Start Sector End Sector # of Sectors System
/dev/sdb1 2,048 4,095 2,048 BIOS Boot partition
/dev/sdb2 4,096 2,605,768,703 2,605,764,608 Data partition (Windows/Linux)
/dev/sdb3 2,605,768,704 2,639,306,751 33,538,048 Swap partition (Linux)
"blkid" output: ________________________________________________________________
Device UUID TYPE LABEL
/dev/sda2 DCA04533A0451584 ntfs
/dev/sdb2 ea61c63c-0a93-44fb-894c-f652c28b67d0 ext4
/dev/sdb3 ca9c61ec-f99e-428c-bdf3-65fbbfc4b43b swap
================================ Mount points: =================================
Device Mount_Point Type Options
/dev/disk/by-uuid/ea61c63c-0a93-44fb-894c-f652c28b67d0 / ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)
/dev/sda2 /mnt/win fuseblk (ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
=============================== StdErr Messages: ===============================
xz: (stdin): Compressed data is corrupt
OS-prober 似乎无法检测到我的 Win7 安装。如果我运行update-grub2
(我相信这反过来会运行 OS-prober),它将输出:
Generating grub.cfg ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-3.2.0-4-amd64
Found initrd image: /boot/initrd.img-3.2.0-4-amd64
done
我尝试了一些 GRUB 菜单项的变体(通过修改/etc/grub.d/40_custom
然后运行update-grub2
)。以下是其中一些:
第一个很简单,灵感来自(例如)这个链接:http://technologytales.com/2010/11/21/manually-adding-an-entry-for-windows-7-to-an-ubuntu-grub2-menu/
menuentry 'Windows 7' {
set root='(hd0,2)'
chainloader +1
}
这将无法启动,并导致 GRUB 输出以下信息:
Booting a command list
error: invalid signature.
Press any key to continue...
然后我尝试了这个:
menuentry 'Windows 7' --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,2)'
search --no-floppy --fs-uuid --set=root DCA04533A0451584
chainloader +1
}
结果是:
BOOTMGR is missing
Press Ctrl+Alt+Del to restart
然后我尝试:
menuentry 'Windows 7' --class windows --class os {
insmod part_msdos
insmod ntfs
insmod ntldr
set root='(hd0,2)'
search --no-floppy --fs-uuid --set=root DCA04533A0451584
ntldr ($root)/Windows/System32/winload.exe
}
它也不起作用(转到一个带有闪烁光标的空白屏幕)。
我真的很困惑。任何帮助都将不胜感激!
更新:我使用默认设置运行了 boot-repair-disk(如 moses 在评论中建议的那样)。它没有在启动菜单中添加 Win7 条目。也许它无法检测到 Win7 安装,因为它用 GRUB 覆盖了它的 MBR。以下是链接启动修复磁盘日志。
答案1
问题是 Windows 7 使用 100MB系统分区,用于存放启动文件。因此,您需要从该分区启动,而不是从 Windows 驱动器(称为引导分割)。
menuentry 'Windows 7' {
set root='(hd0,0)'
chainloader +1
}
boot info script
注意 GRUB 从 0 开始计数分区,因此 /dev/sda1 是 (hd0,0),/dev/sda2 是 (hd0,1)。尽管无法挂载文件系统似乎存在问题,但这很可能可行。