In last month's "Initializing Windows Disks with Diskpart," I showed you how Diskpart lets you view, select, create, and obtain detailed information about disk partitions. This month, we'll make those partitions useful by formatting them and giving them drive letters, then we'll see how to resize an existing partition to make it larger or smaller. (Learn more from "Diskpart Exerts VHD Control" and "Diskpart Goes Virtual").
In last month's example, we added an empty 24GB drive to a Windows system and created a 10GB partition by typing select disk 1 (which pointed Diskpart to the second physical hard disk) and create partition primary size=10240 (Diskpart prefers size information in megabytes). To complete this disk's setup, we need to give it a drive letter with the Assign command, then format it with the Format command.
The Assign command is simple: After you focus Diskpart on a partition or volume, you can give that partition/volume a drive letter (or change the existing drive letter) by typing
To set this partition's drive letter to T, for example, you would use
(If you don't specify a letter, Diskpart automatically assigns the next available letter to the partition.)
Now, you need to format the disk before you can use it. The syntax of Diskpart's Format command is a bit different from the syntax of the native Format command that Windows OSs have had since DOS 1.0. It has many options, but in most cases these options will do the trick:
format fs=<filesystemtype> \\[quick\\] \\[label=<label>\\] \\[unit=<clustersize>\\]
For example, you could format the partition quickly, allow Format to use the default cluster size, and label it "Data drive" by typing
format fs=ntfs label="Data drive" quick
That command gives you a working disk volume, but what if you want to change the volume's size? Since Windows Vista, Diskpart has been able to expand or shrink a partition/volume. Why shrink an existing volume? I've had to do it on a number of Vista and Windows Server 2008 systems because Windows' useful BitLocker drive-encryption tool lets you encrypt entire OS drives—but only if you have the foresight to leave 1.5GB of unused space on the disk where the OS resides. Because Vista/Server 2008 Setup is sadly BitLocker-unaware (a problem that Windows 7 and Server 2008 R2 don't share), many Vista/Server 2008 users carefully set up their systems, add BitLocker as a final touch, then find that Bitlocker won't work without a 1.5GB partition. Oops!
I've used Diskpart to help many people in this situation. The tool's Shrink command reduces an existing partition's size without damaging that partition. To shrink a partition/volume, I'd first select that partition or volume. For example, if I want to shrink the C drive on a system by 1.5GB, I would type list volume to determine the volume number that specifies the C drive (e.g., volume 2), select that volume by typing select volume 2, then type
shrink \\[desired=<sizeinmegabytes>\\] \\[querymax\\]
In my example, I need to clear 1,500MB of free space so that I can create the partition that will make BitLocker happy. If I just type shrink without any parameters, Diskpart computes the maximum space it can extract from C, then shrink C by that amount. But I don't want C minimized in size; I just want 1,500MB taken from it. So, I'll add the desired= parameter:
That command will give me the 1.5GB of space I need to set up that extra drive letter that Vista/Server 2008's Bitlocker needs. To see how much space you can snatch from an existing drive, you can type shrink querymax.
Consider the opposite situation. You have a volume on a drive that doesn't fill that drive, leaving some precious disk space unused. How do you expand the volume to use all remaining space? You can use Diskpart's Extend command:
As with Shrink, first shift Diskpart's focus to the volume/partition you want to extend. Then, either type simply extend, which causes Diskpart to expand the volume/partition as much as possible, or constrain the extension with the size= parameter:
Diskpart's ability to expand and shrink volumes is a welcome addition to the list of built-in Windows storage tools. Next month, we'll take a look at a new-to-Windows-7 storage capability: the ability to create and manipulate drives packaged in VHD format.