Problem
Format a disk or partition in Windows through command line
tl;dr
C:\> diskpart list disk select disk X clean create partition primary list partition select partition X format fs=ntfs quick
This will erase all data on the disk and create a single NTFS partition. X is the number of your disk or partition.
Solution
When dealing with Windows, normally the easiest way to do most disk management tasks is through its Disk Management utility. However, sometimes you may need to do it manually through the command line, such as when attempting to restore your system.
Diskpart
Diskpart is the utility used to do so. To start it, log in to command prompt (cmd.exe) and type Diskpart:
C:\> diskpart
To see your active disks:
list disk
You will see a table such as this:
DISKPART> list disk Disk ### Status Size Free Dyn Gpt -------- ------------- ------- -------- --- --- Disk 0 Online 465 GB 0 B Disk 1 Online 111 GB 0 B
If you want to work on Disk 0, for example, then you have to select it:
select disk 0
Then you can see what partitions exist on it via list partition. It will show a table similar to list disk above.
list partition
Select the partition you need:
select partition 1
To format it:
format fs=ntfs quick
Format Arguments
Add the following after format:
fs=FILESYSTEM_TYPE - filesystem, i.e. ntfs, fat32. Example:
format fs=ntfs
quick - quick format; writes new address table but does not erase any data. Example:
format quick
Create new partition
If there are no partitions on disk, you have to create one manually:
select disk 1 clean create partition primary select partition 1
clean erases all formatting on the disk, such as partitions or filesystems.
- Updated