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

Linux 開機引導修復實戰:GRUB2 救援模式與檔案系統修復

編輯:Linux 教學

前言

系統無法開機、GRUB 損毀、檔案系統錯誤是運維高頻故障。本文提供標準化救援流程:光碟救援模式 → chroot → GRUB 重裝 → 檔案系統檢查。

一、 標準救援流程

  1. 啟動安裝光碟/USB,選擇 Troubleshooting → Rescue a Linux system(或啟動參數加 rescue)。
  2. 掛載系統根分區(救援模式通常自動掛載至 /mnt/sysimage):
    chroot /mnt/sysimage
  3. 重新安裝 GRUB2:
    # 確認目標磁碟(通常為 /dev/sda 或 /dev/vda)
    grub2-install /dev/sda
    
    # 若為 UEFI 系統
    grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
  4. 重建 GRUB 配置:
    grub2-mkconfig -o /boot/grub2/grub.cfg
    # UEFI: grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  5. 退出 chroot 並重啟:
    exit
    reboot

二、 磁碟分區與檔案系統診斷

# 查看分區表
fdisk -l
# 或
lsblk -f

# 檢查並修復檔案系統(需卸載分區)
# 假設根分區為 /dev/sda2
fsck -y /dev/sda2
# -y 自動回答 yes 修復所有發現錯誤

三、 常見故障場景與對策

故障現象可能原因核心修復步驟
grub rescue> 提示 GRUB 核心映像遺失/分區 UUID 變更 chroot → grub2-install → grub2-mkconfig
Kernel panic - not syncing: VFS initramfs 缺少驅動/根裝置參數錯誤 chroot → dracut --force → grub2-mkconfig
Emergency mode / 檔案系統唯讀 ext4/xfs 元資料損毀 fsck -y /dev/sdX → 重啟
UEFI 開機項目消失 NVRAM 變數損毀/ESP 分區未掛載 掛載 ESP → grub2-install --target=x86_64-efi
Windows 更新後 Linux 消失 Windows 覆寫 EFI 啟動順序 BIOS 調整啟動順序 / efibootmgr 重建項目

四、 進階:使用 Live USB 手動掛載修復(無救援模式)

# 1. 啟動 Live 系統(Ubuntu/CentOS/Fedora Live)
# 2. 識別分區
lsblk -f
# 3. 掛載根分區與關鍵目錄
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot       # 若有獨立 /boot
mount /dev/sda1 /mnt/boot/efi   # UEFI ESP 分區
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
# 4. chroot 進入
chroot /mnt
# 5. 執行修復(grub2-install, fsck, dracut 等)
# 6. 退出、同步、重啟
exit
sync
umount -R /mnt
reboot

五、 預防與備份

  • 備份 GRUB 配置:cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
  • 備份 EFI 開機項目:efibootmgr -v > /root/efiboot.bak
  • 定期檢查檔案系統:tune2fs -c 30 -i 180d /dev/sda2(每 30 次掛載或 180 天自動 fsck)。

結語

引導修復核心三步:**chroot 進入真實系統 → 重裝 GRUB 到正確裝置 → 重建配置**。熟練掌握 grub2-install、grub2-mkconfig、fsck、dracut 四大工具,配合 Live USB 通用掛載流程,可應對 99% 的開機故障。

Copyright © Windows教程網 All Rights Reserved