萬盛學電腦網

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

Win7+Ubuntu 12.04 雙系統重裝 Win7 後 GRUB 引導修復全記錄

重裝 Windows 7 會覆寫 MBR,導致原有 GRUB 引導消失,無法進入 Ubuntu。本文記錄通過編輯 grub.cfg 隱藏多餘啟動項、調整啟動順序的完整修復過程。

現象

重裝 Win7 後直接進入 Windows,無 GRUB 選單。需從 Ubuntu Live USB 啟動修復。

修復步驟

1. 掛載 Ubuntu 根分區並編輯 grub.cfg

  1. 啟動 Ubuntu Live USB → 選擇「Try Ubuntu」。
  2. 開啟終端機,掛載根分區(假設為 /dev/sda5):
    sudo mount /dev/sda5 /mnt
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
  3. 進入 chroot 環境:
    sudo chroot /mnt
  4. 編輯 GRUB 設定:
    gedit /boot/grub/grub.cfg

2. 隱藏/刪除多餘啟動項

  • 搜尋 menuentry 關鍵字,找到欲隱藏的條目(如舊的 "Windows 7 (loader) (on /dev/sda2)")。
  • 在該條目整個區塊(從 menuentry 到對應的大括號結尾)每行行首加 # 註解掉。
  • 儲存檔案。
grub.cfg 原始內容
註解掉多餘啟動項

3. 調整啟動順序(將 Windows 7 設為預設第一項)

  • GRUB2 透過 /etc/grub.d/ 目錄下腳本編號決定順序:
    00_header, 05_debian_theme, 10_linux (Ubuntu), 30_os-prober (Windows)。
  • 將 30_os-prober 重命名為 09_os-prober(優先於 10_linux):
    mv /etc/grub.d/30_os-prober /etc/grub.d/09_os-prober
  • 更新 GRUB:
    update-grub

4. 重新安裝 GRUB 到 MBR

  1. 退出 chroot:exit
  2. 安裝 GRUB:sudo grub-install /dev/sda(目標為整顆硬碟,非分區)。
  3. 重啟,移除 Live USB,應進入 GRUB 選單,Windows 7 位於首位。

注意事項

  • 修改 grub.cfg 為臨時方案,update-grub 會重新生成覆蓋。永久調整須修改 /etc/grub.d/ 腳本或 /etc/default/grub(GRUB_DEFAULT)。
  • UEFI 系統需掛載 EFI 分區,使用 grub-install --target=x86_64-efi --efi-directory=/boot/efi。
  • Ubuntu 12.04 已停止支援,強烈建議升級至 LTS 版本(20.04/22.04/24.04)。

掌握 GRUB 修復核心邏輯,雙系統重裝不再恐懼。

copyright © 萬盛學電腦網 all rights reserved