環境:磁碟 0 (hd0) 安裝 Windows 7 + Ubuntu 12.04;磁碟 1 (hd1) 安裝 Windows XP。`update-grub` 僅偵測到 Win7 與 Ubuntu,選單中 XP 項目雖顯示但無法啟動。需手動編輯 `/boot/grub/grub.cfg` 加入正確的 `drivemap` 指令修正磁碟映射。
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)。檔案包含標準區塊:`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` 遭覆蓋。