obive.net

Monday June 22 2020 @ 12:59 AM

I posted this article a while back on another blog. It has since been removed so I'm reproducing it here. Enjoy!

 

Introduction

There are few reasons to switch from MBR on BIOS to GPT on UEFI, but some like adventure. Current OS and motherboard support is quite inconsistent and not well documented. If you first installed on the former and want to switch to the latter without having to lose all your data or re-install Windows, then this is your guide.

The basic idea is to backup the current install to a disk image, erase the disk, then reload the backup. Windows ships with a disk imaging tool and an image restore tool. Unfortunately the restore tool (wbadmin) requires the target partition to be at least the same size as the original backup, so we have to use another method for restore.

WARNING: You may lose all the data on your disk during this process. Make sure to back up your data!

Prerequisites

  • A UEFI motherboard
  • A copy of Windows 7 64bit installed to a local disk partitioned using MBR
  • Windows install media (DVD, Hard disk, USB stick)
  • Backup destination with enough space to hold a copy of your existing Windows install
  • Sufficient free space on the Windows partition; the new partition will be about a gigabyte larger.

Process

  1. Backup your Windows installation and all other partitions on the physical disk to another physical disk. This backup can be done using the built-in image tool found within the control panel under “Backup and Restore” behind the “Create a system image” link. NOTE: The rest of this guide will assume just one partition to be restored.
  2. Reboot the computer to a Windows install disk.
  3. Open the command prompt
    1. press Shift + F10 at the “Install Windows” window.
  4. Repartition the disk
    1. diskpart
    2. list disk
    3. select disk x (where x is the number of the disk to convert)
    4. WARNING: This is your last chance to go back!
    5. clean
    6. convert gpt
    7. create partition ESP size=128
    8. format fs=fat32 quick
    9. assign letter=i or any other free drive letter
    10. create partition MSR size=128
    11. create partition primary
    12. format fs=ntfs label="Windows" quick
    13. active
    14. assign letter=y or any other free drive letter
    15. exit
  5. Mount the backup VHD
    1. diskpart
    2. select vdisk file=filename.vhd where filename.vhd is your disk backup
    3. attach vdisk
    4. assign letter=z or any other free drive letter for your new partition
    5. exit
  6. Restore the files from the image
    1. z: (where z is the letter of your VHD)
    2. xcopy * y:\ /e /c /h /k /o /b /q /y (where d is the letter of your new partition)
      1. e = copy all subdirectories even if they are empty
      2. c = ignore errors
      3. h = copy hidden and system files
      4. k = retain readonly flag
      5. o = copy file ownership
      6. b = copy links as links
      7. q = quiet mode (should speed things up)
      8. y = always respond with yes instead of prompting
    3. Wait for the copy to complete. Commenter Niko has an excellent point here: There may be permission errors which you can probably ignore. These are likely for special system folders like "System Volume Information". Turn off quiet mode to be sure or if the process doesn't work and you want to verify this isn't the cause.
  7. Copy EFI bootloader to ESP partition
    1. i: (where z is the letter of your ESP partition)
    2. mkdir EFI
    3. cd EFI
    4. mkdir Boot
    5. mkdir Microsoft
    6. cd Microsoft
    7. mkdir Boot
    8. copy x:\Windows\Boot\EFI\bootmgfw.efi i:\EFI\Microsoft\Boot
    9. copy x:\Windows\Boot\EFI\bootmgfw.efi i:\EFI\Boot\bootx64.efi
  8. Create BCD
    1. This step varies quite a bit, depending on your system’s hardware, existing NVRAM (non-volatile memory on your motherboard), and hidden BCD stores scattered around your system’s disks and partitions.
    2. Cross your fingers and hope that this step can be done automatically
      1. bootrec /RebuildBcd
    3. If things don’t work out, you will have to resort to using bcdedit. A few notes about BCD edit: it operates on the motherboard’s NVRAM unless you specify a file. As far as I can gather, the NVRAM store doesn’t matter as my PC basically ignores any setting within and boots just fine after I’ve erased it.
      1. i:
      2. cd EFI\Microsoft\Boot
      3. bcdedit /createstore BCD
      4. bcdedit /store BCD  /create /d "Windows Boot Manager" {bootmgr}
        1. Commenter Manuel says this should be bcdedit /store BCD /create {bootmgr} /d “Windows Boot Manager” but I haven't tested this. This may depend on the version of BCD edit you are using.
      5. bcdedit /store BCD /create /d “Windows 7” /application osloader
      6. The previous command will return a GUID, referred to later as <guid>
      7. bcdedit /store BCD /set {bootmgr} default <guid>
      8. bcdedit /store BCD /set {bootmgr} path \EFI\Microsoft\Boot\bootmgfw.efi 
      9. bcdedit /store BCD /set {bootmgr} locale en-us
      10. bcdedit /store BCD /set {bootmgr} displayorder {default}
      11. bcdedit /store BCD /set {bootmgr} timeout 10
      12. bcdedit /store BCD /set {default} device partition=c:
      13. bcdedit /store BCD /set {default} osdevice partition=c:
      14. bcdedit /store BCD /set {default} path \windows\system32\winload.efi
      15. bcdedit /store BCD /set {default} systemroot \windows
  9. Change your motherboard firmware to run in UEFI mode
  10. You should now be able to select your Windows disk as your startup disk.

Good luck!

More Reading

  • https://neosmart.net/wiki/recovering-windows-bootloader/
  • http://technet.microsoft.com/en-us/library/cc709667(v=ws.10).aspx