2019年12月21日 星期六

2019-12-21 21:30 Windows 10開機引導錯誤BCD修正(MBR)

原打算在磁碟、磁區復原測試一併帶過,但發現實際的內容有些龐雜、另寫本篇。這篇是針對開機發生0xc000000e或0xc000000f錯誤、無法以\Windows\system32\winload.exe引導開機、且「啟動修復」完全無法處理的情況、如何由Windows Recovery Environment(疑難排解-命令提示字元的Windows RE、PE變體)下、透過Bcdedit修改BCD紀錄修復開機引導問題。

先提議最簡便的方式--在系統還正常時、以Bcdedit /export備份BCD,之後可透過Bcdedit /import還原損壞的BCD;或直接在Windows RE進入MBR磁碟的系統保留分割區\Boot 或者GPT磁碟的EFI分割區(需先自行設定磁碟代號) \EFI\Microsoft\Boot 直接複製備份隱藏的BCD檔、日後碰上BCD檔損壞可直接還原、最省事。

首先透過Windows 10安裝媒體(DVD或USB隨身碟)進入疑難排解-命令提示字元(千萬別用Shift+F10的方式進入、將遭遇檔案鎖定而無法完成操作的情況)進入Windows RE。也可藉此先備份前述的BCD檔。

執行 Bcdedit /enum all /v 列舉BCD全部項目、應當會見到類似以下內容(原始BCD內容頗多、難以擷圖呈現、只節錄可能受影響需修改的區塊)

Windows 開機管理程式
--------------------
identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device partition=C:
description Windows Boot Manager
locale zh-TW
inherit {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default {1ede9478-2108-11ea-9755-8e663bbbaab2}
resumeobject {1ede9477-2108-11ea-9755-8e663bbbaab2}
displayorder {1ede9478-2108-11ea-9755-8e663bbbaab2}
toolsdisplayorder {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout 30

Windows 開機載入器
-------------------
identifier {1ede9478-2108-11ea-9755-8e663bbbaab2}
device unknown
path \Windows\system32\winload.exe
description Windows 10
locale zh-TW
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {1ede9479-2108-11ea-9755-8e663bbbaab2}
displaymessageoverride Recovery
recoveryenabled Yes
allowedinmemorysettings 0x15000075
osdevice unknown
systemroot \Windows
resumeobject {1ede9477-2108-11ea-9755-8e663bbbaab2}
nx OptIn
bootmenupolicy Standard

Windows 開機載入器
-------------------
identifier {1ede9479-2108-11ea-9755-8e663bbbaab2}
device ramdisk=[unknown]\Recovery\WindowsRE\Winre.wim,{1ede947a-2108-11ea-9755-8e663bbbaab2}
path \windows\system32\winload.exe
description Windows Recovery Environment
locale zh-tw
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
displaymessage Recovery
osdevice ramdisk=[unknown]\Recovery\WindowsRE\Winre.wim,{1ede947a-2108-11ea-9755-8e663bbbaab2}
systemroot \windows
nx OptIn
bootmenupolicy Standard
winpe Yes
custom:46000010 Yes

休眠後繼續
---------------------
identifier {1ede9477-2108-11ea-9755-8e663bbbaab2}
device unknown
path \Windows\system32\winresume.exe
description Windows Resume Application
locale zh-TW
inherit {1afa9c49-16ab-4a5c-901b-212802da9460}
recoverysequence {1ede9479-2108-11ea-9755-8e663bbbaab2}
recoveryenabled Yes
allowedinmemorysettings 0x15000075
filedevice unknown
filepath \hiberfil.sys
bootmenupolicy Standard
debugoptionenabled No

裝置選項
--------------
identifier {1ede947a-2108-11ea-9755-8e663bbbaab2}
description Windows Recovery
ramdisksdidevice unknown
ramdisksdipath \Recovery\WindowsRE\boot.sdi

開機失敗主因是當中紅字項目的設定值為 unknown 導致無法正常引導開機。

這時以 Bcdedit /set {identifier GUID} object value 逐項修正,除Windows Recovery Environment的Windows開機載入器與搭配的裝置選項(虛擬磁碟boot.sdi檔)此項以外、所有 unknown 的項目,device、osdevice、filedevice修正值為 partition=Windows所在的磁碟代號,可用 Bootrec /scanos 指令確認(以Windows RE當下查詢的磁碟代號為準、千萬不可直接以C:代入、否則也將引導錯誤)。

例如修改Windows 10的Windows 開機載入器這項所含的2筆錯誤值,操作指令為

Bcdedit /set  {1ede9478-2108-11ea-9755-8e663bbbaab2} device partition=D:

Bcdedit /set  {1ede9478-2108-11ea-9755-8e663bbbaab2} osdevice partition=D:

Windows Recovery Environment的Windows開機載入器{1ede9478-2108-11ea-9755-8e663bbbaab2}此項的deviceosdevice、則是將 unknown 改為Windows RE分區磁碟代號(注意含[ ]括號)並保留其餘舊值

Bcdedit /set  {1ede9479-2108-11ea-9755-8e663bbbaab2}  device ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{1ede947a-2108-11ea-9755-8e663bbbaab2}

Bcdedit /set    {1ede9479-2108-11ea-9755-8e663bbbaab2} osdevice ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{1ede947a-2108-11ea-9755-8e663bbbaab2}

Windows Recovery Environmen相應的Windows Recovery虛擬磁碟裝置{1ede947a-2108-11ea-9755-8e663bbbaab2}此項的ramdisksdidevice分區 unknown   也一併改為與Windows RE所在相同磁碟代號

Bcdedit  /set     {1ede947a-2108-11ea-9755-8e663bbbaab2}   ramdisksdidevice  partition=E:

 

以上為參考範例、實際的BCD identifier GUID請以 Bcdedit /enum all /v 列舉為準、Windows所在磁碟代號由Windows PE/RE以   Bootrec /scanos 查詢為準。若   Bootrec /scanos  無法正確判斷Windows安裝位置、請以 Diskpart 的 list disk / part / vol 查詢各分區研判Windows Recovery Environment (\Recovery\WindowsRE\winre.wim)所在以及相應的Windows Recovery虛擬磁碟檔(\Recovery\WindowsRE\boot.sdi)可能直接存在於系統分區、或者獨立的復原分區,也請自行確認。

某些情況下Windows RE將會安裝於系統分區、而非以獨立復原分區安裝,若欲將存在於Windows所在分區的Windows RE搬移至另行規劃的復原分區、以避免Windows RE連帶損壞的情況,可先新增一額外的NTFS分區(大小約600MB,必須移除磁碟代號、否則該分區Windows RE將失效),接著進入Windows RE、透過Diskpart進入該分區(sel disk # -> sel part #)以   set id=27   設置為復原分區類型、再將系統分區下的Recovery隱藏目錄透過xcopy /e /h完整複製至該復原分區,最後透過上述方式重新設定Windows RE以及搭配的裝置選項所在位置至還原分區。

 

一般介紹的修正開機方式多以刪除原有問題BCD,再透過 Bootrec /rebuildbcd 重新偵測系統中Windows所在位置、並提示使用者新增至BCD(重建)的方式,或以Bcdboot \Windows_path\ /S C: /F ALL /L zh-TW 將位置確定的Windows啟動項目「重增」於BCD解決,似乎也很妥當(但若Bootrec /scanos 無法正確研判系統分區配置、則Bootrec /rebuildbd 亦無法重建BCD

先看看以 Bootrec /rebuildbcd 方式重建的BCD(重建的僅有以下內容以及刪除的Windows 記憶體測試器引導)

Windows 開機管理程式
--------------------
identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device partition=C:
path \bootmgr
description Windows Boot Manager
locale zh-TW
default {ce0a49a5-23f7-11ea-ad4d-a0ed28f09187}
displayorder {ce0a49a5-23f7-11ea-ad4d-a0ed28f09187}
timeout 30

Windows 開機載入器
-------------------
identifier {ce0a49a5-23f7-11ea-ad4d-a0ed28f09187}
device partition=E:
path \Windows\system32\winload.exe
description Windows 10 Enterprise
locale zh-TW
recoverysequence {ce0a49a6-23f7-11ea-ad4d-a0ed28f09187}
recoveryenabled Yes
osdevice partition=E:
systemroot \Windows
bootmenupolicy Standard

Windows 開機載入器
-------------------
identifier {ce0a49a6-23f7-11ea-ad4d-a0ed28f09187}
device ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{ce0a49a7-23f7-11ea-ad4d-a0ed28f09187}
path \windows\system32\winload.exe
description Windows Recovery Environment
locale zh-TW
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
displaymessage Recovery
osdevice ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{ce0a49a7-23f7-11ea-ad4d-a0ed28f09187}
systemroot \windows
nx OptIn
bootmenupolicy Standard
winpe Yes
custom:46000010 Yes

裝置選項
--------------
identifier {ce0a49a7-23f7-11ea-ad4d-a0ed28f09187}
description Windows Recovery
ramdisksdidevice partition=E:
ramdisksdipath \Recovery\WindowsRE\boot.sdi

 

很明顯少了相當的項目、不過Windows RE的引導還在、之後的測試也正常。再看看以 Bcdboot \Windows_path\ /S C: /F ALL /L zh-TW將Windows啟動「重增」的BCD

Windows 開機管理程式
--------------------
identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device partition=C:
description Windows Boot Manager
locale zh-TW
inherit {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default {2d2c3b86-234c-11ea-9c81-bd5c8869bb1f}
resumeobject {2d2c3b85-234c-11ea-9c81-bd5c8869bb1f}
displayorder {2d2c3b86-234c-11ea-9c81-bd5c8869bb1f}
{1ede9478-2108-11ea-9755-8e663bbbaab2}
toolsdisplayorder {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout 30

Windows 開機載入器
-------------------
identifier {2d2c3b86-234c-11ea-9c81-bd5c8869bb1f}
device partition=E:
path \Windows\system32\winload.exe
description Windows 10
locale zh-TW
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
allowedinmemorysettings 0x15000075
osdevice partition=E:
systemroot \Windows
resumeobject {2d2c3b85-234c-11ea-9c81-bd5c8869bb1f}
nx OptIn
bootmenupolicy Standard

休眠後繼續
---------------------
identifier {2d2c3b85-234c-11ea-9c81-bd5c8869bb1f}
device partition=E:
path \Windows\system32\winresume.exe
description Windows Resume Application
locale zh-TW
inherit {1afa9c49-16ab-4a5c-901b-212802da9460}
allowedinmemorysettings 0x15000075
filepath \hiberfil.sys
bootmenupolicy Standard

相較 Bootrec /rebuildbcd 「重建」BCD, Bcdboot \Windows_path\ /S C: /F ALL /L zh-TW「還原」的BCD內容似乎較多(還有部分與復原前相同內容刪除),但未包Windows RE引導。

因此若不願以 Bcdedit /set 逐項修改、或係因BCD完全損毀而無法修改,建議以  Bootrec /rebuildbcd 「重建」BCD、起碼相較 Bcdboot \Windows_path\ /S C: /F ALL /L zh-TW「重增」Windows啟動的BCD、Windows RE能正常運作(Bootrec /rebuildbcd  消失的休眠裝置也可透過Windows休眠功能重新設定)。

或者、透過Bcdboot \Windows_path\ /S C: /F ALL /L zh-TW「還原」BCD後、也可在進入Windows後、透過 Reagentc  /disable 停用Windows RE再以 Re  agentc  /ensable 重建BCD內的Windows RE啟動項目。

以上的情況為BIOS/MBR磁碟開機引導的修正、EFI/GPT磁碟的BCD處理也是近似方式處理。

沒有留言:

張貼留言