Increasing the Size of the VHD File
With the help of the freely available VHD Resizer tool, you can expand the size of a VHD using it’s simple wizard interface. When opening VHD Resizer the wizard prompts you for the source VHD file to resize.
After selecting the source, set a destination VHD to a new file.
This new file will be an exact copy of the source, only a larger size.
Once selected, set the new size of the destination VHD file. This will be the capacity of the new VHD. Once set, start the resizing process.
Depending on the size of the source and destination file, this can take some time.
Repeat the process for any additional VHD files.
Resizing the Partition of the VHD Drive
After resizing the VHD file, the extra space is recognized by the respective Windows installation as an unallocated partition. In order to assign this extra space to the system drive, we have to link the new VHD file to an existing VHD file and resize it within the virtual machine.
In an existing VHD file, such as the source, link the new VHD file as a second hard disk. This is done through the the properties of the virtual machine.
Once you have the new VHD linked as a secondary drive, start the respective virtual machine.
When you look at the Disk Management, you can see the additional space is unallocated.
In order to resize the system drive on the new VHD file, you use the Windows tool, Diskpart.
Within Diskpart, set the disk (usually disk 1) and respective partition (usually there is only one) and then issue the ‘extend’ command.
After the extend command of Diskpart has run, the previously unallocated space has been combined with the system drive to form a single larger drive.
Once you have resized the new drive, shut down the virtual machine you used to resize the new drive and then remove the new VHD file as the secondary drive.
The new VHD file is ready to use as it’s own virtual machine, so create a new VM based on the newly created file.
Once created, boot up the new virtual machine.
The new VHD file will now have a single drive with the new space available to use as needed.
Conclusion
The ability to resize VHD files is tremendously useful. Since you can never predict what you may need in the future, you can build your VHD files with the size you know you need and then simply expand the size as needed.
Links
Download VHD Resizer from VM Toolkit (requires registration)
Microsoft documentation on Diskpart