How to expand a VHD disk

NB, MAR 2009: It was brought to my attention (thanks Fernando) that utilities like VHDResizer ( https://vmtoolkit.com/files/default.aspx ) may do the job in a simpler way. I did not check myself.

 

 I was working on a Virtual PC 2007 virtual machine with a dynamically expanding disk of a maximum of 16 Gb.

This disk was the C: system drive on the virtual machine and I was running out of virtual space (I had enough space on the hardware host disk).

A dynamically expanding disk can only grow to its predefined maximum size. The name comes from the fact that if you store 10Mb in a 16Gb dynamically expanding disk, vhd file size will only be ~10 Mb. You'll find much more at https://support.microsoft.com/kb/825092/en-us

So the virtual guest machine had a 15.5 Gb system drive for a maximum of 16Gb.

Here is what worked for me.

Let's call C.vhd the file of the 15.5 Gb C: drive.

  1. shut down the guest virtual machine
  2. Create thru the Virtual Disk Wizard a new dynamically expanding disk with a max size of 100 Gb => this creates Cbis.vhd with an initial size of a few Kb.
  3. close Virtual PC 2007
  4. use VHDMount (installed it on my Vista machine from the Virtual Server 2005 SP1 installation) to issue the following commands
    (if prompted to format a disk, don't do it, if X: or Y: drives don't get created, don't worry)
    1. vhdmount /m /f C.vhd X
    2. vhdmount /m /f CBis.vhd Y
  5. go to Disk Management (Computer, Manage, Disk Management) on the real Vista machine
    1. assign X: to the disk corresponding to C.vhd if it's not already done
    2. format the disk corresponding to CBis.vhd. NTFS, quick formatting is OK
    3. assign Y: to the disk corresponding to Cbis.vhd if it's not already done
  6. Copy all the files from X: to Y:
    1. robocopy X:\ Y:\ /E /COPYALL /R:5
    2. Fix any remaining copy issues (for instance ACL not authorizing administrators group to read)
  7. go to Disk Management (Computer, Manage, Disk Management) on the real Vista machine
    1. Mark Y: partition as active
  8. Unmount X: and Y:
    1. vhdmount /u All
  9. Change the virtual machine .vmc file (with notepad) and replace C.vhd by Cbis.vhd
  10. Restart virtual machine

Then you can delete C.vhd and keep CBis.vhd.