Computer Stuff
scythe944  

Converting MBR to GPT partitions in Windows Server for free

For whatever reason, Microsoft makes it difficult / impossible to convert old disks (even in virtualized systems) from MBR to GPT. This is very important for administrators that need to have drives / shares that are larger than the physical 2TB limit on an MBR partitioned disk. One of the ways to mitigate this problem is to create a new drive with GPT partition(s) and migrate the files from the old drive, but this can be tedious if you have a drive or share with millions of files. Shares need to be set back up, permissions recreated, etc. Robocopy can adequately deal with permissions pretty well in this scenario, but the time that it takes, the additional resources and the recreation of shares can be a bit of a time waste. If you want to be lazy, the easiest way is to purchase software from Easeus / Aomei / Parted Magic to do it for you, but those are not (or no longer) free, especially for Server Operating Systems. They used to be, because I’ve personally used them in the past, but now I’m running into issues finding them again.

Anyway, to work around this and to convert a data drive other than a system drive which is what drove me to do the research and create this post, I found this useful Reddit Post (https://www.reddit.com/r/sysadmin/comments/374cyq/mbr_gpt/) that helped me get started.

Please note that I’ve only completed this procedure on a test VM in my homelab so far and have not tried in a production environment yet (see update at the bottom of this page), although I plan to. PLEASE back up the system and or snapshot it before carrying out these commands in case something goes wrong. Also note that my drive lost its drive letter assignment after running. It was an easy fix to add a drive letter, but I’m unsure if shares will automatically get created and likely, they will not. If you have some sort of backup software that was configured to backup the drive by drive letter, you’ll likely need to re-create that as well, depending on the backup software that you use.

Anyway, here are the instructions and commands to get this done fairly quickly:

Download from SourceForge (https://sourceforge.net/projects/gptfdisk/)

Find physical disk number from Disk management
***Side notes from Reddit***
• Run the tool
• gdisk 1: -l (Lists partition for Physical Disk 1, verify I got the right drive)
• gdisk 1: (Launched Gdisk on Physical Disk 1)
• p (print partition info, 100% make sure I have the right drive)
• R (Recovery and transform Menu)
• f (Create GPT from MBR data)
• Cross your fingers.
• W (Write changes to disk).
• Reboot, fix and change drive mapping if it got changed. (Mine did).

From <https://www.reddit.com/r/sysadmin/comments/374cyq/mbr_gpt/> 



Once downloaded and extracted, open a command prompt with Administrative rights, browse to the extracted files and launch gdisk64.exe and follow the commands as shown below

In my example here, I wanted to convert Disk 2 as shown in the image below:
screenshot of disk management on test server showing Disk 2 as the desired disk
This command will give you basic information about the physical disk:
C:\gdisk-windows-1.0.10>gdisk64.exe -l \\.\physicaldrive2
GPT fdisk (gdisk) version 1.0.10


Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************

Disk \\.\physicaldrive2: 83886080 sectors, 40.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 1A626D40-478C-486F-A7E3-048BF7199A16
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 6077 sectors (3.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        83881983   40.0 GiB    0700  Microsoft basic data

This command will enter the gdisk program with the specified physical disk:
C:\gdisk-windows-1.0.10>gdisk64.exe \\.\physicaldrive2
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************

************************************************************************
Most versions of Windows cannot boot from a GPT disk except on a UEFI-based
computer, and most varieties prior to Vista cannot read GPT disks. Therefore,
you should exit now unless you understand the implications of converting MBR
to GPT or creating a new GPT disk layout!
************************************************************************

Are you SURE you want to continue? (Y/N): y

Command (? for help): p
Disk \\.\physicaldrive2: 83886080 sectors, 40.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 4250D7BE-E6EA-43C2-B70A-994A803162BB
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 6077 sectors (3.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        83881983   40.0 GiB    0700  Microsoft basic data

Command (? for help): r

Recovery/transformation command (? for help): f
Warning! This will destroy the currently defined partitions! Proceed? (Y/N): y

Recovery/transformation command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to \\.\physicaldrive2.
Disk synchronization succeeded! The computer should now use the new
partition table.
The operation has completed successfully.


Reboot the server

Upon reboot, the drive had been converted to GPT successfully, however, there was no longer a drive letter attributed to it. Re-assigned a drive letter.

If there had been shares on this drive, I'm unsure if they would be retained due to the loss of the drive letter. Will probably need to document shares and permissions or back them up and restore them after the procedure.

If you want to try to backup your shares and try to restore them automatically, you can backup the registry and restore it after you get the drive converted and the drive letter assigned by using the following instructions. Hope this helps someone!

Backup Windows Shares

To backup shares on a drive in Windows, you can use the Registry Editor to save the share names and their permissions. Start Registry Editor and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares. Right-click on the Shares folder and select Export to save the current share names and permissions to a .reg file. This file can be used later to restore the shares and their permissions.

Alternatively, you can use the command prompt to export the shares to a .reg file. Open a new command prompt as Administrator and type the following command:

reg export HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares "%UserProfile%\Desktop\Network Shares.reg"

To restore the shares, use the following command:

reg import HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares "%UserProfile%\Desktop\Network Shares.reg"

After importing the .reg file, restart your computer to apply the changes.

***Update***

I was successfully able to use this on a production server that had a 2TB share and only 89GB space free remaining. The process was quick, and did not require me to set the drive letter or shares after a reboot. I did take backups of the registry for shares as well as screenshotted the shares and did an export of the shares to CSV just in case, but after the reboot, everything on the drive was recognized, all files and shares were still available. This was on a Windows Server 2019 server.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.