Diskpart – Utility to Format and Clean your Computer

Diskpart is integrated into Windows since Windows 7 and is a utility that will help us manage all our disks. With its own command interpreter and thanks to its wide variety of options. we will be able to carry out all the necessary tasks to make changes to our PC’s disks, such as migrating the information to an SSD. In addition, we will leave you some examples of use so that making any changes will be much easier.

If we install a new disk drive on our PC, Diskpart will help us to prepare the new drive for use, we can also modify the existing ones or remove them from a disk that we already have installed on our PC. We simply have to run the utility and type some command lines.


To be able to use this utility, our Windows user must be Administrator or belong to the local administrator’s group. If this is not a problem, we can type in the search field diskpart to start the shell. To open the Windows search, we can press the Windows key + S or click on the magnifying glass and type it directly.

Once the command interpreter is open, we only have to type the command to perform the necessary action. If, for example, we write help, it will show us all the available commands. Next, we will tell you what each one is used for.

Functionalities of Diskpart

Diskpart keys/ command lines

Active :

This command applies only to the MBR system partitions. When it is executed, it marks the MBR partition that we have selected as an active partition. To run it, we previously select an MBR partition and simply type active at the command prompt.

Add :

With this command, we will be able to reflect the simple volume that we must select previously, on the disk specified as a parameter. For example, if we have disk 1 and partition 2 selected, we can mirror disk 2 to partition 2 of disk 1 simply by typing add disk 2.

Assign :

It allows us to assign a drive letter or a mount point to the volume that we have selected. We only have to write assign letter = t to assign the letter t to the volume that we have previously selected, if we do not write any drive letter or mount point, it will assign the next available drive letter.

Attach vdisk

Its function is to attach a virtual hard disk (VHD) so that it appears like a local disk drive. Previously we must have selected a virtual hard disk and we will associate it by writing attach vdisk, if we want to mount it as a read-only unit we can add the read-only parameter.

Attributes :

Shows us, sets, or deletes attributes of disks or volumes. For disks, we can use set to set the attribute, clear to clear the attribute and readonly to specify that it is read-only.

For volumes, we have the same set, clear and read-only. but in addition, hidden is added to specify that it is hidden, nodefaultdriveletter with this, we say that it does not receive a drive letter by default and shadowcopy to specify that it is a snapshot volume.

To see the attributes of a disk, just write attributes disk, if we want the disk to be read-only, we add set readonly.

  Create Icons to Customize Folders in Windows 10

Automount :

Enable or disable automount on a basic or dynamic volume. To enable it we will write automount enable, or automount disable to disable it.

Break :

It divides the selected volume into two simple volumes. To use it on disk 0 we must write break disk = 0.

Clean :

It will remove all the partition or volume formats from a disk that we have previously selected. We just run clean all and all the data on the disk will be erased.

Compact vdisk :

It allows us to reduce the size of a dynamically expanding virtual disk. These dynamic expansion disks increase in size as needed.

But do not reduce in size, taking up more physical space, when files are deleted. When we have already selected a dynamically expanding virtual disk.

We run compact vdisk to reduce its size. This command is only valid on Windows Server 2012 onwards.

Convert :

Converts dynamic disks into basic ones, it also converts basic disks into dynamic ones. It can convert MBR disk to GPT and its reverse operation, convert GPT disk to MBR. To perform the necessary operation we will write the convert command followed by basic or dynamic if we want to convert a dynamic disk into basic or a basic disk into dynamic, we will write convert and then GPT or MBR if what we want is to convert an MBR disk into GPT or a disk GPT in MBR.

Create :

It allows us to create partitions on disks, we can also create volumes on one or more disks or create a VHD virtual hard disk. To create a partition, the attributes can be efi, extended, logical, msr OR primary we will write create partition and the attribute followed by the size.

For example, if we want to create a 1 GB primary partition we write create partition primary size = 1000 . To create a volume we have the options of doing raid, simple, stripe or mirror , we must also write create volume simple size = 1000 disk = 2 to create a simple 1GB volume on disk 2, in the case of a raid we should indicate in disk = the number of disks to create the raid separated by commas, for example create volume raid size = 1000 disk = 1,2,3 to create a raid with those disks.

Delete :

It will allow us to delete a volume or a partition of a disk, it is also capable of eliminating a dynamic disk from the list of disks. To delete a previously selected disk, partition or volume we must write delete disk, partition or volume.

Detach vDisk :

It is used so that the virtual hard disk that we select as one more disk unit on our computer no longer appears. It’s as simple as typing detach vdisk.

Detail :

It will show us information about a disk, partition, volume or virtual hard disk, as we have selected. To show us the information we will write detail followed by disk, partition, volume or vdisk.

Exit :

It allows us to exit the command interpreter, just type it and press enter to close.

Expand vdisk

Expand vdisk expands the size of the virtual hard disk to the new size that we specify, to perform this task and increase the size of the disk, for example, to 2 GB we will write expand vdisk maximum = 2000.

Extend :

Extend allows you to extend a volume or partition with the available unallocated free space of any disk. We can specify the size to extend or use all the contiguous available space on the disk. If we want to extend all the available size on disk two, we write in the interpreter extend disk = 2 by not specifying size with size = n it will use all the contiguous space available on disk 2.

  Defragmenting the Hard Drive

Filesystems :

Shows information about the file system that we currently have of the volume that we have selected. We will only have to write filesystems when we have selected a volume. since it does not work with disks or partitions.

Format :

Format assigns a format to a disk to be able to use it with Windows systems. It also has several parameters to perform the correct format.

FS =we specify the type of format 
LABEL =to write the name of the label
QUICKperforms a quick format on the volume
COMPRESSIt is only valid on NTFS, it compresses all files created on the volume
OVERRIDEif necessary, unmount the file system to perform the format
NOWAITwill not show the percentage while formatting and can use other commands while

If for example we want to format with label in NTFS and fast we can write format fs = NTFS label = LABEL quick, remember that you must select the volume to be formatted before executing this command.

Checkout: Speed Up your Windows 10


It works with Windows Server 2012 and later, it is used to assign the GPT attribute to the active partition at that moment.

Help :

It gives us help on the Diskpart commands, as we gave as an example at the beginning, we write help in the interpreter and all the available commands will appear, to have help with a specific command, we write help command. For example, if we want help with format syntax, we type help format, and it will show us the information about this command.

Import :

We import a snapshot from a metadata file. These commands are used more in business settings and we won’t go into much detail.

Inactive :

We marks the selected system partition as inactive, this must be done on a disk with a master boot record or MBR. We just type inactive to make it work.

List :

it will show us a list with information about disks, partitions, volumes or virtual disks, according to the added parameter. To show this information, we write list followed by disk for the list of disks, partition for partitions, volume for a list of volumes and with vdisk we will see the list of virtual disks.

Merge vdisk :

Merge vdisk allows us to combine a secondary virtual hard disk with its corresponding primary virtual disk, adopting the corresponding modifications. This command is only available in the Server version of Windows from 2012.

Offline :

Changes the online status of a disc to offline mode, basically like ejecting a USB drive. We write offline disk or volume depending on whether we want to change a disk or volume to offline.

Online :

Online offers us the opposite of offline, offline disk changes to online status. As before, we write online disk or volume to change the state from offline to online a disk or volume that we have selected.

Recover :

Recover helps us to recover the disks from a damaged raid, it also resynchronizes the volumes that are mirrored or with parity data. We simply execute recover which will only work if we have selected a disk from a raid. Otherwise, it will tell us that the operation has been completed without performing any task.

  Linux Commands

Rem :

Add comments to a diskpart script. We write rem comment to specify, for example, what this script will do.

Remove :

Removes the drive letter or mount point from a volume. We can use the letter = a parameters to specify the drive letter to remove, mount = path and thus say which mount point we want to unmount, all to remove everything at once or dismount that can be used together with all or if they have previously been removed all letters and paths from the volume.


Repair helps to repair a damaged Raid-5 volume and allows you to replace the damaged Raid-5 volume with a properly functioning one. It only applies to Windows Server 2012 onwards.

Rescan :

Rescan searches for new disks that have been connected to the computer. We simply write rescan and it will immediately check for new connected units.

Retain :

Retain prepare a dynamic volume to use as a boot or system disk. This command works simply by executing retain at the shell, but in order to execute it, you need to select a dynamic simple volume.

San :

Sets the storage area network (SAN) policy for the operating system.

Select :

Select allows us to select the disk, partition, volume or virtual disk by typing select disk, partition, volume or vdisk respectively. It is necessary to correctly execute most of the commands, previously select the disk, partition, volume or virtual disk with which we want to work.

Desired =

Specifies the amount in MB that we want to reduce, if we do not specify the amount it will be reduced according to the maximum amount of free space left on that volume.

Minimum = 

Specifies the minimum number of MB to remove to reduce the volume.


Querymax gives us the maximum byte that can be removed, basically the remaining free space of that volume to get an idea of ​​how much we can reduce the volume.


Nowait allows us to return to the command interpreter before the operation ends, so while it is still in progress we can continue using the interpreter.


UniqueID allows us to show or change, of the disk we have selected, the identifier of the partition table (GUID) or the signature of the master boot record (MBR). If we want to see the identifier of the disk that we have selected, we must write uniqueid disk, to change it we will write uniqueid disk.

Format a Drive using Diskpart

These are all the commands available to perform tasks with diskpart, although some will only work if you are in a business environment, the rest can be useful if we want to make changes to a new disk or removable drive without the need for additional software, simply by typing some commands we will have the new unit ready to go.

Leave a Comment