1. 程式人生 > >Linux:安裝雙系統(Win7+Ubuntu)後,Ubuntu正常,Win7無法啟動

Linux:安裝雙系統(Win7+Ubuntu)後,Ubuntu正常,Win7無法啟動

作業系統版本:Ubuntu14.04.1和Windows7 sp1x64版

故障現象:

先安裝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啟動畫面。