DISKPART - CMD
Overview
DISKPART is a command-line disk partitioning utility included in Windows operating systems that allows users to manage their computer’s drives. This tool is vital for configuring and organizing hard disks, SSDs, USB drives, and other storage devices. It operates by accepting commands directly when run in a CMD prompt with administrative privileges and can be used for tasks ranging from formatting drives to creating and deleting partitions.
Syntax
To utilize DISKPART, run the DISKPART command, and then you can enter specific sub-commands directly inside the DISKPART environment. Here is the general approach to starting and using DISKPART:
DISKPART
Once inside the DISKPART utility, available commands include:
LIST DISK
SELECT DISK <disk number>
CLEAN
CREATE PARTITION PRIMARY SIZE=<size>
SELECT PARTITION <partition number>
FORMAT FS=<file system> QUICK
ASSIGN LETTER=<drive letter>
EXIT
Options/Flags
LIST DISK
– Lists all disk drives detected by the system.SELECT DISK <disk number>
– Selects a specific disk to focus subsequent commands on.CLEAN
– Erases all partition and volume formatting from the selected disk.CREATE PARTITION PRIMARY SIZE=<size>
– Creates a primary partition with a specified size (in MB).SELECT PARTITION <partition number>
– Selects a particular partition on the current disk.FORMAT FS=<file system> QUICK
– Formats the selected partition with a specified filesystem (e.g., NTFS, FAT32); theQUICK
option speeds up the formatting process by skipping the bad sector check.ASSIGN LETTER=<drive letter>
– Assigns a drive letter to the selected volume.EXIT
– Exits the DISKPART command line utility.
Examples
Example 1: Formatting a USB Drive
DISKPART
LIST DISK
SELECT DISK 2
CLEAN
CREATE PARTITION PRIMARY SIZE=1024
SELECT PARTITION 1
FORMAT FS=NTFS QUICK
ASSIGN LETTER=E
EXIT
Example 2: Deleting All Partitions on a Disk
DISKPART
LIST DISK
SELECT DISK 1
CLEAN
EXIT
Common Issues
- Disk Not Found: Ensure you select the correct disk number from
LIST DISK
. Using the wrong disk number can affect an unintended drive. - Permission Errors: Running DISKPART requires administrative privileges. Right-click on CMD and select “Run as administrator.”
- Data Loss: Commands like
CLEAN
will erase data. Always back up data before performing disk operations.
Integration
DISKPART can be integrated with scripts to automate setup processes, like preparing new machines. Below is a basic script example that formats a new disk:
@echo off
echo Selecting Disk 0
echo.
diskpart /s scriptfile.txt
echo Disk has been prepared
Where scriptfile.txt
contains:
SELECT DISK 0
CLEAN
CREATE PARTITION PRIMARY
FORMAT FS=NTFS LABEL="NewDrive" QUICK
ASSIGN LETTER=D
EXIT
Related Commands
- CHKDSK – Check the disk for errors and display a status report.
- FORMAT – Formats a disk for use with Windows.
- FSUTIL – Displays or configures the file system properties.
For more detailed information and documentation, you can visit the Microsoft official documentation page for DISKPART at Microsoft Docs.