Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lewdlime/83ee6cd6124fb58c9fb4 to your computer and use it in GitHub Desktop.
Save lewdlime/83ee6cd6124fb58c9fb4 to your computer and use it in GitHub Desktop.

Convert a MBR disk to GPT without losing any operating system data (Windows 7)

By Greg5884

Introduction

For the past week, I've been determined to triple boot with my existing Windows 7 installation, Ubuntu, and Mac OS X (Hackintosh). In order to do so on my laptop, I would have to change the partition table from MBR (Master Boot Record) to GPT (Guided Partition Table).

However, I did not want to lose my existing Windows 7 installation since I had a lot of files/applications already installed. Moreover, I've had a woeful track record of having my data botched during Windows backups.

Many of the how-to's covering this conversion typically say that you have to wipe the entire hard drive and reinstall, but after following a few different guides and doing enough tinkering around in Windows PE, I managed to retain my same Windows partition without any loss.

1. Read this first!

  1. Even though these steps have worked for me, I make no guarantee that they will deliver the same results for you. I am not responsible for any damage you may levy to your software or hard drive. I have tried this process twice, both with successful results on a Lenovo y510p laptop and a Dell Optiplex 7010 tower—both running Windows 7 x64.
  2. Please, back up any data or files that you cannot bear to lose. In case I botched up my OS, I made sure to clone my entire HDD to an external drive with CloneZilla. http://clonezilla.org/
  3. This guide is assuming that you are using a computer with a motherboard that supports UEFI. If you are not sure, check the boot options in your BIOS/firmware or Google your own model number and make sure. If it doesn't, then you'll find yourself in a boot loop at the end of this tutorial.
  4. Many people on their guides use the words "firmware" and "BIOS" interchangeably. This is not technically correct, as UEFI firmware is the replacement for BIOS, but more of a colloquialism. Here, I'll just simply refer to it as "BIOS/firmware."

2. You will need:

  1. A Windows 7 UEFI bootable Install USB. If you have the disc or ISO file, you can use this tool to help make one. Make sure it's formatted to FAT32. http://rufus.akeo.ie/ (You can use a CD if you wish, but you will have to keep your BIOS/firmware in "Legacy Mode" for a longer duration of the process, and it may complicate things).
  2. The Windows GPT fdisk binaries. This is the tool we will use in the Windows PE console to help convert your existing 100 MB MBR partition to EFI. Place these files on your Windows Install USB or on a separate USB http://sourceforge.net/projects/gptfdisk/files/gptfdisk/

3. Edit Registry Keys for AHCI in the UEFI Firmware

Edit Registry Keys for AHCI in the UEFI Firmware

  1. In Windows (on the HDD you will be converting), pull up regedit and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\msahci and change the (Default Value) to 0.
  2. Do the same for the one below: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\pciide

4. Change your firmware to AHCI and UEFI

Change your firmware to AHCI and UEFI

  1. Insert your Windows USB. Reboot your computer and pull up the BIOS/firmware screen
  2. Change the SATA mode to AHCI from IDE (if it's not already).
  3. Change the Boot mode from Legacy to UEFI.
  4. If present, make sure that Secure Boot is OFF.
  5. Save and Exit.

5. Formatting and Modifying your System Parition

Formatting and Modifying your System Parition

  1. Boot into the USB installer you made earlier.

  2. At the first Window, press SHIFT+F10 to bring up the Command Prompt.

    Enter the following in the Command Prompt:

         diskpart
         // This will bring up the disk partitioning tool.
         list volume
         // Make note of the drive letters for your
         // Windows USB Boot Drive and your 100 MB
         // System Partition (We will give it one
         // later if it doesn't have one right now).
         list disk
         // See which # your System HDD is (usually 0).
         // Also, like the last step, make note of what
         // disk # your Windows Boot USB is. We're going to need it later.
         select disk 0
         // To select the System HDD (or replace 0 with whatever # it is).
         list partition
         // To see which partition # is the 100 MB System part. (Usually 1).
         select partition 1
         // To select the system partition.
         format fs=fat32 label="" quick
         // Tell it to format the partition, remove its label — quickly.
         // As I said above, if your 100 MB System volume didn't have
         // a drive letter, let's go ahead and assign one now (for
         // the guide's sake, we'll do "B").
         assign letter=B:
         // All done with diskpart.
         exit
    

6. Changing the System Partition Code to EFI

Changing the System Partition Code to EFI

  1. Navigate to the USB drive path where you stored the GDisk files (Still remember the drive letter it was assigned earlier?)

    Bear in mind, in the Windows PE CMD, cd and chdir does not work like they usually would. You can simply hop to the other drive letter by just entering the drive letter in followed by a colon (i.e. B:).

    NOTE:

    If you cannot access your USB or even see it, for whatever reason, type in
    set AllowRemovableMedia = TRUE and set AllowAllPaths = TRUE.

  2. Run gdisk64.exe (or gdisk32.exe if your running 32-bit).

    Enter the following:

     \\.\physicaldrive#
     // Where # is the Disk number of the HDD (usually 0).
     // It will present a message about an invalid GPT and
     // having an MBR only. Go ahead and enter "y" at the prompt.
     t
     // If any of you have ever used fdisk for any Linux distros,
     //you will quickly become familiar with the commands and menus.
     // "t" will bring up the Code change menu.
     1
     // # of your System partition, usually always 1
     EF00
     // This will it that we want to change the type code to EFI.
     w
     // This will write the changes to the table and exit. A message
     // will come up warning you once more about the permanent changes.
     // Enter "y" to proceed. GDisk will then exit after writing the changes.
    

7. Rebuilding the Boot Configuration Data (BCD).

Rebuilding the Boot Configuration Data (BCD).

  1. Change your directory so you're now on the letter of the newly converted 100 MB EFI partition (we labeled it B: a few steps ago).

     B:
     mkdir B:\EFI\Microsoft\Boot
     // to create a new folder for your EFI files.
     xcopy /s C:\Windows\Boot\EFI\*.* B:\EFI\Microsoft\Boot
     // Copy all of the EFI files from your Windows OS partition
     // We will then go into our newly created directory and create
     // a new BCD from the files we copied over. Enter the following:
     cd EFI\Microsoft\Boot
     bcdedit /createstore BCD
     bcdedit /store BCD /create {bootmgr} /d "Windows Boot Manager"
     bcdedit /store BCD /create /d "Windows 7" /application osloader
     // This will return a GUID.
     bcdedit /store BCD /set {bootmgr} default {guid-from-last-step-here}
     // Insert the GUID from the last line here.
     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
    

    Now reboot, and disable Legacy mode in the BIOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment