The `diskpart` command in Command Prompt allows users to manage disks, partitions, and volumes efficiently using a set of specific commands. Here's an example of how to list all disks on your system:
diskpart
list disk
Understanding Diskpart in CMD
What is Diskpart?
Diskpart is a powerful disk partitioning tool that allows users to manage disks, partitions, and volumes from the command line. Unlike graphical disk management interfaces, Diskpart provides a more advanced, text-based alternative, offering robust functionality for both seasoned IT professionals and tech-savvy users.
Launching Diskpart
To access Diskpart via CMD, follow these steps:
- Press Windows + R to open the Run dialog.
- Type `cmd` and hit Enter.
- In the Command Prompt, type `diskpart`, then press Enter.
You will see a pop-up message requesting permission to run Diskpart. Click Yes, and the Diskpart prompt will open, indicating that you're ready to input commands.

Diskpart Command Basics
Navigating Diskpart
Upon launching Diskpart, you can explore the available commands. It’s crucial to familiarize yourself with basic commands to navigate effectively:
list disk
This command displays all disks connected to your system, each represented by a disk number, size, and status.
Understanding CMD Diskpart Syntax
The general syntax for Diskpart commands usually follows this format:
command [parameters]
This structure is critical to correctly executing commands. Always ensure you input parameters, such as disk numbers or partition sizes, accurately to avoid errors.

Key Diskpart Commands
List and Select
Listing Disks
To view all attached disks, use:
list disk
This command provides vital information on each disk, such as size and whether it has available space for partitioning.
Selecting a Disk
Once you've identified the disk you want to manipulate, select it using:
select disk [number]
For example, if you wish to select the first disk, your command would be:
select disk 0
This command sets the context for subsequent commands, meaning that any changes will affect the selected disk.
Creating and Managing Partitions
Creating a New Partition
To create a primary partition, your command should look like:
create partition primary size=[size in MB]
For instance, to create a partition of 5000 MB, enter:
create partition primary size=5000
This command allocates space on the selected disk, turning it into a usable partition.
Deleting a Partition
To remove a partition, ensure you are careful with this command, as it may result in data loss:
delete partition
Before executing, always double-check that you have selected the correct partition.
Formatting a Partition
Once you’ve created a partition, it’s essential to format it to make it usable. Use the following command:
format fs=ntfs
You can adjust the file system type by replacing `ntfs` with `exfat` or another format as required. Proper formatting is crucial for ensuring your system recognizes and utilizes the partition correctly.
Changing Partition Attributes
Setting a Partition as Active
To designate a partition as active (typically required for bootable partitions), you will use:
active
This command marks the selected partition as the bootable one, which is essential when setting up an operating system.
Removing a Drive Letter
To remove a drive letter from a partition, this command will suffice:
remove letter=[drive letter]
For example, to remove drive letter E, enter:
remove letter=E
This command can help in managing drive visibility and accessibility on your system.

Advanced Diskpart Commands
Expanding and Shrinking Partitions
Shrinking a Partition
If you need to free up space, you can shrink a partition with:
shrink desired=[size in MB]
For instance, to reduce the size by 2048 MB, enter:
shrink desired=2048
Expanding a Partition
To reverse this and expand a partition, use:
extend size=[size in MB]
For example, if you want to expand by 3000 MB, the command will be:
extend size=3000
This capability is helpful when reallocating storage space as needed.
Cleaning Disks
Cleaning a Disk
To remove all partitions and data from a disk thoroughly, you can use the following command:
clean
This command is powerful and will erase everything on the selected disk, so always ensure you have backups before proceeding with this.

Practical Examples of Diskpart in Action
Setting Up a New Hard Drive
When setting up a new hard drive, you would typically follow these Diskpart commands:
- List the current disks to identify the new one:
list disk
- Select the new disk:
select disk [disk number]
- Create a primary partition:
create partition primary size=[size in MB]
- Format the new partition:
format fs=ntfs
This sequence of commands allows for a smooth setup of a new hard drive, enabling it for use immediately.
Partition Recovery Using Diskpart
Diskpart can also assist in recovering partitions. To view existing partitions on a selected disk:
list partition
Once you identify the partition you want to recover, you can select it and assign a new drive letter using:
select partition [number]
assign letter=[letter]
This brings the partition back into play, allowing access to its contents once more.

Troubleshooting Common Diskpart Issues
Common Errors with Diskpart Commands
While using Diskpart, you might encounter error messages such as “The volume is in use” or “Access is denied.” These often indicate that the command requires administrative privileges or that the partition is currently being utilized by a running process. Always ensure you run CMD as an Administrator to mitigate these issues.
Backup and Risk Management
Before engaging in any Diskpart commands, prioritize data backup. As many operations can lead to irreversible data loss, developing a consistent backup strategy is essential. Utilize external hard drives or cloud-based solutions to safeguard your files.

Conclusion
CMD Diskpart commands are an invaluable tool for managing disk partitions effectively and efficiently. By understanding how to navigate this command-line utility, you can perform complex operations quickly while gaining greater control over your storage solutions. As you continue to explore and practice using Diskpart, you will enhance your skills and confidence in managing disk drives while minimizing risks associated with data loss or corruption.