Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

GRUB 救援全攻略:從 grub> 提示符到急救模式完美修復開機引導

編輯:Linux 教學

GRUB 是主流 Linux 發行版預設的開機載入器。當 /boot/grub/grub.conf 遺失、關鍵參數錯誤或 MBR 引導碼受損時,系統會停在 grub> 提示符無法繼續啟動。本文提供兩套經實戰驗證的修復方案,助你快速恢復開機。

現象確認

螢幕僅顯示 grub>,鍵盤可輸入指令,但無開機選單。

方法一:在 grub> 環境下手動引導進入系統

適用於 grub.conf 內容正確但 MBR 未損壞、或單純參數輸入錯誤的情況。

grub> root (hd0,0)                # 指定 /boot 所在分區 (第一顆硬碟第一分區)
grub> kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet  # 載入核心,建議用 Tab 鍵補全檔名
grub> initrd /initrd-2.6.18-128.el5.img  # 載入初始虛擬檔案系統,同樣用 Tab 補全
grub> boot                         # 啟動核心

成功進入系統後,立即執行 grub-install /dev/sda 將 GRUB 重寫入 MBR,並檢查修正 /boot/grub/grub.conf。

方法二:光碟急救模式 (Rescue Mode) 徹底修復

適用於 MBR 損壞、grub.conf 遺失、檔案系統錯誤等嚴重情況。

1. 進入急救環境

  1. 插入安裝光碟,重啟,BIOS 設為光碟啟動。
  2. 開機提示符輸入 linux rescue 進入救援模式。
  3. 依序接受預設語言、鍵盤佈局;網路設定選 NO;系統自動掃描硬碟並嘗試掛載至 /mnt/sysimage,選 Continue。
  4. 關鍵:出現「是否初始化磁碟」警告時,務必選 NO,避免覆寫資料。
  5. 最終進入 sh-3.1# Bash 環境。

2. 情況 A:僅 grub.conf 損壞,MBR 完好

sh-3.1# chroot /mnt/sysimage          # 切換至原系統根環境
sh-3.1# mount                         # 確認分區掛載狀態
sh-3.1# vi /boot/grub/grub.conf       # 重建設定檔 (參考下方範本)
sh-3.1# exit                          # 離開 chroot
sh-3.1# exit                          # 離開救援環境,系統自動重啟

grub.conf 範本 (依實際分區調整):

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Enterprise Linux (2.6.18-128.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-128.el5.img

3. 情況 B:MBR 亦損壞,需重裝 GRUB

sh-3.1# chroot /mnt/sysimage
sh-3.1# grub-install /dev/hda         # 或 /dev/sda,視硬碟裝置而定
sh-3.1# exit
sh-3.1# exit

重啟後應恢復正常開機選單。

避坑指南

  • Tab 鍵補全:輸入核心與 initrd 檔名時務必善用,防止拼寫錯誤。
  • 分區代號:(hd0,0) 對應 /dev/sda1 或 /dev/hda1,請用 fdisk -l 確認。
  • 備份習慣:定期 dd if=/dev/sda of=/backup/mbr.img bs=512 count=1 備份 MBR,關鍵時刻可秒級還原。
Copyright © Windows教程網 All Rights Reserved