CentOS 開機出現 GRUB、grub> 提示或錯誤代碼,通常因 MBR 損壞、分區變動、核心更新失敗或 U 盤安裝導致裝置映射錯誤。本文提供兩套完整修復方案:光盤救援模式重裝 GRUB、手動編輯 grub.conf 修正配置、U 盤安裝殘留裝置映射修正。
linux rescue


/mnt/sysimage


# chroot /mnt/sysimage
# grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit
# reboot


在 chroot /mnt/sysimage 後:
# vi /boot/grub/grub.conf
# 補全最小可用配置(以 CentOS 5.9 為例)
# grub.conf generated by anaconda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-348.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-348.el5 ro root=LABEL=/
initrd /initrd-2.6.18-348.el5.img
# :wq! 強制存檔
# quit
# reboot

現象:拔掉 U 盤無法開機,插上 U 盤正常啟動。
原因:安裝時 U 盤被識別為 sdb,硬碟為 sda,GRUB 安裝到 U 盤 MBR,device.map 與 grub.conf 記錄錯誤映射。
# 1. 重裝 GRUB 到硬碟 MBR
# grub-install /dev/sda
# 2. 修正 device.map
# vi /boot/grub/device.map
# 修正為:
(hd0) /dev/sda
# 刪除錯誤的 (hd1) /dev/sda 等行
# 3. 修正 grub.conf 中的 root 裝置
# vi /boot/grub/grub.conf
# 將所有 (hd1,0) 改為 (hd0,0)
# 僅保留當前核心啟動項,刪除多餘舊項
# 4. 重啟驗證(拔掉 U 盤)
# reboot
grub2-install /dev/sda (CentOS 7) 或 grub-install /dev/sda (CentOS 6) 明確指定安裝目標/boot/grub/grub.conf 與 /boot/grub/device.map