Managing the hard drive on your computer is not something that most PC users tend to get into. It’s more of a thing reserved for the techy type people or those who work on computers for a living. Regardless of your skill level, it’s always a good idea to know how to manage your hard drives in case you need to fix a problem or simply want to get some information about them.
Many Windows users like to use the built in Disk Management tool to manage their drives. This will work fine for most tasks and is fairly easy to use.
But for those who want a bit more control and prefer to use the command line to manage your hard disks, you can do that as well. In this article we will be showing you how to use the Windows DiskPart command to manage your hard drives.
To use the DiskPart command in Windows, you will need to open an administrative command prompt and then type in diskpart and press enter. You will then be presented with the DISKPART> prompt.
One of the first commands you will use is the list command. You will need to use one of the following words after the list though.
List disk
List partition
List volume
List vdisk (for virtual disks)
As you can see in the images below, you get specific information depending on which command you use.
When it comes time to working with a specific disk you will need to select that disk first using select <disk> and use the disk number from the list disk command.
Once you have a disk selected, then you can take specific actions on that disk. Here is a listing of the more common DiskPart commands.
/? or help:
- Displays information about the available commands and their usage.
/s <script>:
- Specifies a script file containing a sequence of DiskPart commands. This allows for automation of tasks.
/l or /list:
- Lists the disks and volumes on the computer. It provides information such as disk number, status, size, and free space.
/select <disk>:
- Selects the specified disk, making it the focus for subsequent DiskPart commands.
/online:
- Brings an offline disk online. This is useful for activating a disk that was previously set to an offline state.
/offline:
- Takes a disk offline. This is useful for safely removing a disk from the system.
/clean:
- Removes all partitions or volumes from the selected disk. This effectively wipes out all data on the disk.
/create partition primary [size=<n>]:
- Creates a primary partition on the selected disk. The optional size parameter allows specifying the partition size.
/format [fs=<filesystem>] [label=<label>] [unit=<size>] [quick]:
- Formats the selected partition. Options include specifying the filesystem, label, unit size, and performing a quick format.
/assign letter=<letter>:
- Assigns a drive letter to the selected partition.
/extend [size=<n>]:
- Extends the size of the selected volume. The optional size parameter allows specifying the amount by which to extend the volume.
/shrink [desired=<n>] [minimum=<n>]:
- Reduces the size of the selected volume. The optional desired parameter specifies the target size, and the optional minimum parameter specifies the minimum size.
/delete partition [override]:
- Deletes the selected partition. The optional override parameter is used to override protection on the system and OEM partitions.
/convert mbr | gpt:
- Converts the selected disk to either the Master Boot Record (MBR) or the GUID Partition Table (GPT) format.
/clean all:
- Performs a secure wipe of all partitions and volumes on the selected disk by zeroing out the data.
/attributes volume [set | clear] [hidden | readonly | nodefaultdriveletter | shadowcopy]:
- Sets or clears attributes on the selected volume, such as hiding it or marking it as read-only.
/exit:
- Exits DiskPart.
For additional training resources, check out our online training courses.