多重開機環境下,GRUB 安裝位置決定哪個分區的 menu.lst(GRUB Legacy)或 grub.cfg(GRUB 2)被讀取。本文示範 GRUB 命令列模式下 root 與 setup 指令操作,掌控開機選單所有權。
開機選單按 c 進入命令列,提示符 grub>。
grub> root (hdX,Y)
grub> setup (hd0)
hdX:硬碟編號(從 0 起算)。hd0 = 第一顆硬碟,hd1 = 第二顆。Y:分區編號(從 0 起算)。(hd0,0) = 第一顆硬碟第一分區。root (hdX,Y):告訴 GRUB 核心映像與 menu.lst 所在分區。setup (hd0):將 GRUB Stage1 寫入 hd0 的 MBR(主開機記錄)。grub> root (hd1,0)
grub> setup (hd0)
成功會顯示:
Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done.
GRUB 2(Ubuntu 9.10+/RHEL 7+)使用 grub-install 與 grub-mkconfig:
# 安裝至 MBR
grub-install /dev/sda
# 生成配置
grub-mkconfig -o /boot/grub/grub.cfg
# 或更新現有配置
update-grub
多重開機修復常用:
grub-install --boot-directory=/mnt/boot /dev/sda(從 LiveCD 掛載目標系統後執行)
| 現象 | 原因 | 解決 |
|---|---|---|
Error 15: File not found | root 指定分區錯誤,找不到 stage2/menu.lst | 用 find /boot/grub/stage1 確認正確分區 |
開機進入 grub rescue> | MBR 階段 1.5 找不到核心模組 | LiveCD 重裝 grub-install |
| Windows 更新後 GRUB 消失 | Windows 覆寫 MBR | LiveCD 重裝 GRUB |
root 指向配置,**setup 寫入 MBR**。GRUB Legacy 時代的手動操作讓我們理解開機載入器的兩階段架構:MBR (446 bytes) → Stage1.5 (檔案系統驅動) → Stage2 (完整功能) → menu.lst。現代 GRUB 2 雖自動化程度高,但理解底層原理仍是修復複雜多重開機故障的關鍵。
Linux 掛載與卸載完全指南:mount/umount 參數詳解、ISO/Windows分區/NFS 實戰場景
Linux 服務器間文件同步實戰:Rsync 守護進程模式配置與定時同步策略
Linux Telnet 服務快速啟用與 Root 登入設定
Debian Linux 實現 ADSL 撥號上網與動態域名自動更新
Makefile 變量賦值尾隨空格導致 "command not found" 錯誤排查
RHEL 6/7 網卡綁定配置範本:Mode 1 主備與 Mode 4 LACP 聚合雙場景