DiskPart is a utility built into Windows that lets you manage the partitions on storage devices such as hard drives, SSDs, USB flash drives, memory cards and external drives.
Commands and programs are for logical errors; if important files are at risk, first see how hard drive recovery works in a lab.
Although it comes with every Windows computer, not everyone knows how to use it correctly or why it matters so much.
That’s why we have put together this complete guide to DiskPart commands. By the end, you will know how to use it, which precautions to take and which commands you are most likely to need.
Read on for the most important things you need to know!
What is DiskPart?
DiskPart is a command-line disk partitioning utility.
The successor to fdisk, DiskPart works on Windows and Windows Server, from Windows XP and Windows Server 2003 onwards, including Windows 7, 8, 10 and 11 and Windows Server 2008 through 2022.
DiskPart can be used to manage hard drive partitions, to wipe and format USB flash drives, and to create, delete and extend partitions.
In short, DiskPart is the command-line counterpart of Disk Management, but it is more powerful because it can do things that Disk Management cannot, such as deleting protected recovery partitions or changing partition attributes.
Most changes made with DiskPart also take effect immediately, without restarting the computer. DiskPart runs in the Command Prompt.
On its website, Microsoft explains a few key concepts for using DiskPart, which we summarize below.
Setting the focus
Here, “focus” means the object you have selected: a disk, partition or volume. Commands always act on the object that has the focus, and only one object can have it at a time.
Bear in mind that the focus can also change automatically, without you selecting anything. For example, when you create a new partition, the focus moves to that new partition.
Syntax
Syntax is the way each command must be written, together with its parameters (which we cover next), to manage disks and partitions.
In programming languages, syntax is the set of rules that define how statements must be written.
For example, the syntax “clean [all]” is used to wipe the selected disk: it removes the partition table and the formatting information.
Parameters
Parameters are the values you add to a command to tell the interpreter exactly what it should do.
Going back to the previous example, in “clean [all]” the parameter is “all”. Without it, clean removes the partition and volume information from the selected disk; with clean all, every sector of the disk is also overwritten with zeros, and the data is destroyed for good.
Microsoft’s website has a full list of DiskPart commands. It’s worth a look!
What precautions should you take?
If you are planning to use DiskPart, remember that it changes the partitions and the internal structures of storage devices (internal and external hard drives, SSDs and USB flash drives).
That’s why you should use DiskPart commands with great care: once a command has run, there is no undo.
In other words, a single mistake can wipe out the files and folders stored on the drive.
So always double-check your commands, and the selected disk, before running them.
Also, DiskPart is not a recovery tool: every command writes to the disk. If you were thinking of using it to recover data or whole partitions, stop using the drive and leave the job to specialists like us at Bot.
That way, the recovery is carried out safely, without the risk of making the damage worse or losing your data for good.
How do you use DiskPart?
DiskPart is useful when you need to repartition a disk, format, create or resize a partition, or fix the partitioning of a disk after a Windows boot failure.
But, as with any operation involving important data, you must back up your data before running any DiskPart command.
Remember: DiskPart has to run with administrator rights.
You can open DiskPart in two ways:
- Type “diskpart” in the Windows search box, right-click DiskPart in the results and select “Run as administrator”;
- Press the Windows key and “R” at the same time, type “diskpart” in the “Run” box and confirm the User Account Control prompt.
Once DiskPart is open, you first list the objects and then select the one you want to work on, which gives it the focus.
From then on, every DiskPart command you type acts on that object.
How do you use DiskPart in CMD?
CMD is simply the Command Prompt, so the procedure is very similar:
- Search for “CMD” or “Command Prompt” in Windows search and run it as administrator;
- Click “Yes” when the User Account Control window appears;
- Type the command
diskpartand press Enter; - To list the physical disks, run the
list diskcommand.
From there, you can run the commands you need, but be careful: mistakes in DiskPart affect the disks and the data on them directly. If you are not familiar with the utility, it is best not to use it.
Main DiskPart commands
You can list the available objects with the list disk, list volume and list partition commands.
list disk and list volume show all the disks and volumes on the computer, whereas list partition only shows the partitions on the disk you have selected.
You then select the object with the select command followed by its number, for example select volume 2 or select disk 1.
Remember: once you select an object, the focus stays on it until you select a different one.
Some DiskPart commands change the focus automatically. For example, when you create a new partition, the focus moves to that new partition.
Finally, don’t forget to press Enter after each command.
Here are some of the main DiskPart commands:
list disk/volume
- Shows summary information about the disks/volumes on the computer.
list partition
- Shows information about each partition on the selected disk.
select disk/partition/volume
- Gives the focus to a specific disk/partition/volume.
detail disk/partition/volume
- Shows detailed information about the selected disk/partition/volume.
create partition primary/logical
- Creates a new primary/logical partition.
delete disk/partition/volume
- Deletes the selected disk/partition/volume (
delete diskonly removes a missing dynamic disk). Whatever is on a deleted partition or volume becomes inaccessible.
convert basic/dynamic/mbr/gpt
- Converts the selected disk between basic and dynamic, or between MBR and GPT. Converting between MBR and GPT with DiskPart requires an empty disk, so it means wiping it first.
assign
- Assigns a drive letter or mount point to the selected volume.
clean
- Removes the partition and volume information from the selected disk; with
clean all, it also overwrites every sector with zeros.
format
- Formats the selected volume or partition, erasing its contents.
active
- Marks the selected partition as active (boot partition on MBR disks).
How do you format a disk with DiskPart?
Formatting a disk or partition with DiskPart is simple, but you must be absolutely sure you want to do it: once the process is complete, there is no going back and the data on it will be lost.
So, if the disk still holds data you need, don’t format it: talk to a data recovery specialist first.
With that in mind, here are the steps:
- First, follow the steps in the section “How do you use DiskPart in CMD?” up to the
list diskcommand; - Identify the disk you want to format by its size, type
select disk X(replace X with the disk number) and press Enter. Double-check it: selecting the wrong disk will erase it; - Type
clean, press Enter and wait for the disk to be wiped; - Then type
create partition primaryand press Enter; - Finally, format the partition by typing
format fs=ntfs quick, pressing Enter and waiting for the format to finish.
Important: NTFS is the usual file system for Windows hard drives. Choose the one that suits your device: for a USB flash drive, for example, use FAT32 (fs=fat32), or exFAT (fs=exfat) if you need to store files larger than 4 GB.
To finish, type assign to give the volume a drive letter and press Enter. That’s it: the drive is formatted!
Read next
Conclusion
As you have seen, DiskPart commands are useful for partitioning internal or external disks. They are not difficult to use, but you must be very careful not to make mistakes.
So, if you are thinking of using DiskPart to fix a problem with your disk or to recover data, consider a safer option: leave your device in the hands of specialists.
At Bot Data Recovery, we are an experienced team and can help you recover your files safely, quickly and efficiently.
For your convenience, Bot offers free collection of the device from your address (islands not included), or you can drop it off in person at one of our reception points in Lisbon, Coimbra, Porto and Braga. We then diagnose it free of charge and send you a quote, with a standard turnaround of up to 48 hours.
Trust your data to people who know what they are doing. Talk to our specialists and get all your questions answered before you put your data at risk.
