Diskpart Commands in Windows: How to Use Them Safely
In this article
To use Diskpart in Windows, search for "cmd" in the Start menu, right-click Command Prompt and select "Run as administrator," then type diskpart and press Enter. Diskpart is a powerful command-line utility used to manage disks, partitions, and volumes, allowing you to perform tasks like formatting drives, deleting stubborn partitions, or converting disk styles (MBR to GPT) that the standard Disk Management GUI cannot always handle.
What You'll Need
- A PC running Windows.
- Administrator privileges on the account you are using.
- A backup of all important data on the target drive, as Diskpart commands can permanently erase data.
Step-by-Step
Because Diskpart targets specific disks and partitions, you must follow a "focus" hierarchy: you select the disk, then the partition, then apply the command. Labels and paths may vary slightly depending on your Windows version.
- Launch the Command Prompt: Click the Start button, type "cmd", right-click the Command Prompt result, and select "Run as administrator". This is required because disk modification requires system-level permissions.
- Start Diskpart: In the black window, type
diskpartand press Enter. You will see the prompt change toDISKPART>, indicating you are now inside the utility. - List Your Disks: Type
list diskand press Enter. This displays all physical drives connected to your computer, labeled as Disk 0, Disk 1, etc. - Select the Target Disk: Identify the disk number you want to modify (pay close attention to the size to ensure you pick the correct drive). Type
select disk X(replace X with your disk number, e.g.,select disk 1) and press Enter. You should see a message confirming the disk is selected. - Manage Partitions:
- To see existing partitions, type
list partitionand press Enter. - To focus on a specific partition, type
select partition X(replace X with the number).
- To see existing partitions, type
- Execute Common Commands: Depending on your goal, use one of the following:
- To wipe the entire disk: Type
cleanand press Enter. Warning: This deletes every partition and all data on the selected disk. - To create a new partition: Type
create partition primaryand press Enter. - To format the partition: Type
format fs=ntfs quick(for a standard Windows drive) orformat fs=fat32 quick(for USB drives/compatibility) and press Enter. - To assign a drive letter: Type
assign letter=Z(replace Z with any available letter) and press Enter.
- To wipe the entire disk: Type
- Exit Diskpart: Once finished, type
exitand press Enter to return to the standard Command Prompt. Typeexitagain to close the window.
Common Mistakes
- Selecting the Wrong Disk: This is the most dangerous error. If you run the
cleancommand on Disk 0 (usually your OS drive) instead of Disk 1 (your USB drive), you will wipe your operating system. Always double-check the disk size in thelist diskoutput. - Forgetting Administrator Mode: If you open the Command Prompt without "Run as administrator," Diskpart will return an "Access Denied" error when you try to list or modify disks.
- Skipping the Selection Step: You cannot format a partition or clean a disk without first using the
selectcommand. Diskpart will tell you there is no disk or partition selected. - Confusing Partition and Volume: While similar, partitions are physical divisions of a disk, while volumes are logical storage areas. For basic formatting,
select partitionis generally the standard path.
Tips
- Use "Quick" Format: Always add the word
quickto your format command (e.g.,format fs=ntfs quick). A full format checks for bad sectors and can take hours on large drives, whereas a quick format takes seconds. - The Help Command: If you are unsure of a command's syntax, type
helpto see a full list of available commands, or typehelp [command](e.g.,help format) for specific instructions on that command. - Check Disk Status: Use
detail diskafter selecting a disk to see more information, such as the connection type and read-only status.
Troubleshooting
If Diskpart does not behave as expected, try these steps in order:
- "The disk is write-protected": If you cannot clean or format a disk, it may be in read-only mode. After selecting the disk, type
attributes disk clear readonlyand press Enter, then try your command again. - "Virtual Disk Service error: The object is not found": This often happens if the drive was disconnected or the partition table is severely corrupted. Try unplugging the drive and plugging it back in, or restarting your PC.
- Disk not appearing in
list disk: Check the physical connection. If it is an external drive, try a different USB port. If it is an internal drive, ensure it is detected in the BIOS/UEFI settings. - Command hangs or freezes: If a format command hangs, the drive may have physical hardware failure (bad sectors). Try a full format (remove the
quickkeyword) to see if Windows can repair the sectors, though this is slow.
Frequently Asked Questions
What is the difference between clean and clean all?
The clean command removes the partition and volume information from the disk quickly. The clean all command writes zeros to every sector of the disk, which permanently erases data and makes recovery nearly impossible, but takes significantly longer.
Can Diskpart fix a "RAW" drive?
Yes. A RAW drive is one where the file system is corrupted or missing. By using select disk, clean, and then create partition primary followed by a format command, you can usually restore the drive to a usable state.
Can I use Diskpart to convert MBR to GPT?
Yes, but only by using the clean command first. Once the disk is completely wiped, you can type convert gpt or convert mbr to change the partition style.
Will Diskpart delete my files?
Commands like clean, format, and delete partition will erase all data on the targeted area. Always back up your files before using these specific commands.
Why can't I see my USB drive in Diskpart?
If the drive doesn't show up in list disk, it is usually a hardware issue, a dead USB port, or a failed controller on the drive itself. Try a different computer to rule out OS issues.