SEARCH

How-To Geek

How to Resize a Microsoft Virtual Hard Drive (VHD) File

When you create a Microsoft Virtual Hard Drive either through Virtual PC or Virtual Server, you have to specify the maximum size of the file up front. While you can set the VHD to be a fixed or dynamically sized file, the total size the VHD is determined at the time you create it. Over time, however, you may want to increase the total size of the VHD file as requirements for the system change to allow more space for installed programs and data files.

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.

image

After selecting the source, set a destination VHD to a new file.

image

This new file will be an exact copy of the source, only a larger size.

image

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.

image

Depending on the size of the source and destination file, this can take some time.

image

Repeat the process for any additional VHD files.

image

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.

image

image

image

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.

image

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.

image

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.

image

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.

image

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.

image

Once created, boot up the new virtual machine.

image

The new VHD file will now have a single drive with the new space available to use as needed.

image

image

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

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 07/26/10

Comments (17)

  1. chess

    wow that seem like a lot of step but i know this feeling to rezise an VM HD. to bad acronis works half the time

  2. Alder

    Great, simple and to the point

  3. Nice Post

  4. Bill

    I followed the instructions for my Windows 2000 server VHD, but in My Computer on the server it still shows 5gb capacity, even though computer management shows the correct 8gb new size. What gives?

  5. AL

    Can’t say just how grateful I am for this article. Thank alot!

  6. TD

    How about decreasing the size of VHD file?
    Thanks

  7. Jason Faulkner

    @TD – I don’t think it can be done outside of some highly advanced/low level partition manipulation.
    As a result, make your VHD files small initially and then expand as needed.

  8. Whit Chenault

    Great!!! Had to do a VM on my PC at work and set the original size to small. Excellent instructions.

  9. Robert Brown

    I need help and advice. The first time I tried this my new VM drive will not boot. Windows Boot Manager reports that \windows\system32\winload.exe could not be loaded because it is missing or corrupt. The error code is 0xc000000e. It recommends a repair install. What has caused this, and should I expect the possibility of corrupted contents every time I have to use this utility? Should I proceed with the repair install, or will copying the original winload.exe file to the new vhd?

  10. Jason Faulkner

    @Robert Brown – I have seen similar errors when copying/duplicating VHD files.
    I am assuming you are getting this error on the newly resized VHD file in which case the solution which has worked for me is to first boot up the original VHD OS (the one you want to resize) and run a full disk defrag. After that completes, try resizing the VHD.

  11. Robert Brown

    I used the repair install option, which reported what looked like a partition UID not found. Whatever the problem was the repair corrected it in less than a second and the vm rebooted just fine.

  12. Derk

    @ Robert Faulkner: When following the instruction, which are very clear btw, when starting the vpc with the resized disk i get the error:
    A disk read error occurred
    Press Ctrl-Alt_Del to restart
    Restarting does not help but gives the same error

  13. Jason Faulkner

    @Derk – Try defragging the source VM (boot into it and run a defrag from within the VM) and then try your resize again.

  14. Richard L

    With a Windows 7 virtual, when I got to the part of extending, the second disk was shown as offline by disk manager due to a signature conflict. I was able to boot up the resized vhd as disk 1 straight away and didn’t have to use the diskpart utility as the disk manager had an extend option via right clicking the healthy disk (maybe the same for Vista too?)

  15. Royston Shufflebotham

    Turns out you *can* shrink VHD files fairly easily. You do need to play with the partitions a bit, but only to the same extent as when you do that when increasing the size of a VHD.

    Let’s say we’ve got a 20Gb partition with 10Gb used, in our VHD, and we want to reduce that to a 15Gb VHD file. VhdResizer won’t let us reduce the VHD below 20Gb as there’s a partition across that whole 20Gb. If you go into Disk Management and shrink the partition size to 15Gb, you can then use VhdResizer to drop the VHD size (to 15Gb but no less).

  16. Michael Chan

    I followed the instructions and I received the same error message like Derk had: “A disk read error occurred, Press Ctrl-Alt_Del to restart” and it won’t boot!!

    I think the tutorial missed one important step, which is the disk geometry has changed, and need to rebuild the boot sector in order for it to boot again. This may be a problem from upsizing from 4G below to more, like mine.

    I fixed the above boot issue after rebuilding the NTFS boot sector using Testdisk, a free tool. Hope this help.

  17. Jordon

    I have followed everything mention in this article, but for some reason my new vhd is unable to boot.

    Yes i have defragment and tried to resize still i am receiving error.

    Error: The selected entry cannot be loaded because the application is missing or corrupt.

Enter Your Email Here to Get Access for Free:

Go check your email!