How to format USB with DiskPart

Published: Oct 20, 2024

Last updated: Jan 27, 2025

Microsoft logo

Introduction

This tutorial is deigned to guide you through formatting a USB with DiskPart (Disk Partition command interpreter) via CMD (Command Prompt/Windows command line interface). Since this is through CLI, you'll look and feel extra cool!

You will need a USB flash drive. For this tutorial I used a SanDisk Ultra USB 3.0 Flash Drive, which can be found on Amazon.*

If you have ever flashed a disk using balenaEtcher, then you've probably run into this scenario before.
A screenshot of balenaEtcher at 69%

You flash a disk, use it to install an OS or whatever, then your USB is no longer recognized and/or accessible by Windows. Happens to me all the time... You may receive one (or all) of the following errors.
Location is not available, Windows error message
Windows can't format D, Windows error message
You need to format the disk in drive D: before you can use it, Windows error message
The disk is write protected, Windows error message
If you've seen any of the above errors, oof. Luckily, there's a way to fix this issue that's pretty quick, easy, and feels cool.

DiskPart

To get started, open CMD with admin priviliges. Enter the following commands (non-case sensitive):
DiskPart or DiskPart.exe
CMD window with 'diskpart' entered in

list disk


sel disk n (where n = disk number)


clean


create partition primary


sel partition 1


format quick



Additional notes:

DiskPart and DiskPart.exe are interchangeable.
Sel and select are interchangeable. Sel is shorter so why not?
The error messages referenced above are not exclusive to balenaEtcher; however, I personally experience them most frequently while flashing disks with the app.

For reference, this is what the full series of commands looks like:
DiskPart.exe running in command prompt (CMD)

* Amazon Associate notice! *
As an Amazon Associate I earn from qualifying purchases.

For this tutorial I used a SanDisk Ultra USB 3.0 Flash Drive, which can be found on Amazon.

References:

W3Schools
Random post on stack overflow
Mozilla Developer Network documentation. Shoutout to u/morewordsfastera on Reddit.