Most disk operations in Windows can be done through the graphical Disk Management tool. But there are situations where the GUI refuses to help — recovery partitions blocking an extend operation, disks that need to be initialized before Windows Setup can see them, or volumes that need scripted preparation across dozens of machines. This is where DISKPART earns its place in every sysadmin’s toolkit.
DISKPART is a command-line disk partitioning utility built into every version of Windows. It runs as an interactive interpreter or accepts script files, and it can do things that Disk Management simply cannot — including deleting protected partitions, converting disk styles, and automating full disk layouts in one pass.
DISKPART basics
DISKPART uses a select-then-act model. Before you can do anything to a disk, partition, or volume, you must select it first. The selected object becomes the focus of every subsequent command until you select something else.
| Command | What it does |
|---|---|
list disk | Show all physical disks |
list partition | Show partitions on selected disk |
list volume | Show all volumes on the system |
select disk N | Set focus to disk number N |
select partition N | Set focus to partition number N |
select volume N | Set focus to volume number N |
detail disk | Show details of selected disk |
detail partition | Show details of selected partition |
exit | Exit DISKPART |
rem Open DISKPART (must be in elevated CMD or PowerShell)
diskpart
rem Once inside the interpreter:
list disk
Scenario 1: Extend C: on a VMware VM blocked by Recovery Partition
You expand a VMware virtual disk from 60 GB to 80 GB. You open Disk Management — 20 GB of unallocated space appears, but the “Extend Volume” option for C: is greyed out. The reason: a Recovery Partition sits between C: and the new unallocated space. Disk Management cannot extend across or through another partition, and it refuses to delete the recovery partition through the GUI.
The disk layout looks like this:
| Partition | Type | Size | Problem |
|---|---|---|---|
| Partition 1 | System (EFI) | 100 MB | — |
| Partition 2 | MSR | 16 MB | — |
| Partition 3 | Primary (C:) | 59 GB | Cannot extend |
| Partition 4 | Recovery | ~900 MB | Blocking C: extension |
| (unallocated) | — | 20 GB | New space from vSphere resize |
The fix: use DISKPART to delete the recovery partition, then extend C: into the combined free space.
rem Step 1: Open DISKPART as Administrator
diskpart
rem Step 2: Identify your disk (look for the disk with your OS)
list disk
rem Step 3: Select the OS disk (replace 0 with your disk number)
select disk 0
rem Step 4: List all partitions and identify the Recovery partition
list partition
rem Step 5: Select the Recovery partition (replace 4 with its number)
select partition 4
rem Step 6: Verify it is the Recovery partition before deleting
detail partition
rem Step 7: Delete the protected partition
rem The 'override' flag is required — Recovery partitions are protected
delete partition override
rem Step 8: Confirm the partition is gone
list partition
rem Step 9: Select C: (the primary partition, usually partition 3)
select partition 3
rem Step 10: Extend C: into all available unallocated space
extend
rem Step 11: Confirm the new size
list partition
exit
extend only absorbs part of the free space, run extend size=N where N is the size in MB to extend by. Without a size argument, DISKPART extends using all contiguous unallocated space immediately following the partition.
Scenario 2: Initialize and prepare a new disk for data storage
You add a new virtual disk to a VM or attach a new physical disk to a server. Windows sees it in Device Manager but it does not appear in Explorer. Disk Management shows it as “Not Initialized”. You could right-click through the GUI, but if you are doing this on ten machines or in a Sysprep/WinPE context, DISKPART scripting is the right tool.
diskpart
rem List disks — identify the new uninitialized disk by its size
list disk
rem Select the new disk (replace 1 with your disk number)
select disk 1
rem Convert to GPT (use MBR only if the disk must be under 2TB and
rem the system is legacy BIOS without UEFI)
convert gpt
rem Create a single partition using all available space
create partition primary
rem Format as NTFS with a quick format, label it
format fs=ntfs label="DataDisk" quick
rem Assign the next available drive letter automatically
assign
rem Confirm the result
list volume
exit
assign letter=D (or any other letter) instead of plain assign if you need a specific drive letter. Without a letter argument, Windows picks the next available one — which may not match what your application or scripts expect.
convert gpt on a disk that already has data will fail with “there is not enough space.” On an initialized disk with existing partitions, conversion requires the disk to be empty. If you need to convert a data disk in-place, use mbr2gpt for the OS disk, or back up and repartition for data disks.
Scenario 3: Automate disk preparation with a script file
DISKPART can read commands from a text file instead of accepting them interactively. This is the right approach for unattended setups, WinPE environments, and any repeated disk preparation task. Save your commands to a .txt file and pass it with /s.
Example script that wipes disk 1 and creates a clean two-partition layout (a common pattern for dedicated data disks on servers):
rem File: prepare-data-disk.txt
rem Usage: diskpart /s prepare-data-disk.txt
rem WARNING: This wipes disk 1 completely
select disk 1
clean
convert gpt
create partition primary size=51200
format fs=ntfs label="AppData" quick
assign letter=D
create partition primary
format fs=ntfs label="Logs" quick
assign letter=E
list volume
exit
rem Run the script from elevated CMD
diskpart /s C:\scripts\prepare-data-disk.txt
select disk 1 in a script without verifying which physical disk is disk 1 on the target machine. Disk numbering depends on controller order and can differ between machines. On critical systems, always run list disk interactively first to confirm disk numbers before executing a destructive script. A script that runs clean on the wrong disk destroys all data on it immediately.
Scenario 4: Fix a disk that Windows Setup cannot see
During Windows installation, the “Where do you want to install Windows?” screen shows no disks, or shows the disk as unavailable. This happens on disks that are offline, read-only (SAN disks often arrive with this attribute set), or that carry an old MBR from a previous OS. DISKPART from within the WinPE environment (Shift+F10 during setup) fixes all three.
rem Open CMD during Windows Setup: press Shift+F10
diskpart
rem Check if the disk is offline or read-only
list disk
rem Select the problem disk
select disk 0
rem If status shows "Offline", bring it online
online disk
rem If the disk is read-only (common with SAN/iSCSI LUNs)
attributes disk clear readonly
rem Wipe existing partition table if reusing an old disk
clean
rem Reinitialize for modern UEFI systems
convert gpt
rem Exit — let Setup take over
exit
attributes disk clear readonly removes the flag for the current session. To make this persistent across reboots on a multi-path SAN, you may also need to adjust the SAN policy: san policy=OnlineAll before running online disk.
Scenario 5: Remove a stubborn USB drive or ghost volume
A USB drive is showing up with a drive letter but refuses to be ejected — either Windows says it is in use, or the volume keeps reappearing after removal. A related problem: ghost volumes left over from disconnected iSCSI targets or removed virtual disks that still consume drive letters. DISKPART can remove the drive letter assignment without deleting the data.
diskpart
rem Find the volume with the unwanted drive letter
list volume
rem Select it (replace 3 with the volume number)
select volume 3
rem Remove the drive letter without touching the data
remove letter=F
rem For a ghost volume that should not exist at all,
rem offline it first to prevent accidental access
offline volume
exit
remove letter=X only removes the letter assignment — the partition and data remain intact. The volume will be inaccessible until a letter is assigned again via assign letter=X or through Disk Management. This is useful for hiding volumes from Explorer without deleting them (backup target volumes, for example).
Key DISKPART commands reference
| Command | What it does | Notes |
|---|---|---|
clean | Remove all partition and volume information from disk | Destructive — all data lost |
clean all | Same as clean but also zeroes every sector | Slow but secure — use before decommission |
convert gpt | Convert MBR disk to GPT | Disk must be empty |
convert mbr | Convert GPT disk to MBR | Disk must be empty, max 2TB |
create partition primary | Create a primary partition using all space | Add size=N for specific size in MB |
delete partition override | Force-delete any partition including protected ones | Use override for Recovery / System partitions |
extend | Extend selected partition into contiguous unallocated space | Add size=N to extend by N MB |
shrink desired=N | Shrink partition by N MB | Cannot shrink below used space |
format fs=ntfs quick | Quick format selected partition as NTFS | Add label="Name" to set volume label |
assign letter=X | Assign drive letter X to selected volume | Omit letter for automatic assignment |
remove letter=X | Remove drive letter from volume | Data intact, volume becomes inaccessible |
online disk | Bring an offline disk online | Required on SAN / iSCSI disks |
attributes disk clear readonly | Remove read-only flag from disk | Common fix for SAN disks |
san policy=OnlineAll | Automatically bring new disks online | Apply before adding drives in automation |
Tips and gotchas
- There is no undo. DISKPART does not ask for confirmation on destructive commands like
cleanordelete partition override. Once executed, data is gone. Always take a VM snapshot or verify you have a backup before running anything destructive. - Disk numbers change. Adding or removing hardware changes how Windows numbers disks. A script that worked last week with
select disk 2may target a different disk today. Validate withlist diskanddetail diskbefore scripting destructive operations. - Extend only works on contiguous space. The unallocated space must immediately follow the partition you want to extend. If there is another partition between them — like the Recovery partition in Scenario 1 — you must remove it first.
- GPT vs MBR matters for EFI systems. UEFI-based systems require GPT for the OS disk. If a disk is converted to MBR, Windows Setup in UEFI mode will refuse to install to it. Use GPT for all modern systems.
- DISKPART cannot shrink below the immovable files mark. System files, the hibernation file (
hiberfil.sys), and the pagefile can block shrink operations. Disable hibernation (powercfg -h off) and temporarily move the pagefile before shrinking C:. - Use
detail partitionto confirm before deleting. It shows the partition type GUID — Recovery partitions have a specific GUID. Confirming type before runningdelete partition overrideprevents accidentally removing the wrong partition.
Related tools
- Windows Command Line (CMD) Cheat Sheet — quick reference for CMD commands including disk and file system utilities
- PowerShell Commands Cheat Sheet — manage disks with Get-Disk, Initialize-Disk, and New-Partition as an alternative to DISKPART
Related guides
- WMIC vs PowerShell — when to use legacy CLI tools vs modern PowerShell alternatives
- ATTRIB command — manage file and folder attributes from the command line
- DIR command — navigate and list disk contents from CMD
- CHKNTFS command — control and skip disk check at startup