How to use DiskPart – Clean, Format & Create Partitions (Command Prompt, CMD)

What We'll Learn:

Welcome!

This short guide is all about learning how to use the diskpart command from windows command prompt (cmd).

  • We are going to familiarize ourselves with some basic terminology related to the windows file system.
  • We are then going to learn how to completely erase/clean a drive using diskpart
  • And how to create, extend or delete partitions.

Lets get started!

DiskPart Basics - Understanding Some Terminology:

Before we can start using diskpart, we need to understand some basic terminology related to the way the windows file system is structured and labeled.

  • Disk: A disk is simply any storage media, it could be your internal hard disk, a solid state drive or a USB flash drive.
  • Partition: A disk is separated into several partitions. Think of partitions like containers within a drive.
  • Volume: A volume is a collection of one or many drives and partitions.

Now that we are familiar with the basics let’s start using diskpart.

Preparation - Select A Disk to operate on using DiskPart:

To start using diskpart we must first initialize it. To do so simply open a command prompt with administrator privileges and simply type “diskpart”.

DiskPart


Diskpart is now initialized and is ready to be used.

To complete an operation in one of our disks we need to tell diskpart which disk we want to operate on. To do so we must first list all the available disks in our computer.

To do so, simply type “List Disk”.

List Disk

All the available disks in your computer will be shown at once.


All we need to do now is select the appropriate disk. You can use the size of the disk as a reference.

Be very careful now, performing the wrong operation on the wrong disk can very easily delete all your data, so triple check the output of the list disk command and make sure you figure out the appropriate disk.

Afterwards, simply type “Select Disk” followed by the number of the drive you want to select.

Select Disk 1

The drive of your choice will be selected at once and you are now ready to start using diskpart.

How To Use Diskpart to Completely Erase/Clean A Drive:

Oftentimes you might need to completely erase or clean a drive, either because it’s not working correctly or because it’s not recognized by windows. Thankfully, doing so is quite easy, just follow the steps bellow.


Step 1)
Clean Disk – Completely wipe your Drive using Diskpart:

With our drive selected simply type the word “clean” in your command prompt to completely erase it.

Clean

Warning: All data and partitions on the selected drive will be deleted at once.


Step 2) Create Disk Partition – Create a partition using Diskpart:

Our newly cleaned drive now needs a partition. To create a partition simply type “Create Partition Primary” or “Create part prim” for short.

Create Partition Primary


Step 3) Format Disk – Format Your Entire Drive using Diskpart:

Finally, we need to format our drive. To format a drive, we need to use the “format” command followed by the type of file system we want our drive to have. Here is what that would look like:

Format fs=ntfs quick

The “Fs” option specifies the files system, usually either ntfs or fat32, and the “quick” option tells the command prompt to format the drive quickly.

And that’s it! Our drive has now been fully cleaned and should be working correctly.

Play Video

There's an easier way!

Learn the ins and outs of the windows command line with our windows command line course.

How To Use DiskPart to Create, Extend & Delete Partitions:

We can use the diskpart command to do several operations in the partitions of our selected drive. Let’s start with learning how to create a partition.

Creating a Partition – using Diskpart:

Just like before, to create a partition simply type “create partition primary” followed by the “size” option and the size you want your new partition to have in megabytes. If you do not specify a size all the available space will be used. For this example, lets create a 1GB partition. Here is what that would look like:

Create Partition Primary size=1000

Optionally you can assign a disk letter using the following command:

Assign Letter=D

Replace D with the drive letter of your choice.

Finally, we need to format our drive, we can do so simply by using the following command:

format fs=ntfs quick

Replace ntfs with the filesystem of your choice.

Extending Partitions – using Diskpart:

Apart from creating a partition we can use the diskpart command to extend an existing partition. To do so however make sure that contiguous free space is available on your drive.

If there is, we need to select a volume to extent.

Use the “List Volume” command to view all the volumes in the currently selected drive.

List volume

Now select the volume you want to extend by using the “Select Volume” command followed by the number of the appropriate volume.

Select Volume 0

Finally use the “Extend” command to extend the selected volume.

Extend

The diskpart command will automatically use all the available space on your disk.

Deleting Partitions – using Diskpart:

We can use the diskpart command to delete partitions within our selected disk.

To do so, we first need to select the partition we want to delete. Simply use the “list partition” command to view all the available partitions within your selected drive.

List Partition

To select the appropriate partition, use the “select partition” command followed by the number of the partition you want to delete.

Select Partition 0

Finally, to delete the selected partition use the delete partition command.

Delete Partition

Warning all the data within the specified partition will be completely wiped, so be careful!

And that is it! You now know how to create, extend and delta partitions using the diskpart command directly form the command prompt.

Summary:

  • Use the “List Disk” and “Select Disk” commands to select a disk within diskpart.
  • Use the “Clean”, “Create Partition Primary” and the “Format” commands to completely clean a drive.
  • Use the “Create Partition”, “Extend” and “Delete Partition” commands to create, extend and delete partitions accordingly.

That's It!

You now know how to perform a number of operations on your disks using the diskpart command directly from the windows command line.

If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.

Play Video
Dont Stop Learning!

Windows Command Line Course!

This course has everything you need to start learning about the windows command line along with batch scripting.

Read More:

Any Questions? Ask them Below:

Leave a Reply

Your email address will not be published.

Take Your Skills to the next level!
Become one of our beloved students by enrolling into one of our courses. Get started now!

WAIT UP!

Take A Look At Our Command Line Course!

Need Help?

There's an easier way!

Welcome

You are now officially on your way to becoming a genius!