雙系統(Windows + Linux)的啟動管理核心在於 MBR(主引導記錄)由誰佔據,以及次級引導程式如何鏈式載入對方。本文詳細解析 GRUB 與 Windows Boot Manager(NTLDR/BOOTMGR)的互導原理,提供兩種主流配置方案的完整步驟與避坑指南。
| 階段 | Windows (MBR 模式) | Linux (GRUB) |
|---|---|---|
| MBR (446 bytes) | NTLDR (XP/2003) / BOOTMGR (Vista+) | GRUB Stage 1 |
| 分區引導區 (PBR/VBR) | NTLDR 讀取 boot.ini (XP) / BOOTMGR 讀取 BCD | GRUB Stage 1.5 / Stage 2 讀取 /boot/grub/menu.lst 或 grub.cfg |
| 核心載入 | ntoskrnl.exe | vmlinuz + initrd/initramfs |
/dev/sdaX)或 /boot 分區。grldr、menu.lst),放置於 C:\ 根目錄。C:\menu.lst,內容同 Linux /boot/grub/menu.lst(或 grub.cfg 轉換)。C:\boot.ini(XP/2003)或使用 bcdedit(Vista+)新增啟動項:# boot.ini (XP)
[boot loader]
timeout=10
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP" /fastdetect
C:\grldr="Linux (GRUB4DOS)"
# bcdedit (Vista/7/8/10/11) - 管理員 PowerShell
bcdedit /create /d "Linux (GRUB4DOS)" /application bootsector
# 返回 GUID,假設為 {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
bcdedit /set {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} device partition=C:
bcdedit /set {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} path \grldr
bcdedit /displayorder {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} /addlast
bcdedit /timeout 10
C:\menu.lst(或掛載 Linux 分區同步)。# 使用 Live CD 進入救援模式
grub> root (hd0,2) # Linux 根分區或 /boot 分區 (hd0,2 = sda3)
grub> setup (hd0) # 安裝 Stage1 到 MBR
# 或現代 grub-install
grub-install --target=i386-pc /dev/sda
update-grub # 自動偵測 Windows 並生成菜單
menuentry "Windows 10" {
insmod part_msdos
insmod ntfs
insmod search_fs_uuid
insmod chain
search --fs-uuid --set=root
chainloader /EFI/Microsoft/Boot/bootmgfw.efi # UEFI 模式
# chainloader +1 # BIOS/MBR 模式
}
執行 update-grub 後重啟即可看到選單。
bootrec /fixmbr # 修復 MBR 程式碼
bootrec /fixboot # 修復分區引導區
bootrec /scanos # 掃描 Windows 安裝
bootrec /rebuildbcd # 重建 BCD
.efi 引導程式。/EFI/Microsoft/Boot/、/EFI/ubuntu/、/EFI/fedora/)。dd if=/dev/sda of=/backup/mbr.backup bs=512 count=1blkid,GRUB 配置需用 UUID 而非設備名。