萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

CentOS 開機 GRUB 引導錯誤修復:光盤救援模式與 U 盤安裝殘留問題完整解決方案

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

一、方案 A:光盤救援模式修復(標準流程)

  1. 插入 版本相同 的 CentOS 安裝光盤,啟動進入選單
  2. 選擇 Troubleshooting / Rescue a CentOS system 或按 F5 輸入 linux rescue

    開機選單選擇救援模式

    輸入 linux rescue

  3. 語言/鍵盤選擇預設,選 Continue 掛載系統映像至 /mnt/sysimage

    選擇 Continue

    掛載系統映像

  4. 切換根環境並重裝 GRUB
    # chroot /mnt/sysimage
    # grub
    grub> root (hd0,0)
    grub> setup (hd0)
    grub> quit
    # reboot

    chroot 切換根環境

    grub 交互式重裝

二、方案 B:手動修復 grub.conf(若方案 A 無效)

在 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

grub.conf 修復範例

三、方案 C:U 盤安裝導致的裝置映射錯誤修復

現象:拔掉 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

四、預防建議

  • 安裝時拔除非必要 USB 裝置
  • 使用 grub2-install /dev/sda (CentOS 7) 或 grub-install /dev/sda (CentOS 6) 明確指定安裝目標
  • 定期備份 /boot/grub/grub.conf 與 /boot/grub/device.map
copyright © 萬盛學電腦網 all rights reserved