Changes between Version 3 and Version 4 of Correct BCD Boot Records


Ignore:
Timestamp:
01/05/24 01:34:28 (16 months ago)
Author:
Paul Kulda
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Correct BCD Boot Records

    v3 v4  
    11see attached PDF
     2
     3{{{
     4How to Repair EFI/GPT Bootloader on Windows 10 or 11
     5
     6In this article, we will learn how to repair the Windows bootloader on a modern computer that uses UEFI instead of a classic BIOS and GPT disk partition table (instead of MBR). The corruption of the Windows bootloader can occur after installing a second OS (in Dual Boot configurations), file system corruption, incorrect actions during Windows recovery, removal of some data on hidden partitions, malicious software (virus, ransomware, etc.), and for some other reasons.
     7
     8This article contains a step-by-step guide for repairing a damaged or deleted bootloader in Windows 11/10/8.1 and Windows Server 2022/2019/2016/2012R2 on computers running in native (non-compatible) UEFI mode. You can use this guile both to repair the binary files of the Windows bootloader, and the bootloader configuration \EFI\Microsoft\Boot\BCD file (in cases where Windows doesn’t boot due to the missing or corrupted BCD boot configuration file).
     9
     10Contents:
     11
     12    Windows Boot Error: Boot Configuration Data is Missing (EFI\Microsoft\Boot\BCD)
     13    Automatic Windows Bootloader Repair with WinRE
     14    Using BCDBoot to Manually Repair EFI Bootloader in Windows
     15
     16Windows Boot Error: Boot Configuration Data is Missing (EFI\Microsoft\Boot\BCD)
     17
     18A UEFI computer with Windows installed in native mode will not be able to boot if the Windows EFI bootloader is corrupted. When trying to boot from a disk with a damaged or missing EFI bootloader, the following BSOD (Blue Screen of Death) error appear:
     19
     20The boot configuration data for your PC is missing or contains errors.
     21File :\EFI\Microsoft\Boot\BCD
     22Error code: 0xc000000f
     23
     24or:
     25
     26Error code: 0xc000014c
     27
     28boot configuration errors 0xc000000f or missing file \EFI\Microsoft\Boot\BCD
     29
     30This error indicates that the Windows bootloader configuration (Boot Configuration Data, BCD) has been corrupted or even completely removed. If you try to repair the bootloader on a UEFI computer using bcdedit tool, you will receive an error:
     31
     32The boot configuration data store could not be found.
     33The requested system device cannot be found.
     34
     35If Windows 10/11 is installed in native UEFI mode on a GPT disk, then the Windows EFI bootloader (Windows Boot Manager) stores the boot manager and BCD configuration on a separate hidden EFI volume (100 MB in size with the FAT32 file system). The bcdedit tool doesn’t see this EFI partition, and cannot manage the bootloader configuration on it.
     36If you only see a black screen with the message “An operating system wasn’t found” when you boot your computer, it’s likely that the Windows bootloader has been completely removed. Follow the instructions on the link.
     37Automatic Windows Bootloader Repair with WinRE
     38
     39The procedure for the automatic repair of the EFI bootloader used in the Windows Recovery Environment (WinRE) is usually useless in such cases. But it’s still worth a try:
     40
     41    Boot your device from the recovery disc or Windows 10/11 installation media;
     42    Click the Restore System on the installation screen;
     43    Then select Troubleshoot -> Startup Repair and select the OS whose bootloader you want to try to repair;windows10 Startup Repair menu
     44    But most likely the result will be negative: Automatic Repair couldn’t repair your PC. Automatic Repair Couldn’t Repair Your PC
     45
     46Using BCDBoot to Manually Repair EFI Bootloader in Windows
     47
     48Let’s move on to the procedure for manually repairing the EFI Windows bootloader on a UEFI computer.
     49
     50To repair the bootloader configuration (BCD), you have to boot from the original Windows installation media (also, you can use a recovery disk or a special UEFI bootable USB flash drive). After booting into the recovery environment, you need to open a command-line console: select System Restore – > Troubleshoot-> Command Prompt).
     51You can run the Command Prompt even if you only have a Windows installation media at hand. To do this, it is enough to press the key combination Shift + F10 (or Shift + Fn + F10 on some laptop models) on the first Windows setup screen (when choosing a language and keyboard layout).
     52
     53system restore mode win 8
     54
     55In the command prompt that opens, run the disk management tool:
     56
     57diskpart
     58
     59Display the list of drives on the computer:
     60
     61list disk
     62At this stage, it is very important to determine the type of partition table on the disk on which your Windows is installed: MBR or GPT. The point is that the EFI bootloader is used only on disks with a GPT partition table.
     63
     64If the asterisk (*) is in the Gpt column, then the GPT partition table is used on disk. If not, the MBR is used.
     65
     66diskpart: GPT or MBR - checking disk partition table
     67
     68If your disk uses a GPT partition table, follow the steps below in the instructions to repair the Windows EFI bootloader.
     69
     70If you have an MBR partition table on your disk, this guide won’t work for your computer. Most likely you have a computer with BIOS or Legacy/Compatibility Support Mode (CSM) option enabled in the UEFI settings.
     71
     72On MBR disks, the Windows bootloader is stored on a separate System Reserved partition, and not on the EFI partition (in any case, don’t convert the MBR partition table to GPT until you fix the Windows bootloader !!). Use another guide to restore the BCD bootloader on a BIOS computer with MBR (Master Boot Record) disk.
     73
     74Select the drive where your Windows is installed (if there is only one hard drive in the system, its index should be 0):
     75
     76sel disk 0
     77
     78Display the list of partitions and volumes on this disk: list partition
     79list volume
     80
     81window efi partition table structure
     82
     83In this example, you can see that the EFI boot partition has the partition 2 index (aka Volume 5 with the Hidden label). The easiest way to identify an EFI partition is by the FAT32 file system and 100 MB in size (this is the standard minimum size of EFI partition for Windows computers; in rare cases, the partition size may differ). The most commonly used label for it is System EFI or ESP/EFI System Partition).
     84
     85In our example, the main partition on which Windows is installed has a volume 2 index, is formatted in the NTFS file system, and is assigned the drive letter C:.
     86
     87dir C:\
     88
     89Make sure that this drive contains the Windows, Program Files, Users, and other directories.
     90
     91identify windows system partition in winpe
     92
     93If these directories are missing, then your Windows drive has a different drive letter. Check the contents of drives with different drive letters assigned.
     94
     95Write down the drive letter assigned to the Windows partition. We will use it as one of the arguments of the bcdboot command a little later.
     96
     97The partition table must also contain an MSR (Microsoft System Reserved) partition of 16 MB in Windows 10/11 (or 128 MB in Windows 8.1).
     98If you don’t have a separate EFI or MSR partition, you can recreate them manually. Check the article Restoring deleted EFI and MSR system partitions.
     99
     100Assign the drive letter K: to the hidden EFI volume:
     101
     102select volume 5
     103assign letter K:
     104
     105A message that the drive letter has been successfully assigned  to the EFI partition should appear:
     106
     107DiskPart is successfully assigned the drive letter or mount point.
     108
     109Close the diskpart:
     110exit
     111Go to the bootloader directory on the hidden volume:
     112cd /d K:\efi\microsoft\boot\
     113
     114In this case, K: is the drive letter assigned to the EFI partition just above. If the \EFI\Microsoft\Boot\ directory is missing (error The system cannot find the path specified), try the following commands:
     115
     116cd /d K:\Boot\
     117or
     118cd /d K:\ESD\Windows\EFI\Microsoft\Boot\
     119At this point, many guides recommend running the following commands, which should overwrite the partition boot record, find the installed Windows, and add them to the BCD:
     120
     121bootrec /fixboot
     122bootrec /scanos
     123bootrec /rebuildbcd
     124or even:
     125bootrec /FixMbr (preparing MBR record for a GPT disk looks strang)
     126
     127You can use all these commands only for MBR-based disks. If your computer boots in UEFI mode, then it definitely uses the GPT partition table (as in our case). Therefore, when you run bootrec commands, you will see an error: access is denied
     128
     129You need to use the BCDBoot.exe tool to restore bootloader files and fix the boot records on the EFI partition by copying them from the system directory on the Windows partition. The BCD bootloader configuration is recreated using the %WINDIR%\System32\Config\BCD-Template file.
     130
     131Use the attrib command to remove the hidden, read-only, and system attributes from the BCD file:
     132
     133attrib BCD -s -h -r
     134
     135Delete the current BCD configuration file by renaming it (this will keep the old boot configuration as a backup): ren BCD BCD.bak
     136Using the bcdboot tool, you need to copy the critical files of the UEFI boot environment from the system directory to the EFI boot partition and recreate the BCD bootloader config file:
     137bcdboot C:\Windows /l en-us /s k: /f ALL
     138
     139    C:\Windows – the path to the root Windows system directory on the disk (this is your disk on which your Windows is installed, we determined it earlier using the diskpart command);
     140    f ALL –means that you need to copy the Windows Boot Environment files, including those for UEFI and BIOS computers (theoretically able to boot both on UEFI and BIOS computers). To copy only the EFI bootloader, use the /f UEFI command;
     141    /l en-us —specifies the system locale that is used when initializing the BCD store. By default, en-us – English (USA) is used;
     142    /s K: — copy the bootloader EFI files to the specified partition;
     143    /c – this is a new BCDBoot option in Windows 10 that allows you to overwrite existing boot records (including debugsettings). Use this option to ignore old boot settings and create a clean BCD configuration;
     144    /v – used to enable BCDBoot verbose output.
     145
     146Hint. If you use a localized version of Windows 10/11, the command will be different. For example, in the Windows version for the UK, use the following command:
     147bcdboot c:\Windows /l en-GB /s K: /f ALL
     148Windows 10 Dutch:
     149bcdboot c:\Windows /l nl-NL /s K: /f ALL
     150Windows 10 Deutch (German):
     151bcdboot c:\Windows /l de-DE /s K: /f ALL
     152
     153A complete list of language/region tags for Windows is available here:
     154
     155https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/available-language-packs-for-windows?view=windows-11
     156
     157Now, if you run the bcdedit command, you will see the following :
     158
     159An entry should appear in the Windows Boot Manager section containing the full path to the UEFI boot file (\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI).In this example, it is located on volume 5 (partition=\Device\HarddiskVolume5).
     160
     161bcdedit: windows boot manager bootmgfw.efi
     162
     163Windows Boot Manager
     164--------------------
     165identifier              {bootmgr}
     166device                  partition=\Device\HarddiskVolume5
     167path                    \EFI\Microsoft\Boot\bootmgfw.efi
     168description             Windows Boot Manager
     169locale                  en-US
     170inherit                 {globalsettings}
     171bootshutdowndisabled    Yes
     172default                 {CURRENT}
     173resumeobject            {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
     174displayorder            {default}
     175toolsdisplayorder       {memdiag}
     176timeout                 30
     177Windows Boot Loader
     178-------------------
     179identifier              {current}
     180device                  partition=C:
     181path                    \Windows\system32\winload.efi
     182description             Windows 10
     183locale                  en-US
     184inherit                 {bootloadersettings}
     185recoverysequence       {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
     186recoveryenabled         Yes
     187isolatedcontext         Yes
     188allowedinmemorysettings 0x15000075
     189osdevice                partition=C:
     190systemroot              \Windows
     191resumeobject            {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
     192
     193The Windows Boot Manager section must contain the path to the EFI partition (=\Device\HarddiskVolume5 ) and the path to the boot manager file (bootmgfw.efi). The Windows Boot Loader section contains the Windows partition info and the path to the Windows EFI bootloader ( \Windows\system32\winload.efi). When you turn it on, your computer will pass control to the EFI bootloader, which will start the Windows bootloader.
     194
     195Possible errors:
     196
     197    BFSVC Error: Could not open the BCD template store. status – [c000000f] – check if the entered command is correct and whether you have a localized Windows version installed. In this case, you need to specify the correct local language code. bcd template file in windowsThe bcdboot tool copies the BCD template files from the \Windows\System32\Config directory. If the BCD template files in this folder are damaged or deleted, try to check the integrity of the system files offline using the sfc.exe tool (you need a Windows installation disc as a source, drive D: in this case): sfc /scanow /OFFBOOTDIR=C:\ /OFFWINDIR=D:\WINDOWS
     198    BFSVC Error: Error copying boot files from Last Error = 0x570 – try to check drive using the command CHKDSK K: /F
     199    BFSVC Error: Failed to set element application device. Status = [c000000bb] – check the EFI and Windows 10 partitions using chkdsk.exe. Verify that the hidden and system attribute of the BCD file is cleared:
     200    attrib -s -h \EFI\Microsoft\Boot\BCD
     201    del \EFI\Microsoft\Boot\BCD
     202    bcdboot: bfsvc error
     203    Failure when initializing library system volume – make sure you are using the correct FAT32 partition with EFI (you may have several similar partitions);
     204    Failure when attempting to copy boot files – check the Windows drive letter in your bcdboot command. The screenshot below shows that the error appeared when trying to copy the boot files from the C: drive. In this case, most likely the Windows drive is assigned a different letter, such as D:. You can find the Windows drive and the assigned drive letter using the diskpart and dir commands (described above).bcdboot error • Failure when attempting to copy boot files
     205
     206Now you need to restart your computer and disconnect the bootable media. If you did everything correctly, the Windows Boot Manager should appear in the list of bootable devices, where you can choose a desired operating system to boot. Your EFI bootloader and BCD configuration have been restored successfully!
     207In some cases, after repairing the BCD bootloader, when Windows boots, a BAD SYSTEM CONFIG INFO error appears. To fix the error:
     208
     209Make sure you haven’t made any recent changes to UEFI settings. Undo all changes.
     210
     211Boot your computer from the installation/bootable flash drive and change the bootloader configuration with the commands:
     212
     213    bcdedit /deletevalue {default} numproc
     214    bcdedit /deletevalue {default} truncatememory
     215}}}