Windows command – BCDEdit

Loading

以前編輯 Boot Menu 只需要透邊文字編輯器即可,現在都需要透過工具才能編輯,如 Linux 下的 GRUB2 – https://benjr.tw/95009 , Windows 則需要透過 BCDEdit (Boot Configuration Data Store Editor) .

測試環境為 Windows 10 x86_64 (虛擬機)
使用 BCDEdit 需有系統管理員 (administrator) 的權限,在選單 windows system / command prompt 右鍵選擇 Run as administrator.

先來看一下目前的 BCD 設定,bcdedit 同 bcdedit /enum ,或是透過指令 msconfig / Boot 可以看到選單項目.
參數說明 :
/enum : Lists entries in a store.
更多關於 bcdedit 參數,請參考 https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/bcdedit-command-line-options

C:\Windows\system32>bcdedit

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume1
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  en-GB
inherit                 {globalsettings}
default                 {current}
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.efi
description             Windows 10
locale                  en-GB
inherit                 {bootloadersettings}
recoverysequence        {28e2c37c-bceb-11e8-81e9-c62cf0e5dbde}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
nx                      OptIn
bootmenupolicy          Standard

我們先來了解一下 Windows 的開機流程:
Legacy BIOS 會尋找開機硬碟中的 BOOTMGR 檔案 (就是 Windows Boot Manager 開機管理程式), UEFI 的檔案名稱則是 Bootmgfw.efi ,開機管理程式會去 讀取 BCD 的資料,並顯示 Windows Boot Loader 選單資訊.也會依據 BCD 設定位置執行 \windows\system32\winload.exe 來啟動 Windows .

BCD 設定主要有兩個區塊 Windows Boot Manager 與 Windows Boot Loader,設定參數參考如下:

  • identifier
    Globally Unique Identifiers (GUID) 一組識別碼, {bootmgr} 表示為 Windows Boot Manager entry.
  • device
    這裡就是 Boot 的磁區,可以透過指令 DISKPART 來檢視哪一個是 Boot Partition.

    C:\Windows\system32>DISKPART
    
    Microsoft DiskPart version 10.0.16299.15
    
    Copyright (C) Microsoft Corporation.
    On computer: DESKTOP-1SVSF9T
    
    DISKPART> select disk 0
    
    Disk 0 is now the selected disk.
    
    DISKPART> list volume
    
      Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
      ----------  ---  -----------  -----  ----------  -------  ---------  --------
      Volume 0     D                       DVD-ROM         0 B  No Media
      Volume 1     C                NTFS   Partition     59 GB  Healthy    Boot
      Volume 2                      FAT32  Partition    200 MB  Healthy    System
    
  • path
    這裡是指 system 磁區的路徑 \EFI\Microsoft\Boot\bootmgfw.efi , Windows Boot Manager (Bootmgr.exe), UEFI 的檔案名稱則是 Bootmgfw.efi
  • description
    說明敘述
  • locale
    位於哪個區域.
  • inherit
    {globalsettings} 表示為 Global settings that should be inherited by all boot applications.
    {bootloadersettings} 表示為 Global settings that should be inherited by all Windows boot loader applications.
  • default
    預設的開機選項
  • resumeobject
    The resume application identifier?
  • displayorder
    所列的是開機後的選單,可以透過 bcdedit /copy 複製現有的 Boot Entry 再修改 ,或是使用 bcdedit /create 把資料一一鍵入.
  • toolsdisplayorder
    顯示工具畫面 {memdiag} ?
  • timeout
    顯示選單秒數,預設為 30 秒,沒做選擇則使用預設的開機選項.

修改現有 BCD 資料

如果要修改資料內容,就透過 bcdedit /set {identifier} ,如下修改選單秒數.

C:\Windows\system32>bcdedit /set {bootmgr} timeout 100
The operation completed successfully.
C:\Windows\system32>bcdedit

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume1
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  en-GB
inherit                 {globalsettings}
default                 {current}
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 100

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.efi
description             windows 10
locale                  en-GB
inherit                 {bootloadersettings}
recoverysequence        {28e2c37c-bceb-11e8-81e9-c62cf0e5dbde}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
nx                      OptIn
bootmenupolicy          Standard

更多關於有哪一些參數可以設定請參考 https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit–set

新增現有 BCD 選單

開機後的選單,可以透過 bcdedit /copy 複製現有的 Boot Entry ,或是使用 bcdedit /create 把資料一一鍵入.

c:\>bcdedit /copy {current} /d "DebugEntry"
The entry was successfully copied to {28e2c37e-bceb-11e8-81e9-c62cf0e5dbde}.
c:\>bcdedit

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume1
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  en-GB
inherit                 {globalsettings}
default                 {current}
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
displayorder            {current}
                        {28e2c37e-bceb-11e8-81e9-c62cf0e5dbde}
toolsdisplayorder       {memdiag}
timeout                 100

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.efi
description             windows 10
locale                  en-GB
inherit                 {bootloadersettings}
recoverysequence        {28e2c37c-bceb-11e8-81e9-c62cf0e5dbde}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
nx                      OptIn
bootmenupolicy          Standard

Windows Boot Loader
-------------------
identifier              {28e2c37e-bceb-11e8-81e9-c62cf0e5dbde}
device                  partition=C:
path                    \Windows\system32\winload.efi
description             DebugEntry
locale                  en-GB
inherit                 {bootloadersettings}
recoverysequence        {28e2c37c-bceb-11e8-81e9-c62cf0e5dbde}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {28e2c37a-bceb-11e8-81e9-c62cf0e5dbde}
nx                      OptIn
bootmenupolicy          Standard

新增加了 DebugEntry ,開機後可以看到.

如果要把剛剛新增的 DebugEntry 改成為安全模式 (SafeMode) 開機,可以透過下面的方式.

C:\Windows\system32>bcdedit /set {28e2c37e-bceb-11e8-81e9-c62cf0e5dbde} safeboot Minimal
The operation completed successfully.

如果順序要修改可以透過 bcdedit /displayorder {ID} {ID}

新增 BCD 資料

通常修改的是系統目前所使用的 BCD ,如果是要給 PXEBoot WinPE – https://benjr.tw/917 的 BCD 可以透過下面的方式來新增.

C:\Windows\system32>bcdedit /createstore c:\BCD
The operation completed successfully.

新增關於 Setup Ramdisk Options 資料.

C:\Windows\system32>bcdedit /store c:\BCD /create {ramdiskoptions} /d "Ramdisk options"
The entry {ramdiskoptions} was successfully created.

C:\Windows\system32>bcdedit /store c:\BCD /set {ramdiskoptions} ramdisksdidevice boot
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
The operation completed successfully.

新增關於 Windows Boot Loader – winpe boot image 資料,會產生新 Entry 的 GUID ,同一個 Entry 都需要填寫該 GUID.

C:\Windows\system32>bcdedit /store c:\BCD /create /d "winpe boot image" /application osloader
The entry {d65e9db4-c095-11e8-8b94-005056e1d034} was successfully created.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} device ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} path \windows\system32\winload.exe 
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} osdevice ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} systemroot \windows
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} detecthal Yes
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD /set {d65e9db4-c095-11e8-8b94-005056e1d034} winpe Yes
The operation completed successfully.

新增關於 Windows Boot Manager 資料

C:\Windows\system32>bcdedit /store c:\BCD /create {bootmgr} /d "boot manager"
The entry {bootmgr} was successfully created.

C:\Windows\system32>bcdedit /store c:\BCD /set {bootmgr} timeout 30
The operation completed successfully.

C:\Windows\system32>bcdedit /store c:\BCD -displayorder {d65e9db4-c095-11e8-8b94-005056e1d034} -addlast
The operation completed successfully.
C:\Windows\system32>bcdedit /store C:\BCD /enum all

Windows Boot Manager
--------------------
identifier              {bootmgr}
description             boot manager
displayorder            {d65e9db4-c095-11e8-8b94-005056e1d034}
timeout                 30

Windows Boot Loader
-------------------
identifier              {d65e9db4-c095-11e8-8b94-005056e1d034}
device                  ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
path                    \windows\system32\winload.exe
description             winpe boot image
osdevice                ramdisk=[boot]\boot\boot.wim,{ramdiskoptions}
systemroot              \windows
detecthal               Yes
winpe                   Yes

Setup Ramdisk Options
---------------------
identifier              {ramdiskoptions}
description             Ramdisk options
ramdisksdidevice        boot
ramdisksdipath          \boot\boot.sdi

如果還是覺得不習慣文字介面,可以去下載 BCD 圖形介面的編輯器如 Visual BCD Editor .

常見問題:

沒有使用 administrator 權限來執行 BCDEdit .

C:\Users\Ben>bcdedit
The boot configuration data store could not be opened.
Access is denied.
沒有解決問題,試試搜尋本站其他內容

One thought on “Windows command – BCDEdit

  1. 请教一下同胞,能否给其中一项启动菜单设置密码,也就是说只有敲入密码的管理员才能启动某一项菜单,如果有时间,能否抽空回复一下,多谢,邮箱地址:664239199@qq.com

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料