Using Diskpart: A Guide to Windows Disk Management

Learn how to manage disks in Windows using the Diskpart command

Last Update: Feb 18, 2025 | Published: Feb 12, 2025

Azure Hero Server scaled

SHARE ARTICLE

Diskpart is a powerful command-line utility in Windows that allows users to manage their hard drive, disks, partitions, and volumes with precision and control. This article covers key commands, syntax, and best practices to help you manage your storage devices effectively on any version of Windows.

How to access Diskpart

Diskpart is accessed from the command line.

  • You can open Windows Terminal from the Start Menu and use either a command prompt tab or a Windows PowerShell tab. The command will work in both shells.
Opening the Windows Terminal program from the Start Menu
Opening the Windows Terminal program from the Start Menu – Image Credit: Michael Reinders/Petri.com
  • To get started, type in ‘diskpart‘ and press Enter.
Starting the DISKPART shell
Starting the DISKPART shell – Image Credit: Michael Reinders/Petri.com

At this point, you’re at the DISKPART prompt in the local computer’s disk subsystem.

How does Diskpart work? (Key commands)

Understanding how Diskpart commands work is key. One word = “focus.” There are three steps to using Diskpart.

  1. The first step is selecting a particular volume, hard drive partitions, or disks.
  2. Then you mark the item as active.
  3. Finally, you perform actions on said item.

How to list all disks using Diskpart

For instance, we can first type ‘list disk’ to list the state of all disks in my Windows 11 PC. This will display both an online disk and an offline disk.

Using Diskpart 'list disk' to view all logical hard drives
Using Diskpart ‘list disk’ to view all logical hard drives – Image Credit: Michael Reinders/Petri.com

We see our current disks. I have a single ‘virtual’ disk, ‘Disk 0’. It is Online (of course), and is 60 GB in size. It is not a Dynamic Disk (Dyn is null), and the partition type is ‘GPT’.

How to list disk partitions using Diskpart

  • Let me type ‘list partitions‘ to view the partitions on the disk.
Using 'list disk' and 'list partition'
Using ‘list disk’ and ‘list partition’ – Image Credit: Michael Reinders/Petri.com

As you can see, focus is the linchpin to how Diskpart works. Thankfully, it is very precise – harder to make any mistakes, in my opinion.

How to select a disk and list partitions

So, first, let’s do:

  1. select disk 0
  2. ‘list partition’ again
Typing 'select disk 0' and 'list partition' to see current partitions
Typing ‘select disk 0’ and ‘list partition’ to see current partitions – Image Credit: Michael Reinders/Petri.com

There we go. We have 4 partitions. As I’m sure you’re familiar with the Windows Disk Management console, this will undoubtedly look familiar to you. Partition 3 shows 59 GB in size, that is our ‘C: drive.’

Add a new disk to Windows using Diskpart

Let’s go ahead and show you how to handle the addition of a new disk to the computer. Behind the scenes, I will add a 100GB virtual hard disk using the Hyper-V Manager interface because this is a virtual machine (VM). Then, we’ll need to initialize it, select the new disk, and create a partition…let’s not get ahead of ourselves. One moment.

  • Now, let’s try ‘list disk‘ again.
Using 'list disk' to see our new second disk
Using ‘list disk’ to see our new second disk – Image Credit: Michael Reinders/Petri.com

Now we have two disks. You can see that ‘Disk 1’ is the new 100GB disk.

  • First, we need to select it with ‘Select Disk 1‘.

Create a new disk partition

We’ve selected Disk 1. When we list partitions, it shows there aren’t any.

  • Let’s create a partition with this command – ‘create partition primary‘. We can create a specific partition type by specifying it.
We've selected the new disk, and created a new primary partition
We’ve selected the new disk, and created a new primary partition – Image Credit: Michael Reinders/Petri.com

We’ve created our new primary partition. When we ‘list partition‘, we see that Partition 1 is selected (due to the ‘*’ to the left of the partition.

Create and format a new NTFS volume

Now all we need to do is create a new disk volume:

  • Type ‘select partition 1‘ to give it focus.
  • Type ‘format fs=ntfs label=Extra quick‘ to add a logical volume.
Formatting our new partition with NTFS
Formatting our new partition with NTFS – Image Credit: Michael Reinders/Petri.com

Done! The filesystem is NTFS, the drive label is ‘Extra’, and I ‘quick formatted’ the current volume.

List all disk volumes using Diskpart

  • Now we’ll type ‘list volume‘ to see the various volumes and the size of the selected volume (logical containers as Windows sees them).
Diskpart 'list volume' shows all the volumes on the computer
List volume shows all the volumes on the computer – Image Credit: Michael Reinders/Petri.com

We can see our C: drive, our current D: drive (a virtual DVD drive), and the selected Volume 4. There’s the ‘Extra’ label.

How to assign a drive letter with Diskpart

Let’s assign a drive letter next.

  • As ‘Volume 4’ is already selected (the ‘*’), we can type ‘assign letter=E‘ and press Enter.

Voila! There’s a popup from Windows identifying a new volume recognized and accessible in the operating system. Let me open File Explorer and Disk Management to confirm all our hard work.

Validating our work with Disk Management and File Explorer
Validating our work with Disk Management and File Explorer – Image Credit: Michael Reinders/Petri.com

Everything looks good. Let’s backtrack a bit and go over some of the more rudimentary basics of the syntax in Diskpart.

Diskpart syntax basics and example commands

After starting Diskpart by typing in ‘diskpart’ in your admin command prompt, the new interpreter opens. Here are the basic commands and syntax when using Diskpart:

CommandDescriptionExample
diskpartOpens the Diskpart utilitydiskpart
list diskLists all diskslist disk
list volumeLists all volumeslist volume
list partitionLists all partitions on the selected disklist partition
select disk XSelects disk number Xselect disk 1
select volume XSelects volume number Xselect volume 2
select partition XSelects partition number Xselect partition 1
create partition primary size=XXXXCreates a primary partition of specified sizecreate partition primary size=10000
format fs=ntfs quickFormats the selected partition with the NTFS file systemformat fs=ntfs quick
assign letter=YAssigns the drive letter Y to the selected volumeassign letter=D
cleanRemoves all partitions and volumes from the selected diskclean
detail partitionShows detailed information about the selected partitiondetail partition
Diskpart commands, their functions, and examples

Here are some general tips and tricks.

If you need to convert the partition style from MBR to GPT, you can type ‘convert gpt‘ on a selected partition.

Another common troubleshooting step is repairing MBR and GPT partitions. A very simple and succinct Diskpart command – ‘clean’. After you’ve selected a particular disk (using for example ‘select disk 1’), you can use the diskpart clean command to erase all partitions and volumes from the disk. It’s similar to wiping the master boot record.

Note – you can use diskpart on computers running BIOS or UEFI mode.

What is Diskpart?

Diskpart was introduced in Windows 2000, replacing the rather old, long-in-the-tooth, fdisk command. A command interpreter helps you manage your computer’s drives (partitions, disks, volumes, or virtual hard disks) from the command line. The most basic equivalent to a GUI in Windows is the MMC-based Disk Management tool.

Diskpart offers excellent detail when displaying information like system volume, system partition, which volume is your boot volume, and even lists specific types of volumes:

Prerequisites – Supported Windows versions

Every version of Windows (including Windows client and Windows Server) since Windows 2000 has included Diskpart – even “Home” editions. The only real prerequisite is that you’ll need to have administrative privileges in your command prompt or Windows Terminal shell.

Be careful when using Diskpart. You can irrevocably delete or lose data easily on your computers or servers. You can’t recover a deleted partition. Double-check your commands and double-check what disk, volume, or partition is active before you execute – more on this in a bit. If you mess up, you may be unable to boot Windows.

Troubleshooting with Diskpart and best practices

Here are common troubleshooting ideas you should always keep in mind when using Diskpart:

  1. Run Diskpart as Administrator: Ensure you have administrative privileges to make changes to disk partitions.
  2. Check Diskpart Syntax: Double-check the commands and parameters for any typos or errors.
  3. Verify Disk and Volume Selections: Use list disklist volume, and list partition to confirm you’re selecting the correct disk, volume, or partition.
  4. Backup Data: Always back up important data before performing operations that modify partitions or volumes.
  5. Use clean Command: If a disk is not functioning correctly, use the clean command to remove all partitions and volumes from the disk.
  6. Format After Cleaning: After cleaning a disk, use the create partition primary and format fs=ntfs quick commands to create and format a new partition.
  7. Check for Logical Errors: Use Diskpart commands to fix logical errors on the disk.
  8. Disconnect External Drives: If multiple drives are connected, disconnect any external drives to avoid selecting the wrong one.
  9. Consult Diskpart Help: Use the help command within Diskpart to get detailed information about specific commands.
  10. Review Diskpart Logs: Check Diskpart logs for any error messages or warnings that can provide clues about what went wrong.

Regarding best practices, let me show you an example of creating a mirrored volume on my client computer using Diskpart.

  • First, I will add two additional 50 GB disks via Hyper-V to my machine.
  • Then, I will type ‘list disk‘.
List Disk now shows our 2 raw, unused disks to create the mirrored volume from
List Disk now shows our 2 raw, unused disks to create the mirrored volume from – Image Credit: Michael Reinders/Petri.com

We have Disks 2 and 3 each with 50 GB free. First:

  • Type ‘select disk 2’.
  • Type ‘convert dynamic’ to convert the disk type to Dynamic.
  • Now, we do the same for the 2nd disk (Disk 3).
  • ‘Select Disk 3’.
  • ‘Convert dynamic’.
  • Then, type ‘create volume mirror disk=2,3’.
Creating a mirrored volume with our 2 Dynamic disks
Creating a mirrored volume with our 2 Dynamic disks – Image Credit: Michael Reinders/Petri.com
  • When we ‘list volume‘, we see ‘Volume 5’ – unformatted, and Type = ‘mirror’.
  • Next, we’ll assign the drive letter ‘F’ by typing ‘assign letter=F
  • And finally format it with ‘format fs=ntfs quick label=Mirror.
Disk Management and File Explorer see the new mirrored volume correctly
Disk Management and File Explorer see the new mirrored volume correctly – Image Credit: Michael Reinders/Petri.com

Sweet! In Disk Management and File Explorer, we can see the new mirrored volume.

Thank you for reading my article on using Diskpart.

SHARE ARTICLE