Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

雙硬碟三系統 (Win7 + Ubuntu 12.04 + XP) GRUB2 手動配置詳解

編輯:Windows 7 系統介紹

環境:磁碟 0 (hd0) 安裝 Windows 7 + Ubuntu 12.04;磁碟 1 (hd1) 安裝 Windows XP。`update-grub` 僅偵測到 Win7 與 Ubuntu,選單中 XP 項目雖顯示但無法啟動。需手動編輯 `/boot/grub/grub.cfg` 加入正確的 `drivemap` 指令修正磁碟映射。

核心修正:新增 XP 啟動項

menuentry "Windows XP" --class windows --class os {
    insmod ntfs
    set root="(hd0,1)"
    search --no-floppy --fs-uuid --set=root 4C844B34844B2036
    drivemap -s (hd0) ${root}
    chainloader +1
}

關鍵參數解析

  • set root="(hd0,1)":GRUB 裝置命名法,`hd0` = 第一顆實體磁碟 (BIOS 啟動序優先磁碟),`1` = 第一個分割區 (XP 的 C: 槽)。
  • search --fs-uuid:以檔案系統 UUID 精確定位分割區,避免磁碟順序變動導致啟動失敗。UUID 可用 `blkid` 或 `ls -l /dev/disk/by-uuid/` 查詢。
  • drivemap -s (hd0) ${root}:關鍵指令。將 GRUB 的 `hd0` (BIOS 第一磁碟) 臨時映射到 XP 所在分割區,讓 XP 的 NTLDR/BOOTMGR 以為自己在第一磁碟第一分割區,解決 XP 必須啟動於 `hd0,1` 的硬性限制。
  • chainloader +1:鏈式載入分割區啟動區 (PBR)。

完整 grub.cfg 結構參考

檔案包含標準區塊:`00_header` (環境變數、主題、超時)、`05_debian_theme` (色彩)、`10_linux` (Ubuntu 核心項目)、`20_memtest86+`、`30_os-prober` (自動偵測 Win7)、`40_custom`/`41_custom` (使用者自訂)。建議將 XP 項目放入 `/etc/grub.d/40_custom`,再執行 `update-grub` 產生新 cfg,避免直接修改 `grub.cfg` 遭覆蓋。

驗證與除錯

  1. 重開機進入 GRUB 選單,選擇 "Windows XP" 應能正常進入 XP 桌面。
  2. 若仍失敗:GRUB 命令列模式 (按 `c`) 輸入 `ls` 確認裝置命名、`ls (hd0,1)/` 確認 XP 系統檔案 (`ntldr`, `boot.ini`) 存在。
  3. 檢查 `boot.ini` 中 `rdisk(0) partition(1)` 是否與實際分割區對應。

現代替代方案

  • UEFI + GPT 環境:使用 rEFInd 或 systemd-boot 管理多重啟動,無需 `drivemap` 技巧。
  • 虛擬機:將 XP 封裝為 VM (VirtualBox/VMware) 在 Win7/Ubuntu 內執行,避免實體多重啟動複雜度。
Copyright © Windows教程網 All Rights Reserved