作者 主題: grub 裝於次硬碟之boot sector的啟動請教  (閱讀 69557 次)

0 會員 與 1 訪客 正在閱讀本文。

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
1.
xp 先安於 hda
linux 後裝於 hdb, 而 grub 安裝時選擇裝於 boot sector 而非 MBR
--> 如何啟動 linux ?

2.
之後採取如下動作:
dd if=/dev/zero of=/dev/hda bs=446 count=1
linux-rescue mode 下作 grub-install /dev/hda
--> 重開機後於grub選單選windows,但無法啟動...請問這是哪兒出了問題?

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #1 於: 2009-05-09 02:22 »
spfdisk 做完後,與grub一樣的結果,windows還是無法開機...

看了一下鳥哥的網站,我的理解若有錯誤還望指正:

因為我後來將grub裝於hda的MBR,所以開機會以grub為首個 boot loader 並調選單供 user 選擇.而若是我選擇 xp 開機,則 grub 會轉交控制權給另一個 loader(即xp的loader)去啟動 xp.

換句話說,我硬碟的 xp 的 boot loader 可能已損毀....若真為如此,不知有何解決之道?

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #2 於: 2009-05-09 03:25 »
上面的 dd 已經將 hda 的 mbr 摧毀了。
直接將 grub 裝到 mbr 就好了,不需要用 spfdisk ,用 rescue disk 進去跑 grub 安裝就好。

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #3 於: 2009-05-09 11:54 »
感謝 netman 大!  :)

不好意思,可我現況就是已經在 linux-rescue mode 下作過 grub-install /dev/hda
xp啟動不了(僅到出現F8畫面),此動作不就是將GRUB安裝到MBR,難道是我誤解了?

不知 windows boot loader 可否重安裝?另外請教如當我們安裝windows xp時其loader預設是否僅安裝到hda的MBR中?...若是,那隨後在裝linux時,若grub亦裝於hda的MBR,那豈不是會覆蓋掉windows boot loader,根據鳥哥網站說法(http://linux.vbird.org/linux_basic/0130designlinux.php#partition_mbr),那 grub 如何找到 windows loader 並將控制權交給它去繼續啟動 windows ?


darkranger

  • 榮譽學長
  • 俺是博士!
  • *****
  • 文章數: 1384
    • 檢視個人資料
    • https://darkranger.no-ip.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #4 於: 2009-05-09 17:10 »

不好意思,可我現況就是已經在 linux-rescue mode 下作過 grub-install /dev/hda
xp啟動不了(僅到出現F8畫面),此動作不就是將GRUB安裝到MBR,難道是我誤解了?
F8畫面?什麼意思?

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #5 於: 2009-05-09 18:55 »
sorry,是安全模式的menu畫面.

果然真不是loader的問題,而是usb外接硬碟造成.不大清楚原因(??),將其拔掉後windows就可正常啟動.

但是我接著嘗試將 grub 裝於 hdb 的 boot sector:
grub> root (hd1,0) #我的/boot是獨立的partition
grub> setup (hd1,0)
安裝過程正常: stage1,stage2,kernel image都有被找到.

bios 也設定以 hdb 為開機碟...但啟動linux時卻出現錯誤訊息:
先列出 grub.conf (我是用rhel5)的設定,然後顯示 - couldn't mount selected filesystem
確定設定無誤...我系統多為LVM filesystem,但/boot的partition則是ext3,在grub shell設定 root (hd1,0) 時,其出現的結果竟是ext2 的檔案系統....不知問題是否與此有關?
« 上次編輯: 2009-05-09 18:59 由 b90220208 »

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #6 於: 2009-05-09 22:30 »
跑一下 pvscan 跟 vgscan ,找出 VG 之後:
vgchange -a y VG_NAME

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #7 於: 2009-05-10 20:07 »
跑一下 pvscan 跟 vgscan ,找出 VG 之後:
vgchange -a y VG_NAME
感謝 netman 大,但不大懂您的意思..
先請教一下該 error message :couldn't mount selected filesystem -> 指的是哪個 filesystem ?

以下 result 是當我將 grub 改裝於 hda 的 MBR 後,可正常啟動時的情形:
其中 /dev/hdb1 為 /boot  且其並非 LVM! 另外, 我所有的 VG 皆已 active !

...不懂為何只要當我將 grub 改裝至 /dev/hdb boot  sector 時就啟動失敗(掛載不了)?

===========================================
   Device Boot      Start         End      Blocks       Id    System
/dev/hdb1   *           1          13      104391      83    Linux
/dev/hdb2              14         535     4192965     fd    Linux raid autodetect
/dev/hdb3             536        1057     4192965    fd    Linux raid autodetect
/dev/hdb4            1058        2498    11574832+   5    Extended
/dev/hdb5            1058        1579     4192933+   8e   Linux LVM
/dev/hdb6            1580        2101     4192933+   8e    Linux LVM
/dev/hdb7            2102        2228     1020096     fd    Linux raid autodetect
/dev/hdb8            2229        2355     1020096     fd    Linux raid autodetect
/dev/hdb9            2356        2498     1148616     8e    Linux LVM

[root@server1 ~]# lvscan
  ACTIVE            '/dev/VolGroup01/LogVol00' [1.88 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [6.62 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol01' [2.00 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol02' [4.00 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol03' [4.00 GB] inherit

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #8 於: 2009-05-10 22:55 »
哦,還以為你要 mount 的 LVM 還沒 active 呢。
原來不是,那我所答的就不對了。

或許看看 menu.lst 的設定是否也改到 sdb 了?

hikohan

  • 俺是博士!
  • *****
  • 文章數: 1288
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #9 於: 2009-05-11 09:12 »
裝在hda可以開機,這是第一個線索。

裝在hdb的MBR?那hda的boot loader是什麼?只要hda的boot loader是可以載入grldr或選單進入hdbN的grub/lilo選單,那就可以載入kernel開機。
lifeIsFunWithPHP.

harrier

  • 榮譽博士
  • 俺是博士!
  • *****
  • 文章數: 1856
  • 性別: 男
    • 檢視個人資料
    • 國屬武裝兵
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #10 於: 2009-05-11 14:47 »
1.
xp 先安於 hda
linux 後裝於 hdb, 而 grub 安裝時選擇裝於 boot sector 而非 MBR
--> 如何啟動 linux ?

hda 的哪裡?1,2,3,4??
hdb 的哪裡?1,2,3,4??

Windows 的啟動流程是看哪個 partition 是 active,然後去啟動 partition 下 ntldr...
Linux 是 mbr -> 指定的 partition -> 載入該 partition superblock 的 loader...
...90Net(90:1200/1203),GameNET(99:700/707),ALLNet(92:9200/3111),InfoNet(30:100/103)..MaximusCBCS(浮懷),AirNet,TenderNet,StormNet,FidoNet...
<<- www.nas.vg ->>

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #11 於: 2009-05-11 15:54 »
Thanks!  :)

1.
xp 先安於 hda
linux 後裝於 hdb, 而 grub 安裝時選擇裝於 boot sector 而非 MBR
--> 如何啟動 linux ?

hda 的哪裡?1,2,3,4??
hdb 的哪裡?1,2,3,4??

xp :
1.)  /dev/hda1 (c槽=整顆硬碟)

linux(rhel5) :
1.)  /dev/hdb1 的掛載點: /boot (filesystem: ext3)
2.)  grub> root (hd1,0)
      grub> setup (hd1,0) #就是/dev/hdb1
     
     PS.  安裝 GRUB LOADER 前,有先作過: dd if=/dev/zero of=/dev/hda bs=446 count=1

Windows 的啟動流程是看哪個 partition 是 active,然後去啟動 partition 下 ntldr...
Linux 是 mbr -> 指定的 partition -> 載入該 partition superblock 的 loader...



裝在hda可以開機,這是第一個線索。

裝在hdb的MBR?那hda的boot loader是什麼?只要hda的boot loader是可以載入grldr或選單進入hdbN的grub/lilo選單,那就可以載入kernel開機。

hda 裝 xp 所以 boot loader 應該就是 windows 的.
不過之後有執行過: dd if=/dev/zero of=/dev/hda bs=446 count=1 所以 hda 的 MBR 的前 446bytes 應該是清掉了.

PS. bios 中開機硬碟設定為: hdb(裝 LINUX 的那顆)
« 上次編輯: 2009-05-11 15:58 由 b90220208 »

hikohan

  • 俺是博士!
  • *****
  • 文章數: 1288
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #12 於: 2009-05-11 16:05 »
grub裝在hdb MBR的意思是不是你去調bios的開機硬碟順序?  :P
lifeIsFunWithPHP.

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #13 於: 2009-05-11 17:37 »
 :P :P 不好意思,等一下,
可否先請教一下:

一直搞不是很清楚,趁機請教一下各位(有誤請糾正).例如(參考自:http://www.pczone.com.tw/vbb3/thread/39/50519/)
1.) 假若我裝 WINDOWS 於 PRIMARY MASTER 的硬碟(hda1)上的第一個分割區時:
-> 此情形,請教 hda 之 MBR (第零軌上第一個磁區)上的程式區(Pre-Loader/Pre-Boot)上的小程式是否就是 WINDOWS 的 BOOT LOADER?
-> hda 之 boot sector 上又有些甚麼?
-> ntldr 在流程中的角色? 

2.) 而安裝 linux 時的狀況與 windows 是否一樣?
« 上次編輯: 2009-05-11 17:39 由 b90220208 »

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #14 於: 2009-05-11 20:32 »
基本上每顆硬碟都有一個 MBR,這是第一個 sector (512byte)。
過了這個 sector 才是 partition,可以分一個單一 partition 也可以分多個 partition。
然後每一個 partition 的第一個 sector 就是 boot sector (也有其他名稱)

一般的 loader 可以放在 MBR 里面的 446byte 也可以放在 partition 前的 boot sector。
但 BIOS 只會找到 MBR 來開機。
也就是說,如果你將 loader 放在 boot sector,
那 MBR 那邊所開的 loader 必需有一個 entry 指到你所裝的 boot sector 才能開。
通常這也叫 chain loader。

ntld 我不確定是放哪?
但 linux 的 loader 太大了,要分開 stage1 跟 stage2,
其中的 stage2 是在 file system 里面(partition里面),
但 stage1 放 MBR 或 boot sector 都行。
但如果你選擇放 boot sector,那就請修改 MBR 開的那個 loader,
多加一個 entry 給 chain 到你的 boot sector 去。

這些在一般的 Linux 課程都會講到的,有空可以上上課,那就更清楚了。

darkranger

  • 榮譽學長
  • 俺是博士!
  • *****
  • 文章數: 1384
    • 檢視個人資料
    • https://darkranger.no-ip.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #15 於: 2009-05-11 20:43 »
-> ntldr 在流程中的角色? 
ntldr 就是 Windows 的 boot loader


b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #16 於: 2009-05-12 01:17 »
Thanks a lot! ::) ::)

hikohan 兄:
我是將 grub 裝在 hdb 的 boot sector 非 MBR .

如果是 netman 大開的課我一定報名!  :)
可惜我住台北...現在網路這麼發達,如有遠距教學也不錯! 

但 linux 的 loader 太大了,要分開 stage1 跟 stage2,
其中的 stage2 是在 file system 里面(partition里面),
但 stage1 放 MBR 或 boot sector 都行。
但如果你選擇放 boot sector,那就請修改 MBR 開的那個 loader,
多加一個 entry 給 chain 到你的 boot sector 去。

netman 大的解說若化為行動,不就是:

install grub loader
grub> root (hd1,0)
grub> find /grub/stage1
grub> find /grub/stage2
grub> setup (hd1,0)

然後是,

/etc/grub.conf 設定:
title RHEL 5 Server (2.6.18-53.el5)
        root (hd1,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quie
t crashkernel=128M@16M
        initrd /initrd-2.6.18-53.el5.img
title Windows XP
        rootnoverify (hd0,0)
        chainloader +1

.....難道是好事多磨(且我有在 BIOS 中設定 hdb 為開機碟,開機順序是: cd-rom->hard disk),為何我會開不了?
有沒有可把 MBR or Boot Sector 內容倒出來看的工具?

可否請教 darkranger 兄 NTLDR 是如何啟動 windows xp 的?感激不盡! :)

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #17 於: 2009-05-12 01:22 »
grub> setup (hd1)

看看?

fillano

  • 鑽研的研究生
  • *****
  • 文章數: 526
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #18 於: 2009-05-12 09:31 »
基本上每顆硬碟都有一個 MBR,這是第一個 sector (512byte)。
過了這個 sector 才是 partition,可以分一個單一 partition 也可以分多個 partition。
然後每一個 partition 的第一個 sector 就是 boot sector (也有其他名稱)

一般的 loader 可以放在 MBR 里面的 446byte 也可以放在 partition 前的 boot sector。
但 BIOS 只會找到 MBR 來開機。
也就是說,如果你將 loader 放在 boot sector,
那 MBR 那邊所開的 loader 必需有一個 entry 指到你所裝的 boot sector 才能開。
通常這也叫 chain loader。

ntld 我不確定是放哪?
但 linux 的 loader 太大了,要分開 stage1 跟 stage2,
其中的 stage2 是在 file system 里面(partition里面),
但 stage1 放 MBR 或 boot sector 都行。
但如果你選擇放 boot sector,那就請修改 MBR 開的那個 loader,
多加一個 entry 給 chain 到你的 boot sector 去。

這些在一般的 Linux 課程都會講到的,有空可以上上課,那就更清楚了。

這樣講好像怪怪的?

MBR的結構是:前440bytes是程式,然後有一些disk signature,從446開始是64bytes的partition table,總共有4個entry,每個16bytes,最後是0x55AA的signature。這些全部都在這512bytes中。

bootloader一定有部份放在前面這440bytes的空間,因為bios在開機後會把這512bytes載入記憶體,然後從區段位址0開始執行。如果這440bytes不夠用,接下來的部份要放哪裡就看怎麼設計,常常是會放在MBR之後的磁區中,然後透過這440bytes的程式碼載入。只要是用硬碟開機,所有x86 bios應該都是這樣執行的。

額外的程式包含ext2檔案系統讀取的程式,這樣就可以到/boot中讀取stage1的image,也就是initrd。

所以如果MBR裡面什麼都沒有,那開機以後就不會有任何動作。bios可不會載入boot sector的東西。(硬碟第零軌的第一個磁區是MBR,第一軌的第一個磁區是boot sector,每一個軌都有很多磁區的,所以其實MBR之後還有很多空間)


另外,也可以透過ntldr載入linux的bootloader,請上網找一找grub4dos。
Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung.

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #19 於: 2009-05-12 12:18 »
恩?你沒說怪在哪哦~~~

還有你說的那堆,跟我說的沒不一樣啊。?_?

fillano

  • 鑽研的研究生
  • *****
  • 文章數: 526
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #20 於: 2009-05-12 13:35 »
是喔,那是我誤解了。 :)
Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung.

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #21 於: 2009-05-12 15:41 »
哦,那輪到我了哦... ^_^

你說的 stage1 不是 initrd 哦。
stage1 若不放 MBR 那就是放 boot sector,
它的功能只有一個:載入 stage2

fillano

  • 鑽研的研究生
  • *****
  • 文章數: 526
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #22 於: 2009-05-12 16:10 »
了解了,謝謝您。
Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung.

darkranger

  • 榮譽學長
  • 俺是博士!
  • *****
  • 文章數: 1384
    • 檢視個人資料
    • https://darkranger.no-ip.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #23 於: 2009-05-12 19:28 »
可否請教 darkranger 兄 NTLDR 是如何啟動 windows xp 的?感激不盡! :)
原理嗎?我不知道
我只知道我曾經把 NTLDR 砍了,然後就發生悲劇了....

davihuan

  • 榮譽博士
  • 憂鬱的高中生
  • ***
  • 文章數: 96
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #24 於: 2009-05-12 20:26 »
可否請教 darkranger 兄 NTLDR 是如何啟動 windows xp 的?感激不盡! :)
原理嗎?我不知道
我只知道我曾經把 NTLDR 砍了,然後就發生悲劇了....

NTLDR的原理?想要知道什麼?知道了也不能怎樣.....又不是GRUB4DOS什麼奇怪的東西都可以啟動!!!

hikohan

  • 俺是博士!
  • *****
  • 文章數: 1288
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #25 於: 2009-05-12 21:53 »
http://phorum.study-area.org/index.php/topic,55709.0.html

的確,grub什麼都給他啟動下去。

linux kernel + NTLDR + GRLDR + DOS + ISO + Floppy Image + Iso Linux + loadlin.exe....
lifeIsFunWithPHP.

洋蔥叔叔

  • 榮譽博士
  • 鑽研的研究生
  • *****
  • 文章數: 830
    • 檢視個人資料
    • 洋蔥叔叔的隨意漫談電腦、網路、.NET、軟體本地化、雜七雜八
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #26 於: 2009-05-12 22:34 »
NTLDR 跟 Windows 的關係
就有如 Grub/LILO 跟 Linux 的關係

NTLDR 負責載入 Windows 核心,就有如 Grub/LILO 負責載入 Linux 核心。
Windows(nt 系列到 2003) 的 bootsector 只負責載入 NTLDR
只是 Windows 載入核心的程式碼比較肥大,無法只住在 Bootsector 或 MBR 裏面,所以才分割出來另外一個檔案。

至於上面講的 "grub什麼都給他啟動下去" 當然只是個迷思, GRUB 不支援載入 Windows 核心,只支援所謂 chainloader 來呼叫其他地方 bootsector 。
NTLDR 其實也支援類似 chainloader 的功能,理所當然也可以拿來載入 Linux (或精確一點說,呼叫在其他 bootsector 裏面的 GRUB/LILO)。




netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #27 於: 2009-05-13 01:11 »
有興趣的話,也可以看看 12 年前的舊文章:

http://www.tldp.org/HOWTO/Linux+NT-Loader.html

hikohan

  • 俺是博士!
  • *****
  • 文章數: 1288
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #28 於: 2009-05-13 04:33 »
..
至於上面講的 "grub什麼都給他啟動下去" 當然只是個迷思, GRUB 不支援載入 Windows 核心,只支援所謂 chainloader 來呼叫其他地方 bootsector 。
NTLDR 其實也支援類似 chainloader 的功能,理所當然也可以拿來載入 Linux (或精確一點說,呼叫在其他 bootsector 裏面的 GRUB/LILO)。

觀念清楚就不迷啦,觀念不清楚就迷啦,不就清楚迷觀念啦,不就觀念迷清楚啦。

感覺GRUB的大道理喔~
lifeIsFunWithPHP.

b90220208

  • 鑽研的研究生
  • *****
  • 文章數: 557
    • 檢視個人資料
回覆: grub 裝於次硬碟之boot sector的啟動請教
« 回覆 #29 於: 2009-05-13 09:08 »
各位提供的訊息我正在 K  :P 感激不禁!  :)

算算之前一共試裝了幾個不同的地方,
grub> setup (hd1) --> 失敗
grub> setup (hd1,0) --> 失敗
grub> setup (hd0) --> ok

錯誤訊息如下:

選單(黑白,非彩色)以 linux 開機時:
root (hd1,0)
Filesystem type unknown partition type 0x7

Kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crash kernel=128M@16M

Error 17: Cannot mount selected partition press any key to continue .....

選單以 windows 開機時:
Booting windows xp
rootnoverify (hd0,0)   
chainloader +1
GRUB loading stage2 .....
然後自行重開機

PS.
#(hd1,0) 是 linux 的 /boot 所在
#(hd0,0) 是 windows 的 c 槽所在
« 上次編輯: 2009-05-13 09:10 由 b90220208 »