Skip to content
WindowsAdvanced

DiskPart Explained: How It Works, Commands, Benefits, Risks, and Safe Usage

QUICK ANSWER DiskPart is a command-line storage-management utility included with Windows. It can inspect and manage physical disks, partitions, volumes, and ...

BI
Bison Technical Team Enterprise IT specialists
Updated 18 Sep 2026 15 min read 2 total views

QUICK ANSWER

DiskPart is a command-line storage-management utility included with Windows. It can inspect and manage physical disks, partitions, volumes, and virtual hard disks. Administrators commonly use it to initialize disks, create or remove partitions, format volumes, assign drive letters, change disk attributes, and prepare storage during Windows deployment.

Advertisement

DiskPart is powerful but potentially destructive. Commands operate on the currently selected object, called the object “in focus.” Selecting the wrong disk before running clean, delete, or format can cause permanent data loss. Always back up important data and verify the disk number, capacity, and details before making changes.

 

What Is DiskPart?

DiskPart is Microsoft’s interactive command-line interpreter for managing storage in Windows. It is available in supported versions of Windows 10, Windows 11, Windows Server, Windows Recovery Environment, and Windows Preinstallation Environment.

It can manage:

  • Physical HDDs, SSDs, and removable drives
  • Disks connected through USB, SATA, SAS, NVMe, and supported storage controllers
  • Partitions and volumes
  • Drive letters and mount points
  • GPT and MBR partition styles
  • Disk and volume attributes
  • Virtual hard disks in VHD and VHDX formats
  • Storage automount and SAN policies

DiskPart is particularly useful when Disk Management cannot perform an operation, when Windows does not start normally, or when storage configuration must be automated.

How DiskPart Works

DiskPart uses an object-selection model known as focus.

The usual workflow is:

  1. Start DiskPart.
  2. List the available storage objects.
  3. Select the required disk, partition, volume, or virtual disk.
  4. Verify the selected object.
  5. Run a command against that object.
  6. Confirm the result.

For example:

 
diskpart
list disk
select disk 1
detail disk
 

After select disk 1, disk 1 remains in focus until another object is selected or DiskPart is closed. Commands such as clean, create partition, and convert gpt will act on that selected disk.

An asterisk in list disk, list partition, or list volume output normally identifies the object currently in focus.

Warning: Disk numbers are not guaranteed to remain identical after drives are connected, removed, or detected in a different order. Never rely only on a disk number copied from an earlier session or another computer.

Requirements and Prerequisites

Before using DiskPart:

  • Sign in with an account that has appropriate administrative privileges.
  • Open Windows Terminal, Command Prompt, or PowerShell as an administrator.
  • Back up all important data before changing partitions or disk layouts.
  • Disconnect unnecessary external drives when practical.
  • Record the target disk’s capacity, model, current volumes, and drive letters.
  • Suspend BitLocker protection when a planned partition change requires it.
  • Confirm that the operation is supported for the selected disk and file system.

To start DiskPart from an elevated terminal:

 
diskpart
 

The prompt changes to:

 
DISKPART>
 

Type the following to leave DiskPart:

 
exit
 

DiskPart is also available from Windows Recovery Environment and Windows PE. Drive letters in recovery environments can differ from those assigned in normal Windows, so verify volumes by size, label, and contents.

Essential Inspection Commands

Inspection commands should be used before making changes.

Command Purpose
list disk Lists detected physical and virtual disks
list volume Lists available volumes
list partition Lists partitions on the selected disk
list vdisk Lists virtual disks
select disk <number> Places a disk in focus
select volume <number> Places a volume in focus
select partition <number> Places a partition in focus
detail disk Shows information about the selected disk
detail volume Shows information about the selected volume
detail partition Shows information about the selected partition
filesystems Shows the current and supported file systems for the selected volume
rescan Searches for newly added disks

A safe identification sequence is:

 
list disk
select disk 2
detail disk
list partition
list volume
 

Check the disk model, capacity, volumes, and partition layout before proceeding.

Common DiskPart Tasks

Prepare a New, Empty Disk

The following example prepares an empty disk as GPT, creates one partition, formats it as NTFS, and assigns a drive letter.

Destructive operation: clean removes partition and volume information from the selected disk. Replace disk 2 with the verified number of the intended disk.

 
diskpart
list disk
select disk 2
detail disk
clean
convert gpt
create partition primary
format fs=ntfs label="Data" quick
assign letter=E
exit
 

Afterward, the disk should appear in File Explorer as drive E:.

If the letter is already in use, choose another available letter or omit the letter:

 
assign
 

Windows will assign an available drive letter when possible.

Format an Existing Volume

Formatting removes the existing file-system structures and makes the volume ready for new data.

 
list volume
select volume 4
detail volume
format fs=ntfs label="Archive" quick
 

Common file-system choices include NTFS, FAT32, and exFAT, but availability and supported volume sizes depend on the Windows version, device, and formatting method. Run filesystems after selecting a volume to see supported options.

A quick format creates new file-system structures without scanning every sector for bad areas. It does not provide secure data sanitization.

Assign, Change, or Remove a Drive Letter

Assign a specific letter:

 
select volume 4
assign letter=R
 

Remove a drive letter without deleting the volume:

 
select volume 4
remove letter=R
 

Changing or removing a drive letter can break applications, shortcuts, services, and scripts that depend on the old path. Avoid changing the Windows system or boot volume letter.

Create a Partition of a Specific Size

DiskPart sizes are commonly specified in megabytes:

 
select disk 2
create partition primary size=102400
format fs=ntfs label="Data" quick
assign
 

This creates a partition of approximately 100 GB, using 102,400 MB.

Extend a Volume

First inspect the selected volume and available unallocated space:

 
list volume
select volume 3
detail volume
extend
 

If an amount is required:

 
extend size=20480
 

This requests an extension of 20,480 MB.

Whether a volume can be extended depends on factors such as its file system, disk type, partition layout, and the location of unallocated space. DiskPart does not move partitions to create suitable adjacent space. Back up the volume before resizing it.

Shrink a Volume

Check how much space Windows can reclaim:

 
select volume 3
shrink querymax
 

Then shrink it by a specified amount:

 
shrink desired=20480 minimum=10240
 

Unmovable files, file-system state, storage configuration, or insufficient free space can limit shrinking. DiskPart does not guarantee that the full requested amount will be available.

Delete a Partition or Volume

Delete a selected partition:

 
select disk 2
list partition
select partition 1
detail partition
delete partition
 

Delete a selected volume:

 
select volume 4
detail volume
delete volume
 

These operations destroy access to the data stored in the selected partition or volume. Protected system, recovery, OEM, and EFI partitions may reject normal deletion. Do not force their removal unless their purpose has been positively identified and the system’s boot and recovery requirements have been evaluated.

Convert Between GPT and MBR

For a normal basic-disk conversion using DiskPart, the disk must not contain partitions or volumes. Therefore, back up the data and remove the disk layout before conversion.

Convert an empty disk to GPT:

 
select disk 2
clean
convert gpt
 

Convert an empty disk to MBR:

 
select disk 2
clean
convert mbr
 

clean is destructive. Do not use this procedure on a running Windows system disk merely to change its partition style. For a supported conversion of a compatible Windows system disk from MBR to GPT without deleting its data, evaluate Microsoft’s MBR2GPT.exe tool instead.

GPT is generally preferred for modern UEFI systems and large or complex disk layouts. MBR remains useful mainly for older BIOS-based systems and legacy compatibility.

Bring a Disk Online or Clear Read-Only Status

Inspect the disk first:

 
select disk 2
detail disk
attributes disk
 

Bring an offline disk online:

 
online disk
 

Clear a read-only disk attribute:

 
attributes disk clear readonly
 

A disk may remain inaccessible if write protection is enforced by hardware, storage firmware, a controller, SAN policy, group policy, media failure, or another storage layer. Do not clear attributes on shared or protected storage without understanding why they were applied.

Manage a Virtual Hard Disk

DiskPart can select and attach an existing VHD or VHDX file:

 
select vdisk file="C:\VirtualDisks\Test.vhdx"
attach vdisk
 

Attach it as read-only when changes are not required:

 
attach vdisk readonly
 

Detach the selected virtual disk:

 
detach vdisk
 

Detaching makes the virtual disk unavailable but does not delete its VHD or VHDX file. Ensure that applications have finished writing to it before detaching.

Understanding clean and clean all

These commands are not equivalent.

Command Effect
clean Removes partition and volume formatting information from the selected disk
clean all Writes zeros to every sector on the selected disk, completely deleting its contained data

clean normally completes quickly but should not be treated as secure sanitization because underlying data may remain recoverable.

clean all takes considerably longer because it writes across the entire device. It is destructive, provides no normal undo function, and should not automatically be treated as sufficient for every regulatory, forensic, SSD, or enterprise media-disposal requirement. For sensitive data, follow the storage manufacturer’s supported sanitization procedure and the organization’s data-destruction policy.

Neither command repairs physical media damage.

DiskPart Scripting and Automation

DiskPart can run commands from a text file:

 
diskpart /s C:\Scripts\PrepareDisk.txt
 

Its output can be redirected to a log:

 
diskpart /s C:\Scripts\PrepareDisk.txt > C:\Logs\DiskPart.log
 

A script contains one DiskPart command per line. Microsoft advises against empty lines; lines beginning with rem can be used for comments.

Example:

 
rem Verify that disk 2 is the intended target before running
select disk 2
detail disk
clean
convert gpt
create partition primary
format fs=ntfs label="Data" quick
assign letter=E
 

DiskPart normally stops a script when an operational error occurs. Some commands support noerr, which allows script processing to continue, but syntax errors are still reported.

Use noerr cautiously. Continuing after an unexpected failure can cause later commands to act on an incorrect state. Automated scripts should include external validation and should not assume that a particular physical device will always receive the same disk number.

Microsoft recommends grouping related DiskPart operations into one script. If consecutive DiskPart scripts must be executed, allow sufficient time for the previous DiskPart process to shut down; Microsoft documents a delay of at least 15 seconds.

Major DiskPart Command Groups

Area Representative commands
Discovery list, detail, rescan
Selection select disk, select volume, select partition, select vdisk
Disk preparation clean, convert gpt, convert mbr
Partition management create partition, delete partition, extend, shrink
Volume management format, assign, remove, delete volume
State and attributes online, offline, attributes
Virtual disks create vdisk, select vdisk, attach vdisk, detach vdisk, expand vdisk, compact vdisk
Enterprise storage automount, san
Help and control help, exit

For exact syntax on the installed version of Windows, use:

 
help
help clean
help format
help extend
 

This is preferable to copying an unverified command from a third-party tutorial.

Benefits of DiskPart

Works Without a Graphical Desktop

DiskPart can operate in Command Prompt, Windows Recovery Environment, Windows PE, Server Core, and deployment environments where Disk Management may be unavailable.

Provides Precise Object Selection

Administrators can explicitly select disks, partitions, and volumes and then inspect them before making changes.

Supports Repeatable Automation

DiskPart scripts can standardize storage preparation during deployment, imaging, laboratory setup, and administrative maintenance.

Handles More Than Basic Partitioning

In addition to creating and formatting partitions, DiskPart can manage attributes, drive letters, virtual disks, automount behavior, and SAN policies.

Uses Built-In Windows Components

No separate download is normally required, which makes DiskPart useful for recovery and controlled enterprise environments.

Important Risks and Limitations

  • DiskPart does not ask for confirmation before many destructive operations.
  • Selecting the wrong disk can erase an operating system or backup.
  • There is no built-in undo command for clean, formatting, or partition deletion.
  • DiskPart is not primarily a file-recovery or partition-recovery tool.
  • Formatting does not fix failing hardware.
  • DiskPart cannot move partitions.
  • Resizing depends on the file system and physical partition layout.
  • Some operations cannot be performed on the current system, boot, page-file, crash-dump, recovery, or otherwise protected volume.
  • Disk numbers and recovery-environment drive letters can change.
  • Hardware write protection and controller-level problems cannot always be removed through DiskPart.
  • Storage Spaces, RAID controllers, SANs, clustered storage, and vendor-managed disks may require their own administration tools.
  • Changing SAN or automount policies can affect multiple disks and should be reserved for administrators who understand the environment.
  • A disk that disappears intermittently, reports I/O errors, or produces SMART or controller warnings may be physically failing. Copy recoverable data before attempting repairs.

A Safe DiskPart Checklist

Before any destructive command:

  1. Back up required data.
  2. Disconnect irrelevant removable drives if possible.
  3. Run list disk and list volume.
  4. Select the intended object.
  5. Run detail disk or detail volume.
  6. Match its capacity, model, label, and existing partitions.
  7. Re-read the command and confirm whether it deletes data.
  8. Record the original layout when working on important systems.
  9. Avoid experimentation on the production or boot disk.
  10. Stop if the displayed information does not match expectations.

For unfamiliar procedures, test them first on a disposable virtual disk rather than a physical disk containing valuable data.

Troubleshooting Common DiskPart Problems

“Access is denied” or Administrative Privileges Are Required

Close the terminal and reopen Windows Terminal, Command Prompt, or PowerShell by selecting Run as administrator.

An access error can also occur when a volume is in use, protected, encrypted, read-only, controlled by security software, or managed by another storage component.

The Disk Does Not Appear

Run:

 
rescan
list disk
 

If it remains absent, check:

  • Physical cables and power
  • USB ports or enclosures
  • Device Manager
  • Disk Management
  • Storage-controller and chipset drivers
  • BIOS or UEFI detection
  • RAID or storage-controller utilities
  • Hardware health

DiskPart cannot manage a device that Windows does not detect as an available disk.

The Disk Is Offline

Inspect it before changing its state:

 
select disk 2
detail disk
online disk
 

Shared disks and SAN-connected storage may intentionally remain offline because of the active SAN policy. Bringing shared storage online on the wrong server can risk corruption.

The Disk Is Read-Only

Check both disk and volume attributes:

 
select disk 2
attributes disk
 

If appropriate:

 
attributes disk clear readonly
 

For a selected volume:

 
attributes volume
attributes volume clear readonly
 

If the attribute returns, check for a physical lock switch, failing flash media, storage policies, controller configuration, or security software.

Extend Fails

Common causes include:

  • No usable unallocated space
  • Unallocated space in an unsuitable location
  • An intervening recovery or other partition
  • An unsupported file system
  • Disk-layout or storage-type restrictions
  • File-system errors

Inspect the layout in Disk Management or with list partition. DiskPart cannot relocate the intervening partition.

Shrink Cannot Reclaim Enough Space

Unmovable files or file-system metadata can limit the available shrink size. Run:

 
shrink querymax
 

Check the file system, available space, BitLocker state, and relevant Windows logs. Back up the volume before using alternative partition-management methods.

The Wrong Disk Was Cleaned or Deleted

Stop using the affected disk immediately. Do not create partitions, format it, initialize it, or copy files to it. Further writes can overwrite recoverable information.

DiskPart has no undo function. Restore from a verified backup or consult a qualified data-recovery provider when the data is important.

DiskPart Alternatives

Disk Management

Disk Management provides a graphical interface for common tasks such as initializing disks, creating volumes, changing drive letters, and attaching VHD files. It is often safer for occasional users because the disk layout is visible.

Open it by running:

 
diskmgmt.msc
 

PowerShell Storage Cmdlets

PowerShell offers object-based storage management suitable for modern administration and automation. Common cmdlets include:

 
Get-Disk
Get-Partition
Get-Volume
Initialize-Disk
New-Partition
Format-Volume
Resize-Partition
Set-Disk
 

PowerShell objects are generally easier to validate and integrate into scripts than parsed DiskPart text output.

MBR2GPT

MBR2GPT.exe is the appropriate Microsoft tool to evaluate when converting a compatible Windows system disk from MBR to GPT without deleting its data. Validate compatibility and maintain a current backup before conversion.

Manufacturer and Enterprise Storage Tools

Use vendor-supported tools for:

  • SSD secure erase or sanitize operations
  • Firmware updates
  • Hardware diagnostics
  • RAID configuration
  • SAN or multipath storage management
  • Device-specific encryption and security features

FAQ

Frequently Asked Questions

Is DiskPart included with Windows?

Yes. DiskPart is built into supported Windows client and server operating systems and is also available in Windows recovery and deployment environments.

Does DiskPart require administrator privileges?

Most storage-changing operations require an elevated terminal and suitable administrative permissions. Some inspection commands may display information without elevation, but running DiskPart as an administrator is normally required for management tasks.

Does clean permanently erase every file?

clean removes partition and volume formatting information but does not overwrite every sector. Data may remain recoverable. clean all writes zeros across the selected disk, but organizational sanitization requirements may call for manufacturer-supported secure erase, cryptographic erase, or physical destruction.

Can DiskPart recover a deleted partition?

No. DiskPart is a storage-management tool, not a partition-recovery utility. If a partition was deleted accidentally, stop writing to the disk and use an appropriate recovery process or professional service.

Can DiskPart repair a failing hard drive or SSD?

No. It can change a disk’s logical layout, but it cannot repair failing flash memory, damaged heads, bad electronics, controller faults, or other physical failures.

Can DiskPart format a USB drive?

Yes, provided Windows detects the device as a manageable disk. Verify the USB drive by capacity and details before cleaning or formatting it because removable and internal disks appear in the same disk list.

What is the difference between a disk, partition, and volume?

A disk is the physical or virtual storage device. A partition is a defined region in a disk’s partition table. A volume is a storage area Windows can format, mount, and use; it may correspond to a partition or, with some storage configurations, span a more complex arrangement.

Should I use GPT or MBR?

GPT is normally preferred for modern UEFI computers and current Windows installations. MBR is primarily retained for legacy BIOS compatibility and older systems. Confirm firmware and operating-system requirements before choosing.

Is DiskPart better than Disk Management?

Neither is universally better. Disk Management is easier for visual, occasional administration. DiskPart is valuable for recovery, advanced command-line work, Windows PE, Server Core, and repeatable scripting. PowerShell is often preferable for new administrative automation.

FINAL RECOMMENDATION / CONCLUSION

DiskPart is a capable Windows storage-management tool for preparing disks, managing partitions and volumes, assigning drive letters, controlling attributes, working with virtual disks, and automating deployment tasks. Its main advantage is precise command-line control in both normal and recovery environments.

Use it conservatively. Inspect the disk, select it explicitly, run detail disk or detail volume, and confirm the device by more than its disk number before executing a destructive command. Keep verified backups, use Disk Management for straightforward visual tasks, and prefer PowerShell or manufacturer-supported utilities when they provide safer validation or device-specific functionality.

 

#DiskPart #Windows #Windows11 #Windows10 #WindowsServer #DiskManagement #PartitionManagement #DiskFormatting #GPT #MBR #CommandPrompt #PowerShell #StorageManagement #USBDrive #SSD #HardDrive #SystemAdministration #WindowsRecovery #ITSupport #Troubleshooting

SOURCES

 

YOUR FEEDBACK

Was this guide useful?

Your answer helps us keep BISONKB accurate and practical.

THE BISON BRIEF

Practical IT knowledge, once a week.

New troubleshooting guides, scripts and infrastructure notes. No noise.

By subscribing, you agree to our privacy policy.