Skip to content

Instantly share code, notes, and snippets.

@csullivan
Last active October 30, 2021 23:41
Show Gist options
  • Save csullivan/9b0ed1c040771c002fc365f22e6f2dd9 to your computer and use it in GitHub Desktop.
Save csullivan/9b0ed1c040771c002fc365f22e6f2dd9 to your computer and use it in GitHub Desktop.
Repairing EFI/GPT Bootloader using the DISKPART and BCDEdit command
Source: https://www.retrospect.com/au/support/kb/repair_efi_bootloader
This guide details how to rebuild the BCD boot store for windows.
Use diskpart to make System partition available.
(This will allow us to use bcdedit later in this guide to repair the bootloader.)
Boot from the Windows installation media
When at the Install Windows screen hit Shift+F10 to bring up a command prompt.
Type diskpart, then type list disk:
DISKPART> list disk
Disk #### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 465 GB 1024 KB *
Disk 1 Online 14 GB 0 B
Disk 2 Online 7695 MB 0 B
.
Select boot disk
You need to "Select" a disk before continuing. If only one disk shows, type, select disk 0. If there is more than one disk, they will need to verify based on disk size. If it is not disk 0 they would replace 0 with the number of the drive. (In my sample above, it is hopefully clear that '0' is the boot drive and the other two are not.)
DISKPART> select disk 0
Disk 0 is now the selected disk.
Verify Partitions
Type, list par, to verify that there are 4 partitions, Recovery, System, Reserved, Primary.
DISKPART> list par
Partition #### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Recovery 450 MB 1024 KB
Partition 2 System 99 MB 451 MB
Partition 3 Reserved 16 MB 550 MB
Partition 4 Primary 464 GB 566 MB
Partition 5 Recovery 847 MB 464 GB
.
Select volume to use
Type, list vol, the volume number they want to use in the next step will have a FAT32 file system and should be 99MB with System under info.
DISKPART> list vol
Volume #### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 C NTFS Partition 464 GB Healthy Boot
Volume 1 Recovery NTFS Partition 450 MB Healthy Hidden
Volume 2 FAT32 Partition 99 MB Healthy System
Volume 3 NTFS Partition 847 MB Healthy Hidden
Volume 4 F FAT32 Removable 14 GB Healthy
Volume 5 E IRON MAN FAT32 Removable 7695 MB Healthy
In this example, this is Volume 2.
Type, select vol 2, (number identified from previous step), i.e. select vol 2
DISKPART> select vol 2
Volume 2 is the selected volume.
Type, assign letter=z and should see "Diskpart successfully assigned the drive letter".
DISKPART> assign letter=z
DiskPart successfully assigned the drive letter or mount point.
Type exit (Z: drive is now the System partition)
Set up EFI boot partition using bcdedit (Boot Configuration Data editor)
(c.f. https://neosmart.net/wiki/bcdedit/#Commands_and_parameters for more info on bcdedit)
Type mkdir Z:\EFI\Microsoft\Boot
Type xcopy /s C:\Windows\Boot\EFI*.* Z:\EFI\Microsoft\Boot
Type z:
Type cd EFI\Microsoft\Boot
Type the following commands
bcdedit /createstore BCD
bcdedit /store BCD /create {bootmgr} /d "Windows Boot Manager"
bcdedit /store BCD /create /d "My Windows 10" /application osloader (they can change My Windows 10 to anything they want)
The last command will return a GUID, for example, {D91FE7C2-605F-4A2B-B035-80A7C30979BF}, they will need to use this guid in the next step
Type the following commands
bcdedit /store BCD /set {bootmgr} default {your_guid} (your_guid will be the guid mentioned in step 9)
bcdedit /store BCD /set {bootmgr} path \EFI\Microsoft\Boot\bootmgfw.efi
bcdedit /store BCD /set {bootmgr} displayorder {default}
bcdedit /store BCD /set {default} device partition=c:
bcdedit /store BCD /set {default} osdevice partition=c:
bcdedit /store BCD /set {default} path \Windows\System32\winload.efi
bcdedit /store BCD /set {default} systemroot \Windows
exit
Reboot the machine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment