萬盛學電腦網

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

Ubuntu Live CD 修復 GRUB 引導完整教學:chroot 法恢復開機選單

安裝 Windows 後導致 GRUB 被覆蓋、無法進入 Linux,無需重裝系統。使用 Ubuntu Live USB 進入試用環境,透過 chroot 掛載原系統分區並重新安裝 GRUB 至 MBR,即可快速恢復多重開機選單。本文以 Ubuntu Live CD 修復 Fedora (/dev/sda3) 為例,步驟通用於所有 GRUB2 發行版。

GRUB 修復示意圖

前置準備

  1. 製作 Ubuntu Live USB:
    sudo dd if=ubuntu-13.10-desktop-amd64.iso of=/dev/sdb bs=4M status=progress
  2. 從 Live USB 開機,選擇 Try Ubuntu 進入試用桌面。

修復步驟

1. 確認目標分區

sudo fdisk -l
# 或使用 GParted 圖形介面
# 找出 Linux 根分區,例:/dev/sda3

2. 掛載根分區

sudo mount /dev/sda3 /mnt

3. 掛載虛擬檔系統 (bind mount)

sudo mount --bind /dev  /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys  /mnt/sys

4. 進入 chroot 環境

sudo chroot /mnt

5. 重新安裝與更新 GRUB

# 安裝至磁碟 (非分區)
grub2-install /dev/sda
# 產生設定檔
grub2-mkconfig -o /boot/grub2/grub.cfg
# 若為 Ubuntu/Debian 系統:
# grub-install /dev/sda
# update-grub

6. 退出並卸載

exit
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt

7. 重啟驗證

reboot

關鍵注意事項

  • 目標裝置:grub-install /dev/sda (整顆磁碟),非 /dev/sda3 (分區)。
  • UEFI 系統:需掛載 EFI 分區 (/boot/efi) 並加入 --target=x86_64-efi --efi-directory=/boot/efi 參數。
  • LVM/加密分區:需先 vgchange -ay、cryptsetup open 才能掛載。
  • 網路安裝:若 grub2-install 缺失模組,可在 chroot 內 apt update && apt install grub2。

常見錯誤排查

錯誤原因解決
cannot find EFI directoryUEFI 模式未掛載 ESP 分區掛載 /boot/efi 並加入 --efi-directory
failed to get canonical pathbind mount 遺漏 /dev /proc /sys補齊三個 bind mount 後再 chroot
grub.cfg 未更新未執行 grub2-mkconfig / update-grub務必重新產生設定檔

小結

「Live USB + 掛載 + chroot + grub-install + update-grub」是修復 GRUB 的標準流程。熟記此 7 步驟,無論 Windows 更新、磁碟調整或誤操作導致引導損壞,皆可在 10 分鐘內恢復多重開機環境。

copyright © 萬盛學電腦網 all rights reserved