How to use the command diskpart (with examples)
- Windows
- November 5, 2023
Diskpart is a command-line tool in Windows that allows users to manage disks, volumes, and partitions. It provides a set of commands that can be used to perform operations such as creating, formatting, and managing disks and volumes. This article will illustrate various use cases of the diskpart command.
Use Case 1: Running diskpart
Code:
diskpart
Motivation:
Running diskpart
by itself in an administrative command prompt allows users to enter the diskpart command-line interface. This is the starting point for using diskpart and provides an interactive environment to execute the subsequent commands.
Explanation:
diskpart
: This command is used to launch the diskpart tool.
Example Output:
Microsoft DiskPart version 10.0.19041.789
...
DISKPART>
Use Case 2: Listing all disks
Code:
list disk
Motivation:
The list disk
command is useful when you want to view a list of all the available disks on your system. This can be helpful when you need to identify the disks you want to perform operations on.
Explanation:
list disk
: This command lists all disks detected by diskpart on the system.
Example Output:
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 931 GB 0 B *
Disk 1 Online 1863 GB 0 B *
Disk 2 Online 4769 GB 1024 KB *
Use Case 3: Selecting a volume
Code:
select volume <volume number>
Motivation:
The select volume
command is used to choose a specific volume on a disk for further operations. By selecting a volume, you can narrow down the scope of the subsequent commands to work on a specific partition.
Explanation:
select volume
: This command selects a volume by its volume number.<volume number>
: Replace this with the number of the volume you want to select.
Example Output:
Volume 2 is the selected volume.
DISKPART>
Use Case 4: Assigning a drive letter to the selected volume
Code:
assign letter <drive letter>
Motivation:
When a volume is selected, the assign letter
command can be used to assign a drive letter to the selected volume. This allows you to access the volume using the assigned letter in File Explorer or other applications.
Explanation:
assign letter
: This command assigns a drive letter to the selected volume.<drive letter>
: Replace this with the desired letter you want to assign to the selected volume.
Example Output:
DiskPart successfully assigned the drive letter or mount point.
DISKPART>
Use Case 5: Creating a new partition
Code:
create partition primary
Motivation:
The create partition
command is used to create a new partition on a selected disk. This is useful when you need to divide a disk into multiple partitions for better organization and data management.
Explanation:
create partition
: This command creates a new partition on the selected disk.primary
: This parameter specifies that the new partition should be a primary partition.
Example Output:
DiskPart succeeded in creating the specified partition.
DISKPART>
Use Case 6: Activating the selected volume
Code:
active
Motivation:
The active
command is used to mark a volume as active. An active partition is required for the system to boot from that volume. This command is typically used on the system boot volume when managing multi-boot configurations.
Explanation:
active
: This command marks the selected volume as active.
Example Output:
The selected volume is now active.
DISKPART>
Use Case 7: Exiting diskpart
Code:
exit
Motivation:
Once you have completed the desired diskpart operations, the exit
command is used to exit the diskpart command-line interface. This returns you to the regular command prompt.
Explanation:
exit
: This command is used to exit the diskpart tool.
Example Output:
Leaving DiskPart...
C:\>
Conclusion:
The diskpart command-line tool provides a powerful set of commands for managing disks, volumes, and partitions in Windows. By understanding and utilizing the various use cases, users can efficiently perform disk-related operations to suit their needs.