How To Clean A Disk With Diskpart
If you need to manage disks, partitions, and volume on your Windows machine, you have to learn how to use Diskpart. Diskpart is a disk management program to manage disks, partitions, and volumes in Windows right from the command line.
In this tutorial, you will learn how to shrink, extend and delete volumes, and manage unallocated space using Diskpart.
Let's hit it!
Prerequisites
If you'd like to follow along with any demos in this tutorial, be sure you have the following:
- Windows 7+ – All demos in this tutorial will use Windows 10, but everything should still work for older Windows versions.
- A local user account account with administrator privileges to manage Windows storage.
Accessing Diskpart
Diskpart, unlike many other command-line utilities, is interactive. Instead of repeatedly typing the command diskpart
over and over again, you instead run it once to be brought into an interactive session.
To open up the Diskpart shell, open Windows PowerShell as administrator.
Cmd.exe will also work, but since PowerShell is the successor to the cmd.exe, the tutorial will use PowerShell.
In PowerShell, open a Diskpart session by typing diskpart
. You can tell you're in a diskpart session from the new DISKPART> prompt, as shown below.

If you need to exit Diskpart, type exit
.
Selecting a Disk
This tutorial consists of many sections which have one thing in common, selecting a disk. To prevent from explaining how to do this in each section, be sure you know how to select a disk when the tutorial mentions it.
Since you probably have multiple disks on your Windows system, one of the first tasks you will perform is selecting which disk you want to work with. To do that, within the Diskpart session, tell Diskpart to list all of the available disks.
list disk
The list disk
command will then return all of the disks that Windows currently sees. Then, select a disk providing the disk number. For example, the command below is selecting a disk number 0
.
select disk 0
When Diskparts selects the disk, it will return a message shown below that the disk is now selected and return you to the Diskpart prompt. You're now ready to begin managing the partitions and volumes on that disk.

Selecting a Volume
Similarly to selecting a disk, this tutorial will require you to also select a volume with Diskpart. In the sections below, when the tutorial tells you to select a volume, be sure you know this means.
The same principle of selecting a disk applies to selecting volumes; list the volumes and select the volume number you'd like to work with.

Shrinking a Volume
Now that we have the basics out of the way let's now get down to actually doing something useful with Diskpart! First up is shrinking a volume on a disk.
Shrinking a volume turns unused space from the selected volume into unallocated space. Unallocated space is an inactive space or space that does not belong to any partition.
If you're following along, be sure you have a disk that has some unused space with an unformatted volume or one formatted as NTFS (see Creating and Formatting a Volume). Also, ensure the partition isn't an Original Equipment Manufacturer (OEM) partition, Extensible Firmware Interface (EFI) system partition, or recovery partition. This tutorial will use Volume 2 labeled as C.
- Open Diskpart.
2. Select a disk with some unused space.
3. Next, either find a volume using list volume
or run the detail disk
command to bring back disk information along with volumes on the disk. The Volume 2
below is a great candidate for shrinking because it's formatted as NTFS.

4. Select the volume to shrink and then determine the maximum amount of space the volume can be shrunk (shrink querymax
).
This tutorial's example volume can be shrunk by 14GB, as shown below.

5. Now, define the amount of space to shrink by typing shrink desired=#
, replacing # with the preferred amount in megabytes, as shown below.
10240
megabytes is equal to 10GB.
Since applications might be accessing the volume simultaneously and consuming space, run the shrink
command below specifying the minimum
parameter. The minimum
parameter is a fallback in case the desired
value isn't possible.
shrink desired=10240 minimum=8192
You can see below that Diskpart shrunk the selected volume by 10GB.

6. Once you shrink a volume, that space becomes unallocated. To confirm the unallocated space, list the disks again with list disk
. Below, you'll see the unallocated space is under the Free column.

Creating a Partition
As previously mentioned, unallocated space does not belong to a partition. To actually use that space, you must create a partition from it.
To create a new volume from unallocated space:
- Open Diskpart.
2. List all available disks with list disk
to see which disk has unallocated space you can turn into a separate volume and select that disk.
You can see below that disk 0 has 10GB of free space created by shrinking the volume from the previous section.

3. Now, create an active partition on the selected disk by using the create partition
command below. The below example will create a 10GB partition.
create partition primary size=10240

If you plan to install an operating system on your newly created partition, make the partition bootable using the
active
parameter.
Creating a Volume/Formatting a Partition
Once you have a partition, it's then time to format that partition which creates a volume to begin using the space in that storage.
When you create a partition with Diskpart, Diskpart automatically sets focus on the newly created partition. To see this, run the list partition
command. For example, you can see below Partition 4
is currently selected, indicated by the asterisk (*
) next to the partition number.

1. To create a volume with Diskpart, first determine which file systems the partition supports by running the filesystems
command. You can see below that the currently selected partition (Partition 4 in this case) supports NTFS, FAT32, and REFS.
A file system manages how files are named, stored, and retrieved from storage that lets you identify each file apart from one another.

2. Next, perform a quick (quick
) format on the partition as NTFS (fs=NTFS
) and give the volume a label (label="Backup"
). Replace the filesystem with whatever file system you'd like as long as the disk supports it, and choose your own label.
By default, Diskpart holds control of the session until the format is complete. Use the
nowait
parameter to immediately return control to the console while the format is running.
format fs=NTFS label="Backup" quick

3. Now, optionally assign the F drive letter to the volume you just created with assign
command and see your newly created volume with the new drive letter.
assign letter=F list volume

Extending a Volume
If you have some unallocated space on a drive next to a volume and are running out of space on a volume, you can extend that volume with Diskpart. Extending a volume is the opposite of shrinking a volume.
To extend a volume:
- Open Diskpart.
2. Find the disk with a volume you'd like to extend with list disk
to see if any of the disks in the system has enough unallocated space to use.
If you don't have enough unallocated space to extend, you may skip this whole section and clean up your disk to get additional space.
Next, select the disk with unallocated space next to it. This tutorial will use disk 0.

3. Find the volume to extend by running detail disk
for listing all volumes with list volume
. The tutorial will use Volume 2, as shown below.

4. Next, select the volume to extend and extend the volume with the extend
command. In the example below, volume 2 will be extended to 10GB.
If extending is successful, you'd now enjoy 10GB of additional space on the volume!

Deleting a Partition and Volume
If you have multiple volumes or partitions on your computer, you can remove them to "convert" them into unallocated space. If you're trying to free up space on a single-volume drive, though, you're out of luck.
To be safe, be sure you have all data backed up on the volume you're deleting.
Deleting a volume or partition is nearly identical in Diskpart consisting of the same routine you've learned throughout these sections.
1. Select the disk with select
that contains the partition or volume to delete.
2. List the partition or volume with list
.
list partition list volume
3. Select the partition or volume.
select partition # list partition #
4. Deleting the partition or volume with delete
delete volume delete partition


Cleaning an Entire Disk
If you have a disk with nothing of use stored on it and want to go with the nuclear approach, use Diskpart to turn a disk into unallocated with the clean
command.
Cleaning a disk erases everything inside the selected disk and cannot be undone. If the disk is inaccessible and has important files in the disk, give Windows File Recovery Tool a try to recover files after cleaning the entire disk.
To clean an entire disk, select the disk you'd like to clean and simply run clean
.

If you intend to create another partition from a cleaned disk, run the
create partition primary
command without thesize
parameter (See Creating a Volume/Formatting a Partition).
Conclusion
In this tutorial, you've learned using Diskpart to create partitions, extend, delete and shrink volumes, as well as clean an entire disk. Diskpart comes in handy and lets you freely control partitions and volumes on disks.
The next time you manage partitions on your disks, would you turn to Diskpart like you did today?
How To Clean A Disk With Diskpart
Source: https://adamtheautomator.com/diskpart/
Posted by: hubbardtheigners.blogspot.com
0 Response to "How To Clean A Disk With Diskpart"
Post a Comment