DiskPart Command Simplified With Examples

Photo of author

By Victor Ashiedu

Published

This Itechguide teaches you all you need to know about DiskPart. If you ever wonder how on earth you will be able to understand this Windows disk management utility, it ends here!

The guide starts with a simplified definition of DiskPart. Furthermore, it offers an easy-to-understand explanation of the relationship between disks, volumes, and partitions.

You also get a full list of all the DiskPart commands with explanations of what they do. Finally, the guide has common everyday SysAdmin DiskPart examples.

This DiskPart Command guide contains a number of topics. To find the DiskPart Command help topic you need, expand “Browse Post Topics“ below, then click on the topic you need. However, if you are new to DiskPart, you can read through the whole guide. Reading through the entire guide takes approximately 27 minuites to complete. You can always bookmark the link and come back later!

What Is DiskPart?

What Is DiskPart

DiskPart is a Windows command-line tool that helps you manage drives on your computer. With this command-line tool, you can manage disks, volumes, partitions, and virtual hard disks.

As you will see shortly, there are so many DiskPart commands. However, there are two commands – LIST and SELECT – that come before any other command.

Specifically, before you use any other command to manage any object*, you MUST first LIST the object, then, SELECT the object. Once an object is selected, any other command you execute afterward will apply to the selected object.

And object* can be a disk, a volume, partition, or virtual hard disk. The principle of LIST, then SELECT applies to any of these types of objects.

Disks, Partitions, and Volumes Explained

Disks, Partitions, and Volumes Explained

I felt the need to add this section because these 3 “drive objects” are easily confused, but essential to understanding the concept discussed in this guide.

A disk is the primary object or “container” that can either house a partition or volume. In the screenshot below, there are 3 disks. To the right of each disk are partitions or volumes.

Whether a disk contains partitions or volumes depends on the storage scheme. If the disk is a Basic disk, it will contain partitions. However, if it is a Dynamic disk, it will contain Volumes.

To learn more about these concepts, read our guides – Dynamic Disk Explained, and Dynamic Disk vs Basic Disk. You may also benefit from our Windows 10 Disk Management guide.

I strongly believe that understanding these disk concepts will make it easier to understand the DiskPart commands shared in the remaining part of this guide.

Get Help With DiskPart Commands

Getting Help With DiskPart Commands

The beauty of Windows command utilities – or any other computing command utility – is their built-in help functions.

Showing you how to access the DiskPart command help function, is arguably more important than any other thing I will discuss in this guide – more like showing you how to fish!

First things first, you access DiskPart from Windows Command Prompt. I suspect that this is obvious but for the purpose of dotting the Ts and crossing the Is, I needed to mention it!

Most importantly, you MUST open Command Prompt as administrator. The simplified version of what is on the link – to open command prompt as administrator: enter cmd in Windows 10 search, then right-click Command Prompt. Finally, select Run as administrator.

Once you open the command prompt as administrator, type the DiskPart command and press the enter key on your keyboard.

DiskPart

How To List All DiskPart Commands

When the DiskPart command prompt opens, to list all available commands, type HELP. Then, press enter. A full list of all DiskPart Commands will be displayed – see the second screenshot below.

Some commands in the second screenshot are hidden
How To List All DiskPart Commands

How To Get Help With a Specific Command

As explained in the last sub-section, you can list all DiskPart Commands with HELP. Additionally, you can get more information about a specific command.

For example, if you want to learn what the LIST command does, type the command below and press enter.

HELP LIST

Here is the result of the HELP LIST command. It offers additional information.

From the screenshot above, the HELP LIST command explains the following:

LIST DISK – Display a list of disks
LIST PARTITION – Display a list of partitions on the selected disk
LIST VOLUME – Display a list of volumes
LIST VDISK – Displays a list of virtual disks

You can apply this knowledge to any other DiskPart Commands. To learn more about any of the commands discussed in the next section, simply enter HELP, followed by the command.

Full List Of DiskPart Commands

Full List Of DiskPart Commands

The table below is a comprehensive list and explanation of the DiskPart Commands.

S/NDiskPart CommandCommand Details
1RESCANScans the computer for new disks that may have been added to the computer. This is the only command that does not require LIST and SELECT as a pre-requisite command. Command: RESCAN
2LISTDisplays a list of the object – Disks, Partitions, Volumes, or virtual disks. Commands: LIST DISK, LIST VOLUME, LIST PARTITION, or LIST VDISK.
3SELECTShifts the command focus to a specific disk object. To shift command focus to a disk, type SELECT DISK <disk number>. Moreover, if you want to work on a specific partition, use SELECT PARTITION <partition number>. The same applies to volumes and vdisks.
4ONLINEApplies to disks and volumes. The ONLINE command is used to bring a disk or volume previously marked as offline
5OFFLINEPerforms the opposite of the ONLINE command
6DETAILApplies to all disk objects – DISKS, PARTITIONS, VOLUMES, and VDISKS. The DETAIL command displays the property of the object in focus.
7SANDisplays or sets the SAN policy for the operating system. You have to select the disk before using the SAN command.
8UNIQUEIDSets or displays the MBR signature or GPT identifier of a disk. Before you run the UNIQUEID, you MUST put a disk in focus with the SELECT command.
9RECOVERThe RECOVER command is only applicable to dynamic disks. The command operates on disks that are part of a pack.
10FILESYSTEMSDisplays information about the current file system for a selected volume. The command also displays the supported file systems for formatting the volume.
11CLEANThe CLEAN command deletes all partition of volume information from a selected disk – effectively marking the disk as “Unknown”. Use the CLEAN command with caution as it leads to data loss.
12MERGEApplies to VDISKs – merges a child disk with its parent disk
13FORMATFormats the specified volume for use in Windows Operating System. For a full list of the syntax and examples, use HELP FORMAT.
14COMPACTApplies to VDISKs – the COMPACT command attempts to reduce the physical size of the Virtual Disk file
15CONVERTUsed to convert a BASIC disk to DYNAMIC or vice versa. Also applies to convert GPT to MBR or vice versa.
16GPTUsed in conjunction with the CONVERT command
17MBRUsed in conjunction with the CONVERT command
18BASICUsed in conjunction with the CONVERT command
19DYNAMICUsed in conjunction with the CONVERT command
20EXTENDApplies to a volume or partition – extends (increases the size) of a volume or partition in focus using the free (unallocated) space on a disk.
21SHRINKPerforms the opposite of the EXTEND command.
22EXPANDApplies to VDISKs – expands a virtual disk to the maximum size available.
23ACTIVEUsed to mark an MBR partition as active
24INACTIVEPerforms the opposite of the ACTIVE command
25ASSIGNAssigns a drive letter or mounted folder pathname to the volume or partition with focus (selected volume or partition)
26ATTRIBUTESDisplays or manipulates the attributes of a disk or volume. Useful for removing the ReadOnly attribute that prevents you from formatting a disk – especially SD cards.
27CREATEUsed to create a VOLUME, PARTITION, or VDISK. You can create volumes on a Dynamic Disk, and create partitions on a Basic Disk.
28DELETEIf used on a disk, it deletes a missing disk from the disk list. It can also be used to delete a selected partition or volume.
29ATTACHApplicable to VDISKS – Attaches a virtual disk file
30DETACHPerforms the opposite of the ATTACH command
31REPAIRRepairs a selected RAID-5 volume by replacing a failed RAID-5 member with a specified dynamic disk
32ADDMirrors a selected simple volume to a specified disk. Effectively creates a mirror with 2 disks
33BREAKBreaks a selected mirrored volume into two simple volumes
34SETIDChanges the partition type field for a selected partition. Using this command to change the partition type may stop your Operating Syetm from starting-up. Only use if you know what you are doing.
35AUTOMOUNTEnables or disables the automount feature of basic volumes.
36RETAINUse only in Dynamic Volumes. Prepares an existing dynamic simple volume to be used as a boot or system volume.
37EXITExits the DiskPart command utility and returns to Command Prompt

DiskPart Examples

DiskPark Examples

In this section you will learn how to use DiskPart to perform common disk management tasks.

How To Use The CLEAN Command To Un-Initialize a Disk

One of the disk management tasks you can perform – although, it may be uncommon – is to Un-Initialize a disk. When you Initialize a disk, Windows removes the “Unknown, Not Initialize” status from the disk.

How To Use The CLEAR Command To Un-Initialize a Disk

However, there are some rare instances when you may need to un-Initialize a disk. One common scenario is if you need to transfer a disk used in a Windows PC to a macOS or Linux computer.

To use DiskPart to CLEAN a Windows disk for use in another Operating System, follow the steps below:

  1. Open Command Prompt as administrator. Then, open the DiskPart command – type DiskPart into command prompt and press enter key.
  2. Then, on the DiskPart command, enter the command below and press enter:
LIST DISK

The command displays all disks om your computer. Note the disk number of the disk you want to work on.

If you are not sure of the disk, use Disk Management (link opens in a new browser tab – shows you how to open Disk Management) to confirm the disk.

How To Use The CLEAR Command To Un-Initialize a Disk
  1. Next, select the disk with the SELECT DISK command. In this example, I want to select disk 2.
SELECT DISK 2
Replace 2 with your disk number
  1. Finally, with the disk selected, enter the CLEAN command and press enter.
The CLEAN command deletes all volumes and partitions from the disk. You will lose all the data on the disk. Proceed with caution.
CLEAN

When the CLEAN command is completed, if you look at Disk Management, the disk will be displayed as “Unknown, Not Initialize” – see the second screenshot below.

How To Initialize a Disk With the CONVERT Command

The DiskPart CONVERT Command performs the opposite of the CLEAN Command. If you insert a disk into your computer, before you use it you must Initialize the disk.

In the process of Initializing the disk, you select a disk partitioning style – MBR or GPT.

To initialize a disk with DiskPart, open DiskPart in a Command Prompt opened as administrator. Then, run the commands below in order:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
CONVERT MBR

The last command initializes the disk with the MBR partitioning scheme. To initialize a disk with the GPT partitioning scheme, replace MBR with GPT in the command.

When the last command is completed, the disk will no longer be listed as “Unknown, Not Initialize” – see the second screenshot below.

How To Initialize a Disk With the DISKPART CONVERT Command
How To Initialize a Disk With the DISKPART CONVERT Command

How To Use DiskPart ONLINE and OFFLINE Commands

The ONLINE and OFFLINE DiskPart commands are used to – you guessed it – take a disk online or offline! In this example, I will take disk 2 offline.

How To Use DiskPart ONLINE and OFFLINE Commands

Follow the steps below to take an Online disk, Offline:

  1. open DiskPart in a Command Prompt opened as administrator
  2. Then, run the following commands in order –
LIST DISK
SELECT DISK 2
Replace 2 with your disk number
OFFLINE

Here are the commands in DiskPart prompt. The second screenshot shows the disk status as offline.

On the contrary, if a disk is offline, you can make it Online by running the following commands:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
ONLINE

After running the ONLINE command, when you look at Disk Management, it will display the status of the disk as Online.

How To Use DiskPart ONLINE and OFFLINE Commands

How To Display The Properties Of An Object With The DETAIL Command

You can view the properties of DISK, PARTITION, VOLUME or VDISK (virtual disk) with the DETAIL. As usual you have to use the LIST and then the SELECT commands to list and make the object focus respectively.

Then, use the DETAIL command to display the properties of the disk object. To demonstrate how the DETAIL command works, I will view the properties of Disk 2 highlighted in the screenshot below:

How To Use DiskPart ONLINE and OFFLINE Commands

To display the properties of a disk, run the following commands:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
DETAIL DISK

Refer to the result of the DETAIL DISK command in the screenshot below. The command lists important information about the disk.

The information can be used for troubleshooting purposes. For instance, if you are trying to format the disk but unable to, the Read-only status may help.

If the disk is Read-only, Yes, you can change this attribute to No. Then, you will be able to format the disk. More on this in the ATTRIBUTES example later in this guide.

Moreover, there are other important properties displayed. For example, the type of disk is displayed. You also see whether the disk is a Pagefile, Hibernation File, or Crashdump Disk Disk.

These information may be useful for SysAdmins troubleshooting disk problems.

How To Use The FILESYSTEMS Command

As I mentioned in the “DiskPart Commands” section, you can use the FILESYSTEMS command to display the current file system in a Volume. As usual, you have to list and select the disk.

To display the current and supported file system for the selected volume, use the commands below, in order.

LIST VOLUME
SELECT VOLUME 6
Replace 6 with your volume number
FILESYSTEMS

As you can see in the screenshot below, the FILESYSTEMS command shows that Volume 6 (the selected volume) is formatted with the NTFS file system.

Additionally, the command confirms that you can format the volume with the FAT and FAT32 file systems.

How To Use The DiskPart FILESYSTEMS Command

How To Create or Delete Volumes and Partitions

DiskPart has 2 commands – CREATE and DELETE – used to create and delete partitions and volumes respectively. In this section, I will create a partition with all the “Unallocated” spaces in Disk 2.

Disk 2 is a Basic Disk so I can only create partitions on the disk. To be able to create volumes, a disk must be converted from a Basic Disk to a Dynamic Disk (link opens in a new browser tab).

To create a partition with the CREATE DiskPart command, run the commands below:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
CREATE PARTITION PRIMARY

The last command creates a primary partition on the Basic disk, using the whole available spaces on the disk. If you want to create a partition with a specific size, include the SIZE parameter.

The SIZE of the partition is specified in MB. In the example below, I created a 10 GB partition – so I specified the size as 10000
CREATE PARTITION PRIMARY SIZE=10000

Here are the commands. The second screenshot below shows that the partition has been created in the disk.

Moving on, if you already have a partition, you can use the DELETE PARTITION command to delete the command.

However, before you run the DELETE PARTITION command, you have to list the partition first, then select the partition you want to delete.

Here is the full list of the commands in order:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
LIST PARTITION
SELECT PARTITION 1
Replace 1 with your partition number.
DELETE PARTITION

Here are the commands in DiskPart…

How To Use The DiskPart FORMAT Command

After creating a partition or volume, you need to format the partition or volume and assign a drive letter before it becomes available for use. In this sub-section, you will learn how to use the FORMAT Command to format a volume or partition.

Following on from the ongoing example, I will format the single partition in disk 2. The partition is highlighted in the screenshot below.

This image has an empty alt attribute; its file name is image-525-1024x775.png

To format a partition, run the following commands in order…

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
LIST PARTITION
SELECT PARTITION 1
Replace 1 with your partition number.
FORMAT FS=NTFS QUICK

These are the DiskPart commands…

How To Use The DiskPart ASSIGN Command

The ASSIGN Command command is used to assign a drive letter to a partition or volume. As usual, the disk must be selected first, then the partition will be selected before you assign it a drive letter.

To assign a drive letter to a partition, run the following commands in order:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
LIST PARTITION
SELECT PARTITION 1
Replace 1 with your partition number.
ASSIGN

When you run the ASSIGN command without specifying a driver letter, DiskPath will assign the next available drive letter. However, you can specify a drive letter as shown in the command below:

ASSIGN LETTER=E
The problem with specifying a drive letter is that the specified drive letter may not be available – this will result in an error and the command will be unsuccessful.

To see the commands in action, see screenshot below.

How To Use The ATTRIBUTES Command

The DiskPart ATTRIBUTES Command can be used to fix a common real-life disk problem. Sometimes, if you try to format a USB disk, you may receive an error message indicating that “the disk is write-protected”.

If you receive this message, one known method of fixing the problem is to use the DiskPart ATTRIBUTES command to remove the read-only attribute. Once this attribute is removed, you will be able to format the drive.

Here are the steps to remove the “read-only” attribute of a disk and fix the “the disk is write-protected” message:

  1. Run the following diskpart commands:
LIST DISK
SELECT DISK 2
Replace 2 with your disk number

2. Finally, to remove the “read-only” attribute, enter this command and press the enter key.

ATTRIBUTES DISK CLEAR READONLY

So far, I have discussed how you can use the ATTRIBUTES command to remove the read-only attribute. However, there are instances when you may want to apply the read-only attribute to a disk.

One reason you may want to do this is to prevent formatting the disk accidentally. If you want to apply the read-only attribute, use the command below:

Before running the command below, run the LIST DISK and SELECT DISK commands.
ATTRIBUTES DISK SET READONLY

Once you execute this command on a disk, the disk will “lock” and cannot be formatted. To be able to format the drive, you MUST run the ATTRIBUTES DISK CLEAR READONLY command.

How To Use the SHRINK And EXTEND Commands

The SHRINK command is used to free up unallocated space from a volume or partition. One instance you may need to do this is to create a free space to install a dual-boot Operating System.

For instance, you can dual-boot Windows 7 with your existing Windows 10. Furthermore, you may also dual-boot Ubuntu with Windows 10.

To use the shrink command to free-up some spaces, run the following commands:

LIST DISK
SELECT DISK 2
Replace 2 with your disk number
LIST PARTITION
SELECT PARTITION 1
Replace 1 with your partition number.

Finally, use the command below to shrink the partition.

Specify the DESIRED and MINIMUM values in MB.

SHRINK DESIRED=30000 MINIMUM=10000

Alternatively, to free up maximum available, simply use the SHRINK command:

SHRINK

So far in this sub-section, I have been discussing the SHRINK command. On the other hand, the EXTEND command is used to add (EXTEND), a volume or partition with an existing “unallocated” space in the same disk.

To extend a volume or partition with all the available unallocated space on the disk, run all the commands we used in demonstrating the SHRINK command above. Then, use the command below:

EXTEND

You can also specify a size – here is a sample command:

EXTEND SIZE=500
Size is specified in MB.

Frequently Asked Questions

DiskPart Frequently Asked Questions

In this last section of this guide I will answer your commonly asked questions about DiskPart.

1. How Do I Use DiskPart?

Open a command prompt as administrator, enter DiskPart and press enter. To get a list of DiskPart commands, type HELP and press enter. You can also learn how to use a command by typing HELP followed by the DiskPart command.

2. What Does “DiskPart Clean” Do?

It removes all partition or volume information from the disk and changes the disk status to “Unknown, Not Initialized”. Effectively, “DiskPart Clean” makes a disk look like a new disk by wiping all data from the disk.

3. Does “DiskPart Clean” Remove MBR?

Yes, it does. The disk partitioning scheme (MBR or GPT) is set when you initialize a disk. When you run “DiskPart Clean”, you un-initialize the disk, and this includes removing all partitioning schemes.

4. Is MBR Faster Than GPT?

No., a disk with the newer GUID Partition Table (GPT) partitioning style is not faster than a disk partitioned with the older Master Boot Record (MBR). The only primary difference between the two portioning styles is that GPT is more robust and supports volumes bigger than 2 TB.

5. Does Windows 10 Use MBR or GPT?

Windows 10 can use either MBR or GPT disk partitioning schemes.

6. Is NTFS MBR or GPT?

NTFS is neither MBR nor GPT. NTFS is a different disk concept from MBR or GPT. While NTFS is a file system used when formatting a partition or volume, MBR or GPT defines the partitioning schemes used by the disk. Apart from formatting a volume or partition with the NTFS file system, you can also format it with the FAT or FAT 32 file systems.

7. What Happens If I Convert MBR to GPT?

The first notable thing that happens when you convert MBR to a GPT partitioning scheme is that you can have more than four partitions on one disk – a limitation of the MBR scheme. Additionally, GPT uses the new Unified Extensible Firmware Interface (UEFI) which is more secure than the older standard BIOS partition table used by MBR. Finally, unlike MBR, you can use GPT for larger disks – disks larger than 2 TB.

8. How Do I Know If My USB is UEFI Bootable?

Check whether the USB uses GPT or MBR portioning scheme. If GPT was selected when the USB was initialized, it will be UEFI Bootable. GPT is the only partitioning scheme that works with UEFI – MBR uses the older standard BIOS partition table.

9. How Do I Convert My Hard Drive to GPT?

If the disk is already Initialized and uses MBR, the only way to convert it to GPT is to un-Initialize the disk with DiskPart. Here are the steps:
1 – Open Command Prompt as administrator, then type DiskPart and press enter.
2 – On the DiskPart prompt, type LIST DISK, and press enter, and note the disk number of the disk you want to convert from MBR to GPT
3 – Then, enter SELECT DISK <disk_number> and press enter – replace <disk_number> with the number of the disk – from the LIST DISK command
4 Finally, enter CLEAR and press enter. All partitional tables will be removed from the disk

The last step is to open Disk Management. When you open Disk Management, it will display the disk as a new drive and prompt you to Initialize it. Select GPT as the new partitioning scheme. If, in the rare instance that Disk Management does not prompt you to Initialize the disk, right-click it and select Initialize Disk. Then, Select GPT as the new partitioning scheme.

10. Will I Lose Data If I Convert GPT to MBR?

Yes. If you use standard Windows tools – DiskPart and Disk Management you will lose the data in the drive. The reason you lose data is that the first step in the process of converting from GPT to MBR is to remove the partitioning scheme on the drive. This process destroys all data on the drive. However, you could use third-party tools like Partition Assistant. You may be able to convert from GPT to MBR with this tool without losing data.

I hope you found this DiskPart command guide helpful. If you found it helpful, kindly share your experience with our community at [discourse_topic_url].

However, if there is a DiskPart help you need but is not included in this guide, reply to this article’s topic at [discourse_topic_url]. Our dedicated team and other community members will respond back to you as soon as possible.

Finally, for more Windows command Itechguides, visit our PowerShell and CMD Explained page. You may also find our comprehensive Windows 10 Disk Management Guide very helpful.

We go the extra mile to deliver the highest quality content for our readers. Read our Content Writing, Content Review, and Anti-Plagiarism policies to learn more.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

If this article does not meet your expectations, kindly let us know. We have various ways you can get in touch with us:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

Leave a comment

Send this to a friend