DISKPART: practical guide for sysadmins — 5 scenarios where Disk Management fails

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.

CommandWhat it does
list diskShow all physical disks
list partitionShow partitions on selected disk
list volumeShow all volumes on the system
select disk NSet focus to disk number N
select partition NSet focus to partition number N
select volume NSet focus to volume number N
detail diskShow details of selected disk
detail partitionShow details of selected partition
exitExit DISKPART
Warning: DISKPART requires elevation. Always run it from an Administrator command prompt or PowerShell. Commands executed without elevation will fail silently or return access denied errors.
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:

PartitionTypeSizeProblem
Partition 1System (EFI)100 MB
Partition 2MSR16 MB
Partition 3Primary (C:)59 GBCannot extend
Partition 4Recovery~900 MBBlocking C: extension
(unallocated)20 GBNew space from vSphere resize
Common mistake: Deleting the recovery partition without first exporting the recovery image to a USB drive or ISO. If Windows Recovery Environment is needed after a failed update or boot issue and the partition is gone, you will need installation media to recover. On a production VM, ensure you have a snapshot or backup before proceeding.

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
Result: C: now spans the full available space. Disk Management will show the extended volume immediately — no reboot required. The Recovery Environment is gone, but on a VMware VM this is acceptable: you can boot from ISO for recovery if ever needed.
Note: If 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
Note: Use 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.
Warning: 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
Common mistake: Using 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
Result: Close CMD and click “Refresh” on the disk selection screen. The disk now appears as unallocated space and Windows Setup can create its standard partition layout on it.
Note: SAN and iSCSI disks are frequently set read-only by the storage array or by Windows SAN policy to prevent accidental writes from multiple hosts. 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
Note: 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

CommandWhat it doesNotes
cleanRemove all partition and volume information from diskDestructive — all data lost
clean allSame as clean but also zeroes every sectorSlow but secure — use before decommission
convert gptConvert MBR disk to GPTDisk must be empty
convert mbrConvert GPT disk to MBRDisk must be empty, max 2TB
create partition primaryCreate a primary partition using all spaceAdd size=N for specific size in MB
delete partition overrideForce-delete any partition including protected onesUse override for Recovery / System partitions
extendExtend selected partition into contiguous unallocated spaceAdd size=N to extend by N MB
shrink desired=NShrink partition by N MBCannot shrink below used space
format fs=ntfs quickQuick format selected partition as NTFSAdd label="Name" to set volume label
assign letter=XAssign drive letter X to selected volumeOmit letter for automatic assignment
remove letter=XRemove drive letter from volumeData intact, volume becomes inaccessible
online diskBring an offline disk onlineRequired on SAN / iSCSI disks
attributes disk clear readonlyRemove read-only flag from diskCommon fix for SAN disks
san policy=OnlineAllAutomatically bring new disks onlineApply before adding drives in automation

Tips and gotchas

  • There is no undo. DISKPART does not ask for confirmation on destructive commands like clean or delete 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 2 may target a different disk today. Validate with list disk and detail disk before 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 partition to confirm before deleting. It shows the partition type GUID — Recovery partitions have a specific GUID. Confirming type before running delete partition override prevents accidentally removing the wrong partition.

Related tools

Related guides