diskpart - Manage Disks and Partitions

Maintained on
Table of Contents

The diskpart command is used to manage disks, partitions, and volumes. You can run many of the operations available in Disk Management from the command line, such as creating and deleting partitions, formatting, and assigning drive letters.

It is also often used to fix problems such as “my USB drive became read-only and I cannot write to it” or “a partition remains that I cannot delete in Disk Management.”

Mistakes can erase your data

diskpart is a powerful command that can erase the contents of the selected disk instantly. Always confirm the number of the disk you are working on before running anything. If a disk contains important data, we recommend backing it up first.

Basic Usage of diskpart

Use diskpart in a Command Prompt that was run as administrator. If you start it with normal privileges, you will be asked for elevation or get an error. See the related articles for how to start it.

diskpart

After it starts, the prompt changes to DISKPART>. From here on, you enter diskpart-specific commands rather than regular commands.

- □ ×
Command Prompt Icon
Administrator: Administrator: Command Prompt - diskpart
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>diskpart
Microsoft DiskPart version 10.0.xxxxx.xxxx
Copyright (C) Microsoft Corporation.
On computer: DESKTOP-ABC123
DISKPART>

To quit, type exit.

DISKPART> exit

The Basics: “Select First, Then Run”

Operations in diskpart follow this flow.

  1. Display a list with a list command
  2. Choose the target with select
  3. Run an operation such as formatting or deleting on the selected target

Because commands run against whatever you selected with select, it is important to be aware of what is currently selected. The selected item is marked with * at the left edge of the list.

Check the List of Disks

DISKPART> list disk
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
Disk 1 Online 29 GB 0 B

The columns mean the following.

ColumnMeaning
Disk ###The disk number. This is the number you specify with select disk
StatusOnline, Offline, and so on
SizeThe capacity of the disk
FreeCapacity not allocated to a partition
DynMarked with * for a dynamic disk
GptMarked with * for the GPT format (if not marked, it is MBR)
Tell disks apart by size

Disk 0 is often the internal disk that contains Windows, but not always. Use list volume to check which disk C: is on, and identify USB drives and external drives by size (capacity). If you are unsure, unplug and reconnect the USB drive and compare list disk, and the number that appears or disappears is the target disk.

Check Disk Details

Once you select a disk, you can display its detailed information.

DISKPART> select disk 1
DISKPART> detail disk

detail disk shows the model name, type (USB, SATA, NVMe, and so on), whether the disk is read-only, the volumes on the disk, and more. It is useful as a final check before erasing.

Check Partitions and Volumes

With a disk selected, running list partition shows the partitions on that disk.

DISKPART> select disk 1
DISKPART> list partition

When you want to check drive letters and file systems, list volume is handy.

DISKPART> list volume
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 C Windows NTFS Partition 475 GB Healthy Boot
Volume 1 E USB_DRIVE FAT32 Partition 29 GB Healthy

To work with a volume, specify it by volume number, as in select volume 1, or by drive letter, as in select volume E.

Initialize and Format a USB Drive

This is the procedure for wiping a USB drive completely, creating a new partition, and formatting it. Everything on the disk is erased.

Initialize
DISKPART> list disk
DISKPART> select disk 1
DISKPART> detail disk
DISKPART> clean
DISKPART> create partition primary
DISKPART> format fs=ntfs quick label=USB_DRIVE
DISKPART> assign
DISKPART> exit

Each command does the following.

CommandPurpose
select disk 1Sets disk 1 as the target. Always confirm the number
cleanDeletes all partition and volume information on the disk
create partition primaryCreates a primary partition that uses all the free space
format fs=ntfs quick label=USB_DRIVEQuick-formats as NTFS and applies a label
assignAutomatically assigns an available drive letter
Don't get the select disk number wrong

clean immediately deletes the partition layout of the selected disk. If you run it while an internal disk is selected, such as select disk 0, Windows may no longer start. Run detail disk right after select disk, and always confirm that the size, model name, and type match the disk you intend to use. diskpart has no confirmation prompt and no undo.

Choosing a File System

For fs= in format, specify a file system that suits your purpose.

OptionCharacteristics
fs=ntfsFor Windows. Can handle files larger than 4 GB
fs=exfatWorks well on both Windows and Mac and can handle large files. Suited to USB drives and SD cards
fs=fat32Highly compatible. Each file must be smaller than 4 GB. diskpart cannot format volumes larger than 32 GB as FAT32
Quick Format vs. Full Format

Adding quick performs a quick format, which finishes in a short time. Omitting quick performs a full format, which takes a long time on large drives. A quick format is usually enough.

Change the Partition Style (MBR / GPT)

If the disk is empty, for example right after clean, you can convert its partition style.

DISKPART> convert gpt
DISKPART> convert mbr

convert fails with an error if partitions or volumes remain on the disk. Empty the disk first with clean or similar before running it. Note that the MBR format cannot use more than 2 TB of space.

When a USB Drive Is Read-Only

A USB drive that you cannot write to may have the “read-only” attribute set on the disk. You can check and clear it with the following steps.

DISKPART> list disk
DISKPART> select disk 1
DISKPART> attributes disk
DISKPART> attributes disk clear readonly

Running attributes disk displays the current state, such as Current Read-only State : Yes. Clearing the attribute with clear readonly lets you write to the drive without erasing its data.

SD cards and other media with a physical switch

SD cards and some USB drives have a physical write-protect switch. If the switch is in the locked position, you cannot write even after clearing the attribute with diskpart. Check the switch position first.

Delete a Partition

To delete only a specific partition rather than the whole disk, use delete partition.

DISKPART> select disk 1
DISKPART> list partition
DISKPART> select partition 2
DISKPART> delete partition

Protected partitions such as system partitions cannot be deleted with a plain delete partition. Adding delete partition override deletes them, but EFI system partitions, recovery partitions, and others are also erased without confirmation. Do not use it if you do not understand which area you are deleting.

Change a Drive Letter

You can select a volume and assign or remove its drive letter.

DISKPART> select volume 1
DISKPART> assign letter=F

For a volume that already has a drive letter, remove it first and then assign a new one.

DISKPART> select volume 1
DISKPART> remove letter=E
DISKPART> assign letter=F
Be careful when changing drive letters in use

Changing a drive letter that the system uses, such as C:, may affect how programs work. Do this only for external drives and disks you have added.

Extend and Shrink a Volume

You can select a volume and change its size. The unit is MB.

Extend
DISKPART> select volume 1
DISKPART> extend size=10240
Shrink
DISKPART> select volume 1
DISKPART> shrink querymax
DISKPART> shrink desired=10240
  • extend size=10240 expands the volume by 10240 MB (10 GB). This requires unallocated free space immediately after the volume on the same disk. If you omit size, it extends using all the available free space
  • shrink querymax displays the maximum size by which the volume can be shrunk. Run it first to check
  • shrink desired=10240 shrinks the volume by 10240 MB (10 GB). If the volume contains files that cannot be moved, it may not shrink to the size you want

extend applies to NTFS volumes (and ReFS on newer versions of Windows), and shrink applies to NTFS volumes. FAT32 and exFAT volumes can be neither extended nor shrunk.

Run Automatically with a Script

You can write diskpart commands in a text file and load it with the /s option to run them all at once.

format-usb.txt
select disk 1
clean
create partition primary
format fs=ntfs quick label=USB_DRIVE
assign
exit
diskpart /s format-usb.txt
Scripts run without confirmation

diskpart does not show confirmation messages even in interactive mode, but in a script it runs to the end with no chance to check the contents. If the select disk number has shifted at run time, it will erase a disk you did not intend. If disk numbers can change, for example when you plug and unplug USB drives, avoid running the script automatically and proceed by hand, checking as you go.

Quick Reference of Common Commands

What you want to doCommand
Display the list of diskslist disk
Select a diskselect disk <number>
Display disk detailsdetail disk
Display the list of partitionslist partition
Display the list of volumeslist volume
Empty a diskclean
Create a partitioncreate partition primary
Formatformat fs=ntfs quick label=<label>
Assign a drive letterassign letter=<letter>
Remove a drive letterremove letter=<letter>
Clear read-onlyattributes disk clear readonly
Run a scriptdiskpart /s <file name>
Quitexit
About clean all

clean all writes zeros to every sector of the entire disk. It makes data recovery harder, but depending on the disk’s capacity it can take a very long time, and it is normally unnecessary for SSDs. For an ordinary redo of formatting, clean is enough.

Practice Questions

Practice Problem

In diskpart, which command displays the list of connected disks before you choose the target disk?

Choose one answer.

  1. show disk
  2. list disk
  3. dir disk

Practice Problem

What happens when you run clean in diskpart?

Choose one answer.

  1. Only the unnecessary files on the selected disk are deleted
  2. All partition and volume information on the selected disk is deleted
  3. Errors on the disk are detected and repaired

Practice Problem

Which command do you run after selecting the disk to clear the read-only state of a USB drive?

Choose one answer.

  1. attributes disk set readonly
  2. attributes disk clear readonly
  3. format fs=ntfs quick
#Command Prompt #Command Line #Commands #diskpart #Disk #Partition #Format