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 與 Windows 多重開機實戰:GRUB2 與 NTLDR/BCD 雙向引導菜單配置全攻略

編輯:Linux 教學

前言:雙系統共存的引導鏈邏輯

多重開機核心在於「誰佔據 MBR/EFI」與「如何移交控制權」。兩大引導鏈:

  • Windows 鏈:MBR → NTLDR (XP/2003) / BOOTMGR (Vista+) → BCD (儲存啟動項) → 載入 winload.exe
  • Linux 鏈:MBR/EFI → GRUB2 (core.img + /boot/grub2/grub.cfg) → 載入 vmlinuz + initramfs

兩者可互相鏈式載入:GRUB2 chainloader +1 呼叫 Windows BCD;Windows bootsect/bcdedit 可新增 GRUB2 項目。

方案 A:Windows Boot Manager 為主 (保留 MBR 給 Windows)

步驟 1:安裝 Windows (先裝 Win,再裝 Linux 會覆蓋 MBR,需修復)

步驟 2:安裝 Linux,勿將 GRUB 裝入 MBR,改裝至 Linux 根分區 (如 /dev/sda3) 或專用 BIOS Boot Partition

步驟 3:Windows 下掛載 Linux 根分區 (Ext2Fsd/Paragon) 或使用 LiveUSB 取得 GRUB 核心映像

步驟 4:使用 EasyBCD / bcdedit 新增 Linux 項目


# EasyBCD 圖形化:Add New Entry → Linux/BSD → Type: GRUB2 → Name: Ubuntu → Partition: 自動/手動選擇
# 或命令列 (需 Administrator):
bcdedit /create /d "Ubuntu 22.04" /application bootsector
bcdedit /set {GUID} device partition=C:
bcdedit /set {GUID} path \grub\grubx64.efi  # UEFI
bcdedit /set {GUID} path \grub\core.img    # BIOS MBR (需先將 core.img 複製到 C:\grub\)
bcdedit /displayorder {GUID} /addlast

方案 B:GRUB2 為主 (GRUB 佔據 MBR/EFI,鏈載 Windows)

UEFI 環境 (現代標準,推薦)

  1. Windows 先裝,建立 EFI 系統分區 (ESP, 通常 /dev/sda1, FAT32)
  2. Linux 安裝時,同樣使用該 ESP (掛載點 /boot/efi),GRUB2 會自動偵測 /EFI/Microsoft/Boot/bootmgfw.efi 並新增菜單項
  3. UEFI 固件啟動順序第一優先序設為 ubuntu (或 debian, fedora)

BIOS/MBR 環境 (傳統)

  1. Windows 安裝於 /dev/sda1 (NTFS, 啟動旗標 *)
  2. Linux 安裝,GRUB 裝入 MBR (grub-install /dev/sda)
  3. grub-mkconfig -o /boot/grub/grub.cfg 自動偵測 Windows (需 os-prober 套件)
  4. 手動微調 /etc/grub.d/40_custom:

menuentry "Windows 10" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos1'
    chainloader +1
}

GRUB2 關鍵配置檔解析 (/boot/grub2/grub.cfg 或 /etc/default/grub)

參數說明範例
GRUB_DEFAULT預設啟動項 (編號、名稱、saved)saved (搭配 GRUB_SAVEDEFAULT=true 記住上次選擇)
GRUB_TIMEOUT菜單等待秒數5
GRUB_CMDLINE_LINUX核心啟動參數rhgb quiet / nomodeset
GRUB_DISABLE_OS_PROBER停用自動偵測其他 OSfalse (預設啟用)

修改後必須執行 grub2-mkconfig -o /boot/grub2/grub.cfg (或 update-grub) 重新生成。

修復 MBR / 重建 GRUB 常用急救指令


# Linux Live 環境下 (掛載根分區至 /mnt,EFI 分區至 /mnt/boot/efi)
# BIOS/MBR
grub2-install --root-directory=/mnt /dev/sda

# UEFI
grub2-install --root-directory=/mnt --efi-directory=/mnt/boot/efi --bootloader-id=ubuntu /dev/sda

# Windows 修復 MBR (Windows 安裝媒體 → 修復電腦 → 命令提示字元)
bootrec /fixmbr
bootrec /fixboot
bootrec /rebuildbcd

Grub4DOS / GRLDR 兼容舊版技術 (僅供維護舊系統參考)

  • grldr 為 GRUB Legacy 核心映像,menu.lst 內建菜單
  • Windows boot.ini 新增 C:\grldr="Linux" 鏈載
  • 現代系統請直接使用 GRUB2,勿再使用 Grub4DOS

結語

雙系統引導配置的核心原則:先裝 Windows,再裝 Linux;UEFI 共用 ESP;GRUB2 為主引導器;善用 os-prober 自動偵測。避免使用舊版 Grub4DOS、EasyBCD 等變通方案,原生 GRUB2 + UEFI 才是最穩定、最易維護、最符合標準的路徑。定期備份 /boot/efi/EFI/ubuntu/grubx64.efi 與 /boot/grub2/grub.cfg,配合 timeshift/snapper 快照,讓雙系統維護無憂。

Copyright © Windows教程網 All Rights Reserved