Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux 伺服器

讓 Vista 開機選單掛上 Linux:Grub 裝進分區的雙引導實作

把 GRUB 裝在硬碟 MBR 上就能實現 Windows 與 Linux 雙重開機,這是最常見的做法。但它有個惱人的缺點(本質上是 Windows 的缺點):每次重裝 Windows,MBR 都會被覆蓋掉。而修回 GRUB 需要一張像樣的 Linux 安裝光碟(如 Debian),或任何帶有 GRUB 的救援碟。

其實 Windows 自己的 Boot Manager 也能啟動 Linux,方法是把 GRUB 裝在 Linux 分區上,而不是 MBR。

第一步:把 GRUB 裝到 Linux 分區

安裝 GRUB 時通常就有這個選項。若要手動安裝,假設你的 Linux 分區是 /dev/hda2(在 GRUB 中的寫法是 (hd0,1)):

# grub
grub> setup (hd0,1)

注意 GRUB 的磁碟與分區編號都從 0 開始,所以 /dev/hda2 對應 (hd0,1),容易搞錯。

第二步:把開機扇區存成檔案

把 /dev/hda2 的頭 512 bytes 讀出來,寫成檔案:

# dd if=/dev/hda2 of=linux.boot bs=512 count=1

第三步:把檔案搬到 Windows 分區

NTFS 從 Linux 寫入向來麻痺,比較實際的做法是透過網路複製到另一台機器,或先丟進隨身碟,回到 Windows 再複製回來。以下假設放到了 C:\linux.boot。

第四步:設定開機選單

Windows XP

直接編輯 C:\boot.ini,加上一行:

linux.boot="Linux"

重新開機後就會看到 Linux 選項,進入後應出現 GRUB 選單。

Windows Vista

Vista 的 Boot Manager 設定較繁瑣。先執行:

bcdedit /enum all | find "{ntldr}"

若回傳 identifier 為 {ntldr},走方案 B;否則走方案 A。

方案 A

bcdedit /create {ntldr} /d "Linux"
bcdedit /set {ntldr} device boot
bcdedit /set {ntldr} path linux.boot
bcdedit /displayorder {ntldr} /addlast

方案 B(需依第一條指令的實際回傳值替換 identifier)

C:\>bcdedit /copy {ntldr} /d "Linux"
The entry was successfully copied to {bcfa924e-07e0-11db-9d86-accf6fd346a1}.

C:\>bcdedit /set {bcfa924e-07e0-11db-9d86-accf6fd346a1} device boot
The operation completed successfully.

C:\>bcdedit /set {bcfa924e-07e0-11db-9d86-accf6fd346a1} path linux.boot
The operation completed successfully.

C:\>bcdedit /displayorder {bcfa924e-07e0-11db-9d86-accf6fd346a1} /addlast
The operation completed successfully.

重啟後,Vista 的啟動介面就會多出 Linux 這個選項。這種做法的最大好處是:以後重裝 Windows 也不會再弄丟你的 Linux 引導,只要重跑一次 dd 與 bcdedit 即可。

Copyright © Linux教程網 All Rights Reserved