Linux:安裝雙系統(Win7+Ubuntu)後,Ubuntu正常,Win7無法啓動,有需要的朋友可以參考下

操作系統版本:Ubuntu14.04.1和Windows7sp1x64版 故障現象:

先安裝Windows7 SP1 64位版,後使用U盤安裝Ubuntu 14.04.1。Ubuntu安裝成功後,可正常啓動,而GRUB上選擇Windows 7菜單項,無法啓動到Win7界面,直接返回GRUB菜單界面。

故障分析:

安裝Ubuntu的過程中經歷分區步驟,如下圖。在指定Boot Loader時並未選擇默認的選項/dev/sda,而是選擇/dev/sda1。因爲硬盤的活動分區是第一個分區sda1。Windows7安裝程序默認劃分一個100MB的小分區用於存儲啓動文件。而劃分的C盤則是硬盤上的第二個分區即sda2。此時如果將GRUB2的引導程序裝在“/”所在分區,會造成Ubuntu無法啓動,而本人又不想將GRUB2的引起程序裝在硬盤的MBR上。因此選擇將GRUB安裝windows的啓動分區Sda1上。

Ubuntu安裝成功,重啓選擇windows7啓動,結果悲劇出現。選擇Windows 7啓動菜單啓動Windows,毫無反映幾秒鐘後返回GRUB啓動菜單。

1.爲了分析問題打開 Ubuntu 軟件中心 安裝軟件“Inspect boot environment”也可直接搜索“boot-info-script”

2.打開終端,運行命令

sudo bootinfoscript

3.默認輸出結果到主文件夾中的RESULTS.txt,內容如下:

Boot Info Script 0.61 [1 April 2012]

====================== Boot Info Summary: ==========================

=> Windows is installed in the MBR of /dev/sda.

sda1: __________________________________________________________________________

File system: ntfs

Boot sector type: Grub2 (v1.99)

Boot sector info: Grub2 (v1.99) is installed in the boot sector of sda1

and looks at sector 1886304656 of the same hard drive

for core.img. core.img is at this location and looks

in partition 112 for . No errors found in the Boot

Parameter Block.

Operating System:

Boot files: /bootmgr /Boot/BCD

sda2: __________________________________________________________________________

File system: ntfs

Boot sector type: Windows Vista/7: NTFS

Boot sector info: No errors found in the Boot Parameter Block.

Operating System: Windows 7

Boot files: /Windows/System32/winload.exe

sda3: __________________________________________________________________________

File system: ntfs

Boot sector type: Windows Vista/7: NTFS

Boot sector info: No errors found in the Boot Parameter Block.

Operating System:

Boot files:

啓動信息上看Windows的啓動器安裝在主硬盤MBR上,而啓動文件安裝在Sda1上。啓動器爲bootmgr。Boot sector type是GRUB,並不是NTLDR。Boot sectorinfo中也不是Windows啓動器信息。由此可確定位於Sda1啓動扇區上的Windows啓動器已被GRUB所取代。因此,位於Sda1上的Windows啓動器被破壞。

4.下面再看看GRUB啓動腳本中的問題。進入/boot/grub目錄,打開grub.cfg文件查看,下面顯示的grub.cfg有關windows 7啓動的部分。

323 ### BEGIN /etc/grub.d/30_os-prober ###

324 menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-04EC18F4EC18E22A' {

325 insmod part_msdos

326 insmod ntfs

327 set root='hd0,msdos1'

328 if [ x$feature_platform_search_hint = xy ]; then

329 search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 04EC18F4EC18E22A

330 else

331 search --no-floppy --fs-uuid --set=root 04EC18F4EC18E22A

332 fi

333 parttool ${root} hidden-

334 chainloader +1

335 }

336 set timeout_style=menu

337 if [ "${timeout}" = 0 ]; then

338 set timeout=10

339 fi

340 ### END /etc/grub.d/30_os-prober ###

配置文件中Windows啓動部分,沒有問題。如果硬盤上的Windows啓動器沒有被GRUB破壞,那麼上面的配置完全可以正常工作。在這裏特別要提到Chainloader的含義

chainloader +1

chainloader用於切換啓動器,+1是指定啓動器所在硬盤扇區塊位置。334行裏的chainloader+1語句的含義是啓用在sda1的第一個塊的啓動器用於引導操作系統。此時sda1的第一個塊已經被GRUB所佔據,切換啓動器的結果就是再啓動一遍GRUB。因此當用戶在GRUB中選擇windows 7 loader後返回GRUB菜單就以爲怪了。

處理步驟

Win 7的啓動從MBR引導,第二步調用bootmgr,第三步調用winload.exe。最後由winload.exe完成win7系統的啓動。Sda1裏bootmgr文件保存良好,winload在系統文件夾中也未損壞。因此只要完成MBR到bootmgr的引導即可修復Windows啓動。

1.修改grub.cfg配置文件,Ubuntu中需要使用管理員權限。打開終端,輸入以下命令編輯配置文件:

sudo gedit /boot/grub/grub.cfg

2.修改334行的chainloader+1語句,替換成ntldr/bootmgr

........以上省略

331 search --no-floppy --fs-uuid --set=root 04EC18F4EC18E22A

332 fi

333 parttool ${root} hidden-

334 ntldr /bootmgr

335 }

.........以下省略

由ntldr命令完成MBR到bootmgr的引導。

3.保存配置文件,重新啓動計算機。你將會看到熟悉的win7啓動畫面。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章