For basic disk operations on Windows systems, administrators can use diskpart, a command-line utility that remains useful for many different drive-related jobs more than 20 years after it was released.
Microsoft included the free disk management tool in Windows starting in 1999 with the Windows 2000 operating system. Diskpart scans for newly added disks, but it can also create, delete and resize drive partitions, and assign or reassign drive letters. Diskpart also works with drive volumes, virtual hard disks and removable media such as USB flash drives.
Microsoft continues to develop diskpart, and the latest version of the utility features 38 commands. To use diskpart, you list the objects, such as disks or partitions, and then select the object to change it.
Diskpart use requires a basic understanding of Windows disk terminology. A basic disk is a storage device, such as hard drives, solid-state drives and USB flash drives, which you format with a Windows file system.
A basic disk can hold one or several partitions. A partition is a logical structure confined to a single disk.
A volume is a construct of the operating system that consists of one or more partitions that can span one or more disks.
You should be careful when using diskpart because there is no undo function if you select the wrong object. Also, once a command is entered, even a destructive one, diskpart does not ask for confirmation before it runs. For example, if you perform an errant diskpart delete partition operation, you must use another utility, such as third-party disk management program, to recover the data or use a backup image to restore the drive.
Follow these tips to avoid issues when using diskpart:
Using diskpart to partition your disk can help increase the I/O performance of hard disks newly added to a RAID array. The documentation for many server applications, such as Exchange Server, recommends using diskpart to create the primary or extended partitions. You can use a primary partition as the system partition; you can only use an extended partition for additional logical drive assignments.
The diskpart create command makes disk partitions, volumes on a single disk or multiple disks, and virtual hard disks.
For this and all following commands, you need to open the command prompt before you run diskpart. Type cmd from the run command window from the Windows search box or the run command dialog box that you open with the Windows+R key combination.
To create a partition:
When it comes to adding space to a partition or volume, this method is superior to configuring two disks. Dynamic disk extensions only concatenate the newly added space, meaning they merely add the disk space to the end of the original partition without restriping the data.
Concatenation isolates performance within each partition and does not offer fault tolerance when the partition is configured in a RAID array. Diskpart restripes your existing data. This is beneficial when the partition is set up in a RAID array, because the existing partition data spreads across all the drives in the array, rather than just adding new space to the end, like the Disk Management utility.
To extend a partition:
The delete command in diskpart removes dynamic disks, partitions, volumes and shadow copies. When you have multiple volumes on the disk or an unwanted partition, such as a recovery partition, this command will remove them and return them to unallocated space.
To delete a partition:
When using dynamic disks in Windows, you can create four volume types with diskpart: volume mirror, RAID-5 volume, simple volume and striped volume.
To create a simple volume:
When you have an entire disk to wipe clean, you can use the diskpart clean command to convert all the stored data into unallocated space. This operation deletes all data on the disk by writing zeros on each disk sector. Diskpart also removes all partition and volume information from the selected drive.
To clean a disk:
For maintenance work that requires a bootable USB flash drive, you can use diskpart to format the partition and set up the file system on the removable drive. Administrators can also use diskpart in both the Windows Preinstallation Environment and Windows Recovery Environment to correct disk problems or set up the machine for deployment.
With the diskpart /s switch, administrators can run scripts to automate tasks associated with setting up Windows machines, such as configuring the disks for multiple systems, adding a recovery partition or wiping all data from a disk to return it to a factory state.
Sample code from the Microsoft site gives examples of how to develop a text-based script file administrators can call from diskpart and run automatically. IT workers can run several diskpart scripts, but Microsoft recommends building in a delay of 15 seconds after a script runs to prevent issues.
For an in-depth tutorial on how to use diskpart for preparing a Windows 10 system for deployment, this blog post on the SearchEnterpriseDesktop site provides detailed instructions to use diskpart with a script.
20 Jul 2021