TechBuzzPro

Diskpart Commands in Windows: How to Use Them Safely

· 5 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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.

  1. 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.
  2. Start Diskpart: In the black window, type diskpart and press Enter. You will see the prompt change to DISKPART>, indicating you are now inside the utility.
  3. List Your Disks: Type list disk and press Enter. This displays all physical drives connected to your computer, labeled as Disk 0, Disk 1, etc.
  4. 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.
  5. Manage Partitions:
    • To see existing partitions, type list partition and press Enter.
    • To focus on a specific partition, type select partition X (replace X with the number).
  6. Execute Common Commands: Depending on your goal, use one of the following:
    • To wipe the entire disk: Type clean and press Enter. Warning: This deletes every partition and all data on the selected disk.
    • To create a new partition: Type create partition primary and press Enter.
    • To format the partition: Type format fs=ntfs quick (for a standard Windows drive) or format 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.
  7. Exit Diskpart: Once finished, type exit and press Enter to return to the standard Command Prompt. Type exit again to close the window.

Common Mistakes

  • Selecting the Wrong Disk: This is the most dangerous error. If you run the clean command 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 the list disk output.
  • 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 select command. 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 partition is generally the standard path.

Tips

  • Use "Quick" Format: Always add the word quick to 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 help to see a full list of available commands, or type help [command] (e.g., help format) for specific instructions on that command.
  • Check Disk Status: Use detail disk after 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:

  1. "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 readonly and press Enter, then try your command again.
  2. "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.
  3. 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.
  4. Command hangs or freezes: If a format command hangs, the drive may have physical hardware failure (bad sectors). Try a full format (remove the quick keyword) 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.