How to Use the ‘diskpart’ Command for Advanced Partition Management

The Danger of the Command Line

When a USB flash drive gets corrupted, or a new 4TB hard drive refuses to show up in Windows Explorer, most users open the graphical “Disk Management” utility. However, the graphical utility is notoriously limited. It often refuses to delete hidden recovery partitions, OEM partitions, or drives formatted by Linux (like ext4 or swap).

When the graphical interface fails, you must use the ultimate Windows storage tool: diskpart.

diskpart is a low-level, command-line partition manager built directly into Windows. It bypasses the graphical safety rails, allowing you to forcefully wipe, format, and restructure any drive connected to the system.

CRITICAL WARNING: diskpart has no “undo” button. If you select the wrong disk and type the clean command, you will instantly and permanently erase your entire C: drive. Proceed with extreme caution.

Launching Diskpart

Because it requires low-level hardware access, you must run it as an Administrator.

  1. Click the Start button, type cmd, right-click Command Prompt, and select Run as administrator.
  2. Type diskpart and press Enter.
  3. The prompt will change from C:\> to DISKPART>. You are now inside the utility.

Step 1: Identifying the Target Drive

Before you do anything, you must locate the drive you want to fix.

list disk

This will output a table of all physical drives connected to the computer, labeled as Disk 0, Disk 1, Disk 2, etc.

Look at the “Size” column very carefully. If your main Windows drive is 1TB, and the corrupted USB drive you want to wipe is 16GB, ensure you identify the 16GB drive. Let’s assume the USB drive is Disk 2.

Step 2: Selecting the Target

You must explicitly tell diskpart to focus its crosshairs on Disk 2.

select disk 2

The console will confirm: “Disk 2 is now the selected disk.”

Double-check your selection by typing list disk again. The selected disk will now have an asterisk (*) next to it.

Step 3: The “Clean” Command (The Nuclear Option)

If the drive has stubborn OEM partitions or corrupted data that the graphical utility cannot remove, the clean command will obliterate the entire partition table, returning the drive to a completely unallocated, factory-blank state.

clean

This executes instantly. The drive is now blank.

Step 4: Rebuilding the Drive

A blank drive is useless to Windows; it must be partitioned and formatted before you can save files to it.

First, create a new primary partition that spans the entire drive:

create partition primary

Next, select the partition you just created:

select partition 1

Now, format the partition with a file system. For a USB drive, exFAT is the best choice (compatible with Windows and Mac). For an internal Windows drive, use NTFS. The quick flag tells it not to physically scan every single sector, saving hours of time.

format fs=exfat quick

Finally, assign the drive a letter (like D: or E:) so it appears in Windows Explorer.

assign

Conclusion

Type exit to leave the utility.

The diskpart command is the definitive tool for resolving severe storage corruption in Windows. While its lack of safety features demands respect, its ability to bypass graphical restrictions makes it an essential utility for IT professionals dealing with stubborn, unmountable, or corrupted hardware.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.