diskpart Command Builder

Build diskpart scripts to list, clean, partition and format disks safely.

Advertisement

Build a diskpart script — and select the right disk before you run it

diskpart is the most destructive command-line tool shipped with Windows. There is no confirmation prompt, no undo, and no recycle bin. clean takes effect the instant you press Enter, and it acts on whichever disk you last selected — which is not necessarily the one you meant. This builder writes the script for you, and deliberately puts list disk at the top of every sequence so you have the chance to check.

Read that again before continuing: selecting the wrong disk number and running clean destroys the partition table of a disk you may still need. People do this to their backup drive, to a second data drive, and occasionally to the drive they are booted from. No warning appears first.

The verification step is the important part

Every destructive sequence this builder produces starts the same way:

diskpart
list disk

followed by a REM line telling you to confirm the disk by its size. REM is a genuine diskpart command — it is how diskpart scripts carry comments — so you can paste the whole block without the comment lines causing an error.

Confirm the target with two facts, not one:

  • Size. If you meant the 500 GB external and the row says 1863 GB, stop.
  • Detail. Run select disk 2 then detail disk. That prints the model, whether it is the boot disk, and the volumes and drive letters it contains. A drive letter you recognise is the clearest confirmation available. The builder does not emit detail disk for you — type it yourself, every time, before anything destructive.

Disk numbers are assigned at enumeration and are not stable. Unplug a USB drive, reboot, or add a disk, and the numbering can shift. A disk number you noted yesterday is not a disk number you can trust today. Disk 0 is usually the boot disk, but “usually” is doing real work in that sentence — check detail disk for the Boot Disk field rather than assuming.

clean versus clean all

These sound like the same command with more thoroughness. They are not remotely the same operation.

cleanclean all
What it writesWipes the partition table and volume metadataWrites zeros to every sector on the disk
Time takenEffectively instantHours on a large drive — it must write the whole surface
Is the data really gone?No. The file contents remain on the platters or flash; only the map is destroyed. Recovery software can often rebuild a great deal of itYes, for practical purposes — every sector has been overwritten
Right choice forRepartitioning a disk you are keeping; clearing a disk that will not accept a new layoutDisposing of, selling or returning a drive that held data you care about

The distinction matters in both directions. If you are repurposing a disk, clean all wastes hours for nothing. If you are handing a drive to someone else, clean gives you a false sense of security — the data is still there. The builder has a checkbox for this precisely because choosing wrongly is costly either way.

One more wrinkle for solid-state drives: overwriting every sector on an SSD is neither guaranteed to reach every physical cell nor kind to the drive’s endurance, because of wear levelling and over-provisioning. For SSD sanitisation, the manufacturer’s secure-erase utility or a BitLocker crypto-erase is the better route. clean all is a reasonable answer for spinning disks.

The tasks this builder writes

TaskScript it producesRisk
List disks & volumeslist disk, list volume, list partitionNone — read-only. Always start here
Clean a diskselect disk N, then clean or clean allDestroys the entire disk
Create partitionselect disk N, create partition primary, format fs=… quick, assign letter=…Formats what it creates
Format a volumelist volume, select volume N, format fs=… quickWipes that volume
Assign drive letterselect volume N, assign letter=…Low, but changing a letter breaks paths and shortcuts pointing at it
Convert GPT / MBRselect disk N, clean, convert gpt or convert mbrDestroys the entire disk — see below
Set partition activeselect disk N, list partition, select partition 1, activeBoot behaviour only, MBR disks only

Two of these emit a literal N that you must replace: the format and assign tasks say select volume N, because the volume number can only be read off your own list volume output. Pasting the script unedited will simply fail with an invalid-argument error rather than acting on the wrong volume — which is the safer failure, but it does mean you cannot run those two blind.

Converting between GPT and MBR erases the disk

This surprises people, so it is worth stating plainly. convert gpt and convert mbr only work on a disk with no partitions and no volumes. That is why the builder inserts clean before the conversion: without it, diskpart returns The specified disk is not convertible and nothing happens. With it, the disk is wiped and then converted.

If your actual goal is to convert a Windows installation from MBR to GPT so you can enable UEFI boot, diskpart is the wrong tool — mbr2gpt.exe, also built into Windows, does that conversion in place without destroying data. Use the diskpart route only for a disk whose contents you intend to lose.

Which style to pick for a fresh disk:

  • GPT for anything over 2 TB, for any UEFI boot disk, and as the default for new disks. MBR cannot address beyond 2 TB and is limited to four primary partitions.
  • MBR only when something specific requires it — legacy BIOS booting, an old imaging appliance, or a device that refuses to read GPT.

Choosing the file system

OptionUse it forLimits to know
fs=ntfsInternal Windows drives and any volume needing permissionsRead-only on macOS without third-party software
fs=exfatExternal drives shared between Windows and macOS, and large media cardsNo permissions and no journalling — more vulnerable to corruption from a yanked cable
fs=fat32Small removable media, and firmware or devices that only read FAT32Maximum file size 4 GB, and Windows will not create a FAT32 volume larger than 32 GB through diskpart

The builder appends quick to every format. A quick format writes new file-system structures without checking the surface for bad sectors; a full format reads every sector as it goes. Quick is right almost always. Drop the keyword when you suspect the drive is physically failing and want the format to surface that.

Failure modes and what they mean

  • “Access is denied” or diskpart will not start. It requires an elevated prompt. Right-click Command Prompt or Terminal and choose Run as administrator.
  • “There is no disk selected.” Every operation acts on the current selection, and the selection resets when diskpart exits. Run select disk N again.
  • “The selected disk is not a fixed MBR disk.” You ran active on a GPT disk. The active-partition flag is an MBR concept and has no meaning under GPT, where boot is handled by the EFI system partition.
  • “Virtual Disk Service error: the disk is currently in use.” Something has the volume open — an antivirus scan, a backup job, an open Explorer window, or a pagefile on that disk. Close it, or run diskpart from Windows Recovery Environment.
  • “The volume size is too big.” Almost always a FAT32 format over 32 GB. Use exFAT instead.
  • The disk shows no size and no style. Usually a drive that has failed to initialise or a cable or enclosure problem — not something diskpart can fix.

Before you run anything destructive

A short discipline that prevents nearly every disaster in this area: unplug every drive you are not working on. If the only external disk attached is the one you intend to wipe, a mis-typed disk number has far fewer places to land. Then run list disk, then select disk N, then detail disk, and only then the destructive line.

This builder runs entirely in your browser and only produces text. It has no access to your disks, cannot see your drive layout, and cannot verify that the disk number you typed is the one you meant. That verification is yours to do, and it is the only thing standing between a routine repartition and a data-loss incident.

Running these as a script file

diskpart accepts a script file, which is how these sequences get used in deployment and imaging work:

diskpart /s C:\scripts\prepare-disk.txt

The file contains the same lines the builder produces, one per line, without the leading diskpart. Everything runs unattended, and REM lines are ignored as comments. Add > C:\logs\diskpart.log to capture the output, because otherwise a failure mid-script leaves you with no record of which line stopped it.

This is also where the danger multiplies. A script has no pause at which you can look at list disk and change your mind — it selects a hard-coded disk number and acts. If you script anything destructive, script it against a machine whose disk layout you control completely, and put the list disk and detail disk output into the log so that after the fact you can prove what was attached at the time. For interactive troubleshooting, do not script it. Type the lines and look at the output between them.

The other place these commands turn up is Windows Recovery Environment, reached from a boot medium via Shift+F10 to get a command prompt. diskpart works there, and it is often the only way to touch a disk that Windows will not release while running. Be aware that drive letters in the recovery environment frequently differ from the ones the installed system uses, so C: may not be the volume you think it is — another reason to identify volumes by size and label with list volume rather than by letter.

Frequently Asked Questions

How do I clean a disk with diskpart?+

Open diskpart as Administrator, run list disk and confirm the target by its size, then select disk N and clean. The clean command removes all partitions and volume information. Use clean all to zero every sector for a full, irreversible erase, which is slower.

What is the difference between clean and format?+

clean operates on a whole disk and removes its entire partition layout, leaving it unallocated. format operates on a single selected volume and writes a fresh file system to it. clean wipes the structure of the disk, while format prepares one volume for use.

How do I convert a disk between GPT and MBR with diskpart?+

The disk must be empty first. Select it with select disk N, run clean to remove all partitions, then run convert gpt or convert mbr. Converting destroys existing data, so back up anything important before you start.

How do I avoid wiping the wrong disk in diskpart?+

Always run list disk before any destructive command and identify the target by its capacity, not just its number, because disk numbers can shift between reboots. The select then act model means every command hits the last selected disk, so confirm the selection each time.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.