How to get started with the Windows command-line tool, DiskPart.
Partitioning a computer's hard disk and solid state drives can be a good way to keep operating system and applications separate and user data.
Doing this means that if something goes wrong with a hard drive or the file governing where different data is stored – a partition's index file – it will be easier to recover than if it was all stored on one drive partition. Partitioning drives also helps make backing up data easier and can allow for a reinstall of Windows to be carried out without reformatting all of the drive's data.
There are plenty of tools to enable disk partitioning in Windows, including Microsoft's own Disk Management utility.
However, one of the most prevalent and granular methods of cleaning, formatting, and partitioning hard drives is through the use of the DiskPart command tool.
What is DiskPart?
DiskPart stands for disk partition utility and is a command-line based tool for all versions of Windows and Windows Server, running on versions of the operating software later than Windows XP and Windows Server 2003. It is the successor to the older fdisk tool.
The tool essentially allows for more granular control of disk management, including the cleaning and formatting of USB flash drives, and the creation of partitions and assignment of disk drive letters.
Unlike Microsoft's Disk Management tool, DiskPart can be run without Windows starting up and offers explicit control over hard drive volumes and partitions, including surfacing hidden recovery partitions. This makes it a powerful tool and not one to be used without a degree of caution, as any formatting it does on a hard drive cannot be undone once actioned.
DiskPart's power also means it is a useful tool for fixing problems such as data corruption on USB flash drives and SD cards which a simple formatting in Windows cannot fix.
How to use DiskPart
If you have a healthy hard drive that you wish to partition, it is best to first backup the data on that drive to ensure you have a record of the data if something goes wrong when using DiskPart. Once that’s done, you can get started with DiskPart:
- Ensuring you have administrator access, in Windows 10 hit the Windows key and 'X' to bring up the Power User menu and then click on the Command Prompt. Or alternatively, type 'Command Prompt' into the Windows search bar and hit enter then click on the Command Prompt icon.
- This will serve up a window in which you can type command line prompts. In the box type in 'diskpart' and hit enter; this opens up another window and you're ready to use the DiskPart tool.
- Type in 'list disk' to get a view of the storage drives in and connected to your computer.
- Using the command 'select disk' followed by a number you can choose the disk you wish to carry out actions upon; for example, 'select disk 2' will mean any actions you type in will be carried out on the hard drive labelled 'Disk 2'.
From here you can carry out a suite of DiskPart commands, for example:
- The 'Extend' command will extend a disk's selected partition to any unused volume on the drive
- The 'Shrink' command will do the opposite
- 'Clear' will remove the configuration data or all information off the disk
- 'Create' command will allow for the creation of a new partition in a selected hard disk or flash drive.
When creating a new partition in a drive you will need to ensure you make it active and assign a letter to it using listed commands. To get these commands, simply type any letter after the 'DISKPART>' line and hit enter to be served up with a selection of compatible commands.
It’s worth getting familiar with the commands before diving into the utility, and to this end, Microsoft also offers a DiskPart command-line guide.
If you’re not comfortable using the command line and not familiar with hard disk formatting, you may find Windows’ Disk Management tool easier and safer to use.
But for experienced hands and IT administrators, DiskPart should prove to be a powerful hard drive management tool native to Windows.