Converting MBR to GPT without deleting your partitions

Today I tired to convert my Windows 2TB RAID disk from a master boot record (MBR) layout to a GUID partition table (GPT) one. The reason I wanted to swap is that GPT supports partitions larger than 2TB. Normally it is easy to convert a MBR disk to a GPT one by using the Disk Management GUI. However, Microsoft do not allow you to convert you disk if you have any partitions on the disk.

After some searching I found that you could convert the disk non-destructively on Linux, but due to various reasons, my RAID does not work inside my Debian Linux :( I had also read a document outlining how to the conversion works, and it seems such a simple process I was surprised that Microsoft didn’t support it.

Some more searching and I found a Linux/Windows tool that will convert MBR to GPT quite easily. Gptgen is a simple command line tool that seemed to work like a charm. I will quickly outline the steps I took to use it “safely”.

Firstly I identified with disk I wanted to alter. This is done by looking at which number the disk is in Disk Management. I then quickly tested the tool without writing the changes

gptgen.exe \\.\\physicaldrive1

This outputted quite a few lines, including the following:

Write primary.img to LBA address 0.
Write secondary.img to LBA address 4395431903.

When you don’t write the changes to disk, gptgen creates two binary files “primary.img”, and “secondary.img”, which contain what it would have written to disk. The console output from gptgen tells me it would have written primary to LBA address 0, and secondary.img to LBA address 4395431903. So I figured it was a good idea to make a backup of those sections first. To do this I use the Windows version of the classic tool dd

dd if=\\.\\physicaldrive1 of=primary-backup.img bs=512 count=34
dd if=\\.\\physicaldrive1 of=secondary-backup.img bs=512 count=33 skip=4395431903

The numbers I’ve highlighted in bold are ones you might have to change. The first and second relate to the file sizes of primary.img and secondary.img. Find their file sizes and divide them by 512. In my case, primary.img was exactly 17,408 bytes, so 17408 / 512 = 34. Do the same for secondary.img. The final highlighted number is the LBA address shown by gptgen just a minute ago.

Ok, if you have run dd ok, you should have backups of the two sections it is going to overwrite. Now you can tell gptgen to actually make the changes:

gptgen.exe -w \\.\\physicaldrive1

That should be it, BUT if you need to (for whatever reason) restore the backups issue these commands:

dd if=primary-backup.img   of=\\.\\physicaldrive1 bs=512 count=34
dd if=secondary-backup.img of=\\.\\physicaldrive1 bs=512 count=33 seek=4395431903

(notice how the “if” and “of” arguments have swapped, and the word “skip” has changed to “seek”.)

Be Sociable, Share!

16 Comments

  1. Jeremy Blair

    Just wanted to drop a thank You. Used your method several times over the years. Works perfect everytime!

  2. Jon Nicholas

    Hi,

    I need to carry out this procedure on a windows clustered volume, do you know if it will still work?

    Regards
    jon

    • bramp

      Sorry I do not know. Backup and try?

    • Kenneth Nielsen

      Yea it will work, but you have to update the properties for the resource afterwards (or delete the resource and recreate it)

      More specifically you’d need to update the signature for the disk – you can only do this from the command line using powershell or cluster.exe or of course by editing the cluster hive in the registry.

      If none of these methods are something you’re famiiliar with – recreate the resource, just remember to screenshot dependencies as you’ll have to recreate those as well.

      Good luck

  3. Jay Honado

    I need to convert my external drive into a GPT, but I already have nearly 1 TB of data inside and no where to put it. How do you determine which disk you’re working on, and is the physicaldrive1 the mounted disk of the system or something else entirely?

    • Get DD for Windows here:
      http://www.chrysocome.net/dd

      Then use this command:
      dd.exe –list

      I get this output:

      ——–
      \\.\Volume{0ff1608e-b7a3-11e0-8954-806e6f6e6963}\
      link to \\?\Device\HarddiskVolume2
      fixed media
      Mounted on \\.\c:

      \\.\Volume{0ff1609d-b7a3-11e0-8954-806e6f6e6963}\
      link to \\?\Device\HarddiskVolume3
      removeable media
      Mounted on \\.\f:

      \\.\Volume{0ff1609e-b7a3-11e0-8954-806e6f6e6963}\
      link to \\?\Device\HarddiskVolume4
      removeable media
      Mounted on \\.\g:

      \\.\Volume{b7fd1c0b-7a9a-11e1-86b1-806e6f6e6963}\
      link to \\?\Device\CdRom0
      CD-ROM
      Mounted on \\.\d:
      ——–

      This will show you the physical device ID (and number) for each drive letter assigned, and whether it is fixed, removable, or an optical volume.

  4. ade

    Will this work if your boot partition is on the MBR that you convert to GPT. I’m worried Windows wouldn’t boot after the conversion?

  5. James

    AWESOME, Really this was great and it worked perfectly for me.

  6. Mattheus Veloso

    So, It’s not going to delete my partitions but is it going to delete my data?

    • bramp

      If done correctly it will not delete your data. But as always you should backup your data.

      • Mattheus Veloso

        Thank you!

  7. furtivefox

    This is a great tutorial. I’m glad you explained how to back-up the sections of the hard-drive that gptgen edits. I had to use dd in ubuntu to get my drive working again. I searched to see what I did wrong, and it appears as though I need a boot partition for Windows 7. When I installed Windows 7, I made it so it didn’t need that system partition and all I have is my Windows partition and other partitions I’ve made, including Linux. Do you have any suggestions? Should I try shrinking my Windows Partition and creating an EFI boot partition? How large does the EFI boot partition need to be? Thanks for the tutorial. I’d greatly appreciate any help.

  8. Mark Seymour

    I would be looking at converting a SAN Volume for an SQL database Cluster. The drive requiring converting is 2TB LUN.

    First question is how long does the process take?

    We would also need to look at changing the LUN type on the NetApp SAN. Any experiences with this type of conversion?

    • bramp

      The process takes seconds. It’s basically tweaking the header at the beginning of the disk.

      As for NetApp SANs, sorry I have no experience.

Trackbacks

  1. Back up Partition Table and MBR Manually
  2. Andreas' Blog » Blog Archive » ALIX 2D3 system board

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>