DiskPart.exe: Quick Guide to Windows Disk Management Tool

DiskPart.exe is a command-line utility built into Windows that lets you manage disks, partitions, and volumes directly through text commands. Unlike the graphical Disk Management tool, DiskPart gives you more control and works faster for complex disk operations like cleaning drives, converting partition styles, or fixing boot issues.

This guide shows you exactly how to use DiskPart safely and effectively.

What Is DiskPart.exe and Why You Need It

DiskPart is Microsoft’s built-in disk partitioning tool that runs in the Command Prompt or PowerShell. It’s been part of Windows since Windows XP and continues to work in Windows 11.

You’ll need DiskPart when:

  • The graphical Disk Management tool fails or freezes
  • You’re preparing USB drives or SD cards for clean installations
  • You need to remove all partitions from a drive quickly
  • You’re converting between MBR and GPT partition styles
  • You’re troubleshooting boot problems or corrupted partitions
  • You’re working remotely through command-line only access

The tool operates in an interactive mode. You type commands one at a time, and DiskPart executes them immediately. There’s no undo button, which makes it powerful but risky if you select the wrong disk.

DiskPart.exe

How to Open and Use DiskPart Safely

Opening DiskPart

Method 1: Through Command Prompt

  1. Press Windows + X
  2. Click “Terminal (Admin)” or “Command Prompt (Admin)”
  3. Type diskpart and press Enter
  4. Click Yes when User Account Control appears

Method 2: Through Run Dialog

  1. Press Windows + R
  2. Type diskpart
  3. Press Enter
  4. Click Yes for administrator permission

You’ll see a new prompt that says DISKPART>. This means DiskPart is running and waiting for commands.

Safety Rules Before You Start

Always list before you act. Use list disk to see all drives before selecting one. One wrong number can wipe your system drive.

Double-check disk numbers. Disk numbers can change when you plug in or remove drives. The disk you think is Disk 2 might actually be Disk 1 today.

External drives first. Practice on USB drives or external hard drives before touching internal system disks.

No undo exists. Commands like clean execute instantly and permanently erase partition tables.

Essential DiskPart Commands Explained

Viewing Information Commands

These commands show you what’s available without making changes.

list disk

Shows all physical disks connected to your computer with their size and status.

list volume

Displays all volumes (drive letters like C: or D:) and their file systems.

list partition

Shows partitions on the currently selected disk.

detail disk

Provides detailed information about the selected disk including manufacturer and health status.

See also  Top 15 Data Removal Services to Protect Your Privacy in 2026

Selection Commands

You must select an object before you can modify it.

select disk 1

Selects disk number 1 for operations. Replace 1 with the correct disk number from list disk.

select volume 4

Selects a specific volume by number.

select partition 2

Selects a partition on the current disk.

Modification Commands

These commands change your disk configuration permanently.

clean

Removes all partition and volume information from the selected disk. This makes the disk appear as unallocated space.

clean all

Does the same as clean but also overwrites every sector with zeros. This takes hours on large drives but ensures data cannot be recovered easily.

create partition primary

Creates a new primary partition using all available unallocated space on the disk.

create partition primary size=50000

Creates a primary partition of 50,000 MB (about 50 GB).

format fs=ntfs quick

Formats the selected volume with NTFS file system using quick format.

format fs=fat32 quick

Formats with FAT32, useful for USB drives that need compatibility with multiple devices.

assign letter=G

Assigns drive letter G to the selected volume.

remove letter=G

Removes the drive letter from a volume, making it invisible in File Explorer.

convert gpt

Converts the disk’s partition style to GPT (GUID Partition Table).

convert mbr

Converts to MBR (Master Boot Record) partition style.

active

Marks the selected partition as active (bootable) for MBR disks.

Step-by-Step Common Tasks

Task 1: Completely Erase a USB Drive

This removes all partitions and prepares the drive for a fresh start.

diskpart
list disk
select disk 2
clean
create partition primary
format fs=fat32 quick
assign letter=F
exit

What each line does:

  1. Opens DiskPart
  2. Shows all disks so you can identify your USB drive by size
  3. Selects the USB drive (verify the number matches your USB)
  4. Removes all partitions
  5. Creates one new partition using the whole drive
  6. Formats it with FAT32
  7. Assigns drive letter F
  8. Exits DiskPart

Task 2: Create Multiple Partitions on One Disk

diskpart
list disk
select disk 1
clean
create partition primary size=102400
format fs=ntfs quick label="System"
assign letter=C
create partition primary
format fs=ntfs quick label="Data"
assign letter=D
exit

This creates a 100 GB system partition and uses remaining space for data.

Task 3: Convert Disk from MBR to GPT

Warning: This erases all data on the disk. Back up first.

diskpart
list disk
select disk 3
clean
convert gpt
exit

GPT is required for drives larger than 2 TB and for UEFI boot on modern systems.

Task 4: Remove Drive Letter to Hide a Partition

diskpart
list volume
select volume 5
remove letter=E
exit

The partition still exists but won’t show in File Explorer. Useful for recovery partitions or backup drives you don’t want accidentally modified.

Task 5: Fix “The Disk Is Write Protected” Error

Some USB drives get locked with a write protection flag.

diskpart
list disk
select disk 2
attributes disk clear readonly
exit

If this doesn’t work, the drive might have physical damage or a hardware write-protection switch.

Partition Styles: MBR vs GPT

Your disk uses either MBR or GPT as its partition scheme. This affects how many partitions you can create and maximum disk size.

FeatureMBRGPT
Maximum disk size2 TB256 TB (theoretical limit far higher)
Maximum partitions4 primary (or 3 primary + extended)128 partitions
Boot modeBIOS LegacyUEFI
Data redundancySingle partition tableMultiple copies for recovery
Windows supportAll versionsWindows Vista and newer

When to use MBR:

  • Disk is smaller than 2 TB
  • You need compatibility with very old Windows versions
  • Your motherboard only supports BIOS (not UEFI)
See also  Differences Between Bridging Stablecoins and Bridging BTC: A Complete Guide

When to use GPT:

  • Disk is larger than 2 TB
  • You’re installing Windows on a modern UEFI system
  • You want better reliability and recovery options
  • You need more than four partitions

To check your current partition style:

diskpart
list disk

Look for an asterisk (*) in the “Gpt” column. If present, that disk uses GPT. No asterisk means MBR.

Troubleshooting Common DiskPart Errors

“Virtual Disk Service Error: The Device Is Not Ready”

This happens when:

  • The disk has physical damage
  • The USB connection is loose
  • The drive is initializing

Fix: Unplug the drive, wait 10 seconds, reconnect it. If the error persists, try a different USB port or cable. Run chkdsk /f on the drive if you can access it.

“DiskPart Has Encountered an Error: Access Is Denied”

You’re not running DiskPart as administrator.

Fix: Close DiskPart. Open Command Prompt by right-clicking and selecting “Run as administrator,” then launch DiskPart again.

“There Is No Disk Selected”

You tried to run a command without selecting a disk first.

Fix: Run list disk, then select disk # with the correct number before trying your command again.

“The System Cannot Find the File Specified”

Usually appears when trying to run DiskPart from a location where it doesn’t exist, or when typing the command incorrectly.

Fix: Type the full path: C:\Windows\System32\diskpart.exe or ensure you’re in Command Prompt, not a regular folder window.

“Convert Is Not Allowed on the Current Boot Disk”

You cannot convert your Windows system disk while Windows is running.

Fix: Boot from a Windows installation USB, press Shift + F10 to open Command Prompt, then run DiskPart commands. Or use a third-party partitioning tool that can handle this.

Advanced DiskPart Features

Working with Virtual Hard Disks (VHD)

DiskPart can create and manage VHD files used by Hyper-V and other virtualization software.

diskpart
create vdisk file="C:\vdisks\test.vhd" maximum=20000
select vdisk file="C:\vdisks\test.vhd"
attach vdisk
exit

This creates a 20 GB virtual disk file and mounts it to Windows like a physical drive.

Extending or Shrinking Partitions

You can resize partitions if there’s unallocated space adjacent to them.

diskpart
list volume
select volume 3
extend size=10000
exit

This extends the selected volume by 10 GB, but only works if unallocated space exists immediately after the partition.

To shrink a partition:

diskpart
list volume
select volume 3
shrink desired=20000
exit

Shrinks the volume by 20 GB and creates unallocated space.

Setting Disk Attributes

Control whether a disk is read-only or visible.

diskpart
select disk 2
attributes disk set readonly

Makes the disk read-only. Change set to clear to reverse it.

attributes disk clear readonly

DiskPart vs Disk Management vs Third-Party Tools

DiskPart Advantages:

  • Already installed on every Windows system
  • Works through remote sessions
  • Faster than GUI tools
  • Can be scripted for automation
  • Works in recovery environments

DiskPart Limitations:

  • No visual representation of disk layout
  • Higher risk of mistakes
  • Cannot resize partitions as flexibly as some tools
  • No undo function

When to use Disk Management instead:

  • You prefer visual interfaces
  • You’re performing simple tasks like assigning drive letters
  • You want to see disk layout graphically

When to use third-party tools:

  • You need to resize system partitions without data loss
  • You want to convert MBR to GPT without erasing data
  • You need advanced features like partition merging or partition recovery

Microsoft provides comprehensive documentation for DiskPart at the official Windows command reference.

Automating DiskPart with Scripts

For repetitive tasks, you can create a text file with DiskPart commands and run them automatically.

Create a file called diskpart_script.txt:

select disk 2
clean
create partition primary
format fs=ntfs quick
assign letter=F
exit

Run it from Command Prompt:

diskpart /s diskpart_script.txt

DiskPart executes each command in sequence without manual input. This is useful for IT professionals who need to configure multiple drives identically.

See also  AI Story Generators: How to Create Stories With Artificial Intelligence in 2026

Important: Scripts make mistakes faster too. Test your script on a non-critical drive first.

Security and Data Recovery Considerations

How Clean Actually Works

The clean command only removes the partition table. Your actual files remain on the disk until overwritten. Data recovery software can often restore files after a clean command.

The clean all command overwrites every sector with zeros. This takes much longer but makes standard data recovery impossible. Even clean all can sometimes be defeated by forensic recovery techniques.

For secure erasure: Use specialized tools like the built-in Windows cipher command or dedicated disk wiping software if you’re disposing of a drive that contained sensitive data.

What DiskPart Cannot Do

DiskPart cannot:

  • Recover deleted partitions
  • Repair corrupted file systems (use chkdsk for that)
  • Clone disks
  • Create disk images
  • Recover lost data
  • Bypass BitLocker encryption
  • Modify dynamic disks in complex ways

For these tasks, you need specialized utilities or other Windows tools.

Real-World Use Cases

Scenario 1: Creating Windows Installation Media

Many users need to prepare USB drives for Windows installation. The Windows Media Creation Tool usually handles this, but sometimes it fails. DiskPart can prepare the drive manually:

  1. Clean the USB drive completely
  2. Create a primary partition
  3. Format as FAT32 for UEFI or NTFS for BIOS
  4. Mark partition as active (for BIOS only)
  5. Copy Windows installation files to the drive

Scenario 2: Fixing Unallocated Space Problems

Sometimes after deleting partitions, Disk Management won’t let you extend a partition into the newly freed space. DiskPart can force this operation when the GUI refuses.

Scenario 3: Preparing Drives for Linux Installation

If you’re dual-booting Windows and Linux, DiskPart can shrink your Windows partition to create unallocated space where Linux installers can work.

Scenario 4: Removing OEM Recovery Partitions

Computer manufacturers often create multiple hidden partitions. DiskPart lets you remove these if you’ve created your own backup and want to reclaim that space.

Summary

DiskPart.exe is a powerful command-line tool that gives you complete control over disk management in Windows. It works faster than graphical tools and handles situations where GUI utilities fail. The trade-off is risk: commands execute immediately without confirmation, and there’s no undo.

Start with simple tasks on external drives. Use list disk religiously before every operation. Verify disk numbers twice before running destructive commands. Once you’re comfortable with basic commands like clean, create partition, and format, you can tackle more advanced operations like MBR/GPT conversion and VHD management.

For everyday partition management, Disk Management’s GUI is usually safer and sufficient. Reserve DiskPart for situations requiring its speed, precision, or capability to work in command-line-only environments. With practice and caution, DiskPart becomes an essential tool for Windows system administration and troubleshooting.

Frequently Asked Questions

Can DiskPart damage my computer permanently?

DiskPart itself cannot damage hardware, but selecting the wrong disk and running clean will erase your operating system or personal files. Always verify disk numbers with list disk before any destructive command. The data loss is permanent unless you have backups.

Is DiskPart better than Disk Management?

Neither is universally better. DiskPart works faster, handles more scenarios, and runs in command-line environments. Disk Management provides visual feedback and prevents some common mistakes through its interface. Use DiskPart when you need its specific capabilities or when GUI tools fail.

How do I know which disk number is my USB drive?

Run list disk and look at the size column. A 32 GB USB drive will show approximately 29 GB after formatting overhead. You can also remove the USB drive, run list disk, plug it back in, run list disk again, and see which disk appeared. External drives often have higher disk numbers than internal drives.

Can I undo a DiskPart clean command?

No automatic undo exists. The regular clean command removes partition information but leaves data intact, so data recovery software might restore files. The clean all command overwrites everything with zeros and makes recovery nearly impossible. Always back up important data before using DiskPart.

Will DiskPart work on external hard drives and SD cards?

Yes, DiskPart works on any storage device Windows recognizes, including USB drives, external hard drives, SD cards, and SSDs. The commands are identical regardless of device type. Be extra careful with device selection since external drives often store important backups or files.

MK Usmaan