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 消失修復:Windows 重裝後恢復 Linux 開機選單

編輯:Linux 教學

故障成因

Windows 安裝程式會無條件覆寫 MBR (BIOS) 或 EFI 系統分區 (UEFI),移除 GRUB 開機載入器,導致直接進入 Windows 無法選擇 Linux。

判斷系統模式

# 當前執行環境
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"

# 目標磁碟分區表
lsblk -f
# 或
fdisk -l /dev/sda
parted /dev/sda print

修復流程:Live USB 通用大法

  1. 準備與安裝 Linux 相同架構的 Live USB (Ubuntu/Fedora/Arch/RHEL)
  2. 開機進入 Live 環境 (Try/Rescue 模式)
  3. 確認分區:lsblk -f 找出根分區、EFI 分區 (UEFI)、/boot 分區 (若獨立)
  4. 掛載並 chroot (參考 ID 45919/45920 詳細步驟)
  5. 執行對應模式的 GRUB 安裝指令
  6. 更新 GRUB 選單、驗證、重啟

BIOS/MBR 模式 (RHEL 5/6/7、舊版 Ubuntu、傳統安裝)

# 1. 掛載根分區 (假設 /dev/sda2)
mount /dev/sda2 /mnt
# 2. 掛載 /boot (若獨立,假設 /dev/sda1)
mount /dev/sda1 /mnt/boot
# 3. 虛擬檔案系統
for d in dev proc sys; do mount --bind /$d /mnt/$d; done
# 4. Chroot
chroot /mnt
# 5. 安裝 GRUB 到 MBR
grub-install /dev/sda
# 6. 產生選單
grub-mkconfig -o /boot/grub/grub.cfg
# 或舊版
grub2-mkconfig -o /boot/grub2/grub.cfg
# 7. 退出重啟
exit
umount -R /mnt
reboot

UEFI/GPT 模式 (現代系統:Ubuntu 18.04+、Fedora 28+、RHEL 8+、Windows 10/11)

# 1. 掛載根分區
mount /dev/sda2 /mnt
# 2. 掛載 EFI 系統分區 (關鍵!通常 /dev/sda1,FAT32,標籤 EFI/ESP)
mount /dev/sda1 /mnt/boot/efi
# 3. 掛載 /boot (若獨立)
# mount /dev/sda3 /mnt/boot
# 4. 虛擬檔案系統
for d in dev proc sys run; do mount --bind /$d /mnt/$d; done
# 5. Chroot
chroot /mnt
# 6. 安裝 GRUB 到 EFI 分區並註冊 NVRAM
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck
# Fedora/RHEL: --bootloader-id=linux / --bootloader-id=redhat
# 7. 產生選單
grub-mkconfig -o /boot/grub/grub.cfg
# 8. 重啟驗證
exit
umount -R /mnt
reboot

進入 GRUB 救援模式手動開機 (無 Live USB 時)

若看到 grub> 或 grub rescue> 提示符:

# 1. 找出含 grub 目錄的分區
ls
# 輸出如: (hd0,gpt1), (hd0,gpt2), (hd0,gpt3) ...
# 逐一嘗試
ls (hd0,gpt1)/
ls (hd0,gpt2)/boot/grub
# 找到含 grub.cfg 的分區,假設是 (hd0,gpt2)

# 2. 設定 prefix 與 root
set prefix=(hd0,gpt2)/boot/grub
set root=(hd0,gpt2)
insmod normal
normal

# 3. 進入選單後選擇 Linux 啟動,進入系統再執行 grub-install

Windows 端輔助修復 (不進 Linux)

  1. EasyUEFI (免費版):圖形化新增/調整 UEFI 開機項,指向 \EFI\ubuntu\grubx64.efi 或 shimx64.efi
  2. bcdedit (需管理員):bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi
  3. diskpart 確認 EFI 分區掛載字母:sel disk 0; sel part 1; assign letter=Z:,再用 EasyUEFI 指向 Z:\EFI\ubuntu\grubx64.efi

常見坑點避雷

現象原因解決
grub-install: EFI variables are not supportedLive USB 以 BIOS 模式啟動,但目標為 UEFI重新以 UEFI 模式啟動 Live USB (BIOS 設定 UEFI First / 關閉 CSM)
grub-install: failed to get canonical path of /cowchroot 環境不完整確認 /dev, /proc, /sys, /run 皆已 bind mount
Windows 快速啟動鎖定 EFI 分區Windows 預設啟用快速啟動 (休眠)Windows 關機時按 Shift+關機、或 powercfg /h off 關閉休眠
修復後 GRUB 選單無 Windows 項os-prober 未偵測 / 未啟用GRUB_DISABLE_OS_PROBER=false 在 /etc/default/grub → update-grub
雙硬碟:GRUB 安裝到錯誤磁碟/dev/sda vs /dev/sdb 混淆用 UUID/標籤確認,grub-install /dev/disk/by-id/ata-XXXX

驗證清單

  • [ ] 重啟後出現 GRUB 選單
  • [ ] 選單含 Linux 核心項目 (含 recovery mode)
  • [ ] 選單含 Windows Boot Manager 項目
  • [ ] Linux 正常啟動進入桌面/登入提示
  • [ ] Windows 正常啟動
  • [ ] 連續重啟 3 次無異常

核心口訣:Live USB 同架構、掛載對分區、模式對模式、chroot 進系統、grub-install 寫開機、update-grub 產選單。

Copyright © Windows教程網 All Rights Reserved