Skip to main content

How to Convert a Disk from MBR to GPT in Batch Script

The MBR (Master Boot Record) partition style is a legacy format from the 1980s that limits drives to 2 TB and only 4 primary partitions. Modern systems running UEFI firmware require GPT (GUID Partition Table), which supports drives up to 18 exabytes and 128 partitions. If you are migrating an older machine to Windows 11 (which requires UEFI/GPT), upgrading a server to use a disk larger than 2 TB, or preparing hardware for Secure Boot, you need to convert the partition style. The approach depends on whether the disk is the OS drive (non-destructive conversion with mbr2gpt.exe) or a data drive (destructive conversion with DiskPart after backup).

This guide will explain both conversion approaches with proper safety checks.

Critical Warning

Disk partition conversion is a high-risk operation. Before proceeding:

  1. Create a full backup of the disk. Even the "non-destructive" mbr2gpt tool modifies the partition table at a low level, so a power failure mid-conversion can leave the disk unbootable.
  2. Know your firmware type. After converting the OS disk to GPT, you MUST switch the BIOS from Legacy/CSM mode to UEFI mode. If you forget this step, the computer will not boot.
  3. Verify the current partition style first. There is no point converting a disk that is already GPT. Use powershell -Command "(Get-Disk -Number 0).PartitionStyle" to check.
  4. Test on a non-production machine first before converting production systems.

Method 1: Non-Destructive OS Disk Conversion (mbr2gpt)

Windows 10 version 1703 and later includes mbr2gpt.exe, which converts the system disk from MBR to GPT without losing data, applications, or the Windows installation. This is the correct tool for the OS disk.

Step 1: Validate Before Converting

Always validate first. This checks whether the disk layout is compatible with conversion without making any changes.

@echo off
setlocal

:: Verify admin privileges
net session >nul 2>&1
if errorlevel 1 (
echo [ERROR] This operation requires administrator privileges. >&2
endlocal
exit /b 1
)

:: Verify mbr2gpt is available
where mbr2gpt >nul 2>&1
if errorlevel 1 (
echo [ERROR] mbr2gpt.exe not found. Requires Windows 10 version 1703 or later. >&2
endlocal
exit /b 1
)

:: Check current partition style
for /f "delims=" %%s in (
'powershell -NoProfile -Command "(Get-Disk -Number 0).PartitionStyle"'
) do set "CurrentStyle=%%s"

if /i "%CurrentStyle%"=="GPT" (
echo [INFO] Disk 0 is already GPT. No conversion needed.
endlocal
exit /b 0
)

if /i "%CurrentStyle%"=="RAW" (
echo [ERROR] Disk 0 is RAW (uninitialized^). Cannot convert. >&2
endlocal
exit /b 1
)

echo [INFO] Current partition style: %CurrentStyle%
echo [INFO] Running validation check...
echo.

mbr2gpt /validate /disk:0 /allowFullOS

if errorlevel 1 (
echo.
echo [FAIL] Validation failed. The disk cannot be converted. >&2
echo.
echo Common reasons for validation failure: >&2
echo - More than 3 primary partitions (GPT conversion needs space for EFI partition^) >&2
echo - Unsupported partition layout >&2
echo - Disk is not the system disk >&2
echo - BitLocker encryption is active (suspend first^) >&2
echo.
echo Run "mbr2gpt /validate /disk:0 /allowFullOS" for detailed output. >&2
endlocal
exit /b 1
)

echo.
echo [PASS] Validation successful. Disk 0 can be safely converted to GPT.
echo.
echo Next steps:
echo 1. Create a full backup of the disk
echo 2. Run the conversion script (Step 2^)
echo 3. After conversion, change BIOS from Legacy/CSM to UEFI mode
echo 4. Reboot and verify

endlocal
exit /b 0

Step 2: Perform the Conversion

Run this only after validation passes and you have a backup.

@echo off
setlocal

net session >nul 2>&1
if errorlevel 1 (
echo [ERROR] Administrator privileges required. >&2
endlocal
exit /b 1
)

:: Re-validate before converting
mbr2gpt /validate /disk:0 /allowFullOS >nul 2>&1
if errorlevel 1 (
echo [ERROR] Validation failed. Run the validation script first. >&2
endlocal
exit /b 1
)

:: Check current style one more time
for /f "delims=" %%s in (
'powershell -NoProfile -Command "(Get-Disk -Number 0).PartitionStyle"'
) do set "Style=%%s"

if /i "%Style%"=="GPT" (
echo [INFO] Disk 0 is already GPT.
endlocal
exit /b 0
)

echo ============================================================
echo MBR TO GPT CONVERSION - DISK 0 (OS DRIVE^)
echo ============================================================
echo.
echo This will convert the OS disk from MBR to GPT.
echo Data and applications will be PRESERVED.
echo.
echo AFTER conversion, you MUST:
echo 1. Enter BIOS/UEFI settings
echo 2. Disable Legacy Boot / CSM
echo 3. Enable UEFI-only boot mode
echo 4. Save and reboot
echo.
echo If you skip the BIOS change, the computer WILL NOT BOOT.
echo.
echo ============================================================

set /p "Confirm=Type CONVERT to proceed: "
if /i not "%Confirm%"=="CONVERT" (
echo [INFO] Operation cancelled. No changes were made.
endlocal
exit /b 0
)

echo.
echo [ACTION] Converting Disk 0 from MBR to GPT...
echo [WARNING] Do not interrupt this process or shut down the computer.
echo.

mbr2gpt /convert /disk:0 /allowFullOS

if errorlevel 1 (
echo.
echo [ERROR] Conversion failed. >&2
echo The disk may be in an inconsistent state. >&2
echo Do NOT reboot until the issue is resolved. >&2
echo Consider restoring from backup. >&2
endlocal
exit /b 1
)

echo.
echo [OK] Conversion completed successfully.
echo.
echo ============================================================
echo REQUIRED: Change BIOS settings before rebooting
echo ============================================================
echo.
echo 1. Reboot and enter BIOS/UEFI setup (usually F2, F10, or Del^)
echo 2. Find Boot Mode or CSM settings
echo 3. Change from "Legacy" or "CSM" to "UEFI Only"
echo 4. Save and exit
echo.
echo If you do not make this change, Windows will not boot.
echo ============================================================

:: Verify the conversion
echo.
echo [INFO] Verification:
powershell -NoProfile -Command ^
"$disk = Get-Disk -Number 0;" ^
"Write-Host \" Partition Style: $($disk.PartitionStyle)\";" ^
"Write-Host \" Size: $([math]::Round($disk.Size / 1GB, 1)) GB\""

endlocal
exit /b 0

What mbr2gpt does internally:

  1. Validates the disk layout and partition count.
  2. Shrinks the last partition slightly to create space for the EFI System Partition (ESP).
  3. Creates the ESP and populates it with UEFI boot files.
  4. Converts the MBR partition table to GPT format.
  5. Updates the Boot Configuration Data (BCD) to use UEFI boot entries.

The entire process takes 1–5 minutes and does not touch user data or applications.

mbr2gpt requirements:

RequirementDetails
Windows versionWindows 10 version 1703 (Creators Update) or later
Partition countMaximum 3 primary partitions (the 4th slot is needed for the EFI partition)
DiskMust be the system/boot disk (Disk 0 in most cases)
BitLockerMust be suspended before conversion (manage-bde -protectors -disable C:)
Disk typeBasic disk (not dynamic)

/allowFullOS flag:

By default, mbr2gpt is designed to run from the Windows Preinstallation Environment (WinPE). The /allowFullOS flag allows it to run from within the running Windows installation. This is convenient but slightly riskier, as if the system crashes during conversion, recovery is more difficult than from WinPE.

Method 2: Destructive Conversion for Data Disks (DiskPart)

For non-OS data disks where the content has been backed up, DiskPart provides a straightforward conversion. This method erases all data on the disk.

@echo off
setlocal

set "DiskNum=%~1"

if "%DiskNum%"=="" (
echo Usage: %~nx0 ^<disk_number^>
echo.
echo Converts a data disk from MBR to GPT.
echo WARNING: ALL DATA ON THE DISK WILL BE ERASED.
echo.
echo Example: %~nx0 2
endlocal
exit /b 1
)

net session >nul 2>&1
if errorlevel 1 (
echo [ERROR] Administrator privileges required. >&2
endlocal
exit /b 1
)

:: Safety: refuse disk 0
if "%DiskNum%"=="0" (
echo [ERROR] Refusing to destructively convert Disk 0 (OS drive^). >&2
echo Use Method 1 (mbr2gpt^) for the OS disk to preserve data. >&2
endlocal
exit /b 1
)

:: Verify the disk exists and check current style
for /f "tokens=1-2 delims=|" %%a in (
'powershell -NoProfile -Command ^
"$disk = Get-Disk -Number %DiskNum% -ErrorAction SilentlyContinue;" ^
"if (-not $disk) { Write-Output ''NOT_FOUND|''; exit 1 };" ^
"$sizeGB = [math]::Round($disk.Size / 1GB, 1);" ^
"Write-Output \"$($disk.PartitionStyle)|$sizeGB\""'
) do (
set "CurrentStyle=%%a"
set "DiskSizeGB=%%b"
)

if "%CurrentStyle%"=="NOT_FOUND" (
echo [ERROR] Disk %DiskNum% does not exist. >&2
endlocal
exit /b 1
)

if /i "%CurrentStyle%"=="GPT" (
echo [INFO] Disk %DiskNum% is already GPT (%DiskSizeGB% GB^). No conversion needed.
endlocal
exit /b 0
)

:: Show disk list for verification
echo [INFO] Current disk configuration:
echo.
set "DPList=%TEMP%\dp_list_%RANDOM%.txt"
(echo list disk) > "%DPList%"
diskpart /s "%DPList%" 2>nul
del "%DPList%" 2>nul

echo.
echo [WARNING] Disk %DiskNum% (%DiskSizeGB% GB, currently %CurrentStyle%^) will be ERASED and converted to GPT.
echo [WARNING] ALL DATA on this disk will be permanently destroyed.
echo.

set /p "Confirm=Type ERASE to proceed: "
if /i not "%Confirm%"=="ERASE" (
echo [INFO] Operation cancelled. No changes were made.
endlocal
exit /b 0
)

echo.
echo [ACTION] Converting Disk %DiskNum% to GPT...

set "DPScript=%TEMP%\dp_convert_%RANDOM%.txt"
(
echo select disk %DiskNum%
echo clean
echo convert gpt
) > "%DPScript%"

diskpart /s "%DPScript%" >nul 2>&1
set "DPResult=%errorlevel%"

del "%DPScript%" 2>nul

if %DPResult% neq 0 (
echo [ERROR] Conversion failed. >&2
echo The disk may be in use or write-protected. >&2
endlocal
exit /b 1
)

:: Verify
for /f "delims=" %%s in (
'powershell -NoProfile -Command "(Get-Disk -Number %DiskNum%).PartitionStyle"'
) do set "NewStyle=%%s"

if /i "%NewStyle%"=="GPT" (
echo [OK] Disk %DiskNum% successfully converted to GPT.
echo [INFO] The disk is now empty. Create partitions with DiskPart or Disk Management.
) else (
echo [WARNING] Conversion may have failed. Current style: %NewStyle% >&2
)

endlocal
exit /b 0

When to use DiskPart vs. mbr2gpt:

ScenarioToolData Preserved?
OS disk (C:) - keep Windows installationmbr2gptYes
Data disk - content already backed upDiskPart clean + convert gptNo - all data erased
Data disk - content must be preservedBack up → DiskPart → RestoreData restored from backup
New/empty diskDiskPart convert gpt (no clean needed)N/A - no data exists

Method 3: Post-Conversion Verification and BIOS Guidance

After converting the OS disk, this script verifies the new partition style and checks whether the BIOS settings are correctly configured for UEFI boot.

@echo off
setlocal

echo [INFO] Post-conversion verification:
echo --------------------------------------------------

:: Check partition style
for /f "delims=" %%s in (
'powershell -NoProfile -Command "(Get-Disk -Number 0).PartitionStyle"'
) do set "Style=%%s"

echo Partition Style: %Style%

if /i not "%Style%"=="GPT" (
echo.
echo [WARNING] Disk 0 is still %Style%. Conversion may not have completed. >&2
endlocal
exit /b 1
)

:: Check for EFI System Partition
powershell -NoProfile -Command ^
"$efi = Get-Partition -DiskNumber 0 -ErrorAction SilentlyContinue |" ^
" Where-Object { $_.GptType -eq '{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}' };" ^
"if ($efi) {" ^
" Write-Host \" EFI Partition: Present ($([math]::Round($efi.Size / 1MB)) MB)\"" ^
"} else {" ^
" Write-Host ' EFI Partition: NOT FOUND - boot may fail' -ForegroundColor Red" ^
"}"

:: Check boot mode
powershell -NoProfile -Command ^
"if (Test-Path 'HKLM:\System\CurrentControlSet\Control\SecureBoot\State') {" ^
" Write-Host ' Boot Mode: UEFI (Secure Boot capable)'" ^
"} else {" ^
" $env = [System.Environment]::GetFolderPath('System');" ^
" if (Test-Path \"$env\..\..\EFI\Microsoft\Boot\bootmgfw.efi\") {" ^
" Write-Host ' Boot Mode: UEFI (Secure Boot not enabled)'" ^
" } else {" ^
" Write-Host ' Boot Mode: Legacy BIOS' -ForegroundColor Yellow;" ^
" Write-Host '';" ^
" Write-Host ' [ACTION REQUIRED] Switch BIOS from Legacy/CSM to UEFI mode.' -ForegroundColor Yellow;" ^
" Write-Host ' The system is booting in Legacy mode from a GPT disk,' -ForegroundColor Yellow;" ^
" Write-Host ' which may cause boot failure on the next reboot.' -ForegroundColor Yellow" ^
" }" ^
"}"

echo.
echo --------------------------------------------------

endlocal
exit /b 0

Why BIOS verification matters:

After mbr2gpt converts the disk to GPT, the computer may still boot in Legacy/CSM mode (using a compatibility shim). This works temporarily but is not the intended configuration. If the BIOS is not switched to UEFI-only mode:

  • Secure Boot cannot be enabled.
  • Some Windows 11 features may not work.
  • A future BIOS update may remove CSM support, leaving the system unbootable.

The verification script detects this situation and warns the administrator to complete the BIOS configuration change.

How to Avoid Common Errors

Wrong Way: Using DiskPart clean on the OS Disk

:: CATASTROPHIC: destroys Windows, all applications, and all data
select disk 0
clean
convert gpt
note

clean erases the partition table, destroying the entire Windows installation. Use mbr2gpt for the OS disk, as it preserves everything.

Correct Way: mbr2gpt /convert /disk:0 /allowFullOS for the OS disk. DiskPart clean + convert gpt only for data disks that have been backed up.

Problem: More Than 3 Primary Partitions

mbr2gpt needs to create an EFI System Partition, which requires a free partition slot. MBR allows a maximum of 4 primary partitions, so only 3 can exist before conversion.

Solution: List partitions with diskpart > list partition and identify unnecessary ones (often old recovery partitions). Delete one to make room. Alternatively, merge two partitions before conversion.

Problem: BitLocker Must Be Suspended

mbr2gpt cannot modify a disk that is actively protected by BitLocker.

Solution: Suspend BitLocker before conversion, then resume after:

:: Before conversion
manage-bde -protectors -disable C:

:: After conversion and BIOS change
manage-bde -protectors -enable C:

Problem: Forgetting to Change BIOS Settings

After conversion, the disk is GPT but the BIOS may still be set to Legacy boot mode. The system may boot successfully one more time (via CSM compatibility) but fail after the next BIOS update or settings change.

Solution: Method 3's verification script detects Legacy boot mode on a GPT disk and warns the administrator. Always change the BIOS to UEFI-only mode immediately after conversion.

Problem: Conversion Failure Mid-Process

If a power failure or crash occurs during mbr2gpt conversion, the partition table may be left in an inconsistent state.

Solution: For maximum safety, run mbr2gpt from WinPE (without /allowFullOS) rather than from the running Windows. If conversion fails within Windows, boot from a Windows installation USB and attempt recovery or restore from backup.

Best Practices and Rules

1. Always Validate Before Converting

Run mbr2gpt /validate (Method 1, Step 1) before attempting conversion. This checks partition count, layout compatibility, and disk eligibility without making any changes.

2. Create a Full Backup Before Any Conversion

Even mbr2gpt (which preserves data) modifies the disk at a low level. A power failure during conversion can corrupt the partition table. Have a complete disk image backup before proceeding.

3. Update BIOS Immediately After Conversion

After converting the OS disk to GPT, change the BIOS from Legacy/CSM to UEFI-only mode before doing anything else. Run Method 3's verification to confirm.

4. Suspend BitLocker During Conversion

If the OS drive is encrypted, suspend BitLocker protection before conversion and resume it after the BIOS change.

5. Use mbr2gpt for the OS Disk, DiskPart for Data Disks

Never use DiskPart clean on the OS disk for conversion, as it destroys everything. mbr2gpt is specifically designed to preserve the OS, applications, and data during conversion.

6. Verify the Result

After conversion and BIOS change, verify:

  • Partition style is GPT: powershell -Command "(Get-Disk -Number 0).PartitionStyle"
  • EFI System Partition exists (Method 3)
  • System is booting in UEFI mode (Method 3)

Conclusions

Converting a disk from MBR to GPT is a gateway to modern computing capabilities, such as larger drives, more partitions, UEFI Secure Boot, and Windows 11 compatibility. By using mbr2gpt for non-destructive OS disk conversion and DiskPart for backed-up data disks, with proper validation, backup, BIOS configuration, and post-conversion verification, you ensure a safe and successful transition from legacy to modern storage. This capability is essential for anyone preparing hardware for current and future Windows requirements.