Thursday 19 March 2009

Increase the size of your Microsoft Virtual PC hard disk

So you have a virtual PC disk with 20 Gb C drive on it and after a few installs you decide to install Visual Studio service pack 1, and it tells you it needs 4Gb to do it...

So you need to increase the size of your vhd, and you need to do it on the system volume, heres how;

  1. Download VHDResizer from here
  2. Following these instructions from "Murnic" on this thread didnt work, on entering EXTEND, not sure on the exact wording now, but it was along the lines of cant extend this volume.

The easiest way to do this (as long as you have enough hard drive space) is to extend your existing VHD using VHD Expander which gives you two VHD files. The newly extended file will take the name of your existing VHD. You might want to Defragment, Precompact, and Compact your VHD prior to extending your VHD.

In Virtual PC 2007 go to Settings.

  • Select your OLD VHD as Hard Disk 1
  • Select your newly extended VHD as Hard Disk 2
  • Boot your VM
  • Open an Command Prompt
  • Run diskpart
  • From DISKPART>
    - Execute LIST VOLUME
    - Select your new VHD volume by executing SELECT VOLUME where is your new VHD most likely 2
    - Execute EXTEND
    - You should see a success message. If not you may have to recreate your extended VHD due to an error in the process.
  • Quit Diskpart.exe by typing EXIT
  • Shut Down the VM
  • Remove both VHD files from the Hard Disks list
  • Add your newly extended VHD as Hard Disk 1
  • Boot your VM.
  • You will get a Windows Newly Added Hardware message after a short time.
  • Reboot the VM when prompted
  • Start using your newly extended VHD!

Here is Microsoft's information on extending volumes using Diskpart.exe: http://support.microsoft.com/kb/325590


So I went back to these instructions from 'AutoSponge' at the start of the same thread,

  1. Mount the image

    C:\>Program Files\Microsoft Virtual Server\Vhdmount>vhdmount /m “C:Documents and Settings\All Users\Documents\Shared Virtual Machines\\.vhd”

    Start diskpart

    C:\>Program Files\Microsoft Virtual Server\Vhdmount>diskpart

    Expand the partition

    DISKPART>list disk

    DISKPART>select disk 3 -----check the number in the list

    DISKPART>list part

    DISKPART>select part 1 -----check the number in the list

    DISKPART>extend

    DISKPART>list part -----check the new size

    DISKPART>exit

    Dismount and save changes

    C:\>Program Files\Microsoft Virtual Server\Vhdmount>vhdmount /u /c “C:Documents and Settings\All Users\Documents\Shared Virtual Machines\\.vhd”

You can get download Microsoft Virtual Server here.
You can do a custom install and only select VHDMount

Some more information using VHDMount

Using VHDMount with Windows XP -
It is not possible to use '/m' (Mount), you can only use '/p' (Plug in).

The reason for this is that VHDMount uses VDS (the Virtual Disk Service) to assign a disk letter to the virtual hard disk after it is mounted, but VDS is only included in Windows Server 2003 and later. This is not too big of an issue though, as unlike Windows Server 2003, Windows XP will automatically mount the virtual hard disk when it is plugged in. This means that the only functionality you lose on Windows XP is the ability to specify exactly which drive letter should be used.


5 comments:

Paul Rowland said...

Content copied to Stackoverflow question - http://stackoverflow.com/questions/28946/expanding-virtual-disk

Shaun Edwards said...

Excellent, I've been looking for a tool to do this and you've provided a step by step guide.

Thanks Paul.

Aman said...

When i try to run DiskPart.exe on VPC, it show the error "disk management services could not complete the operation "

Please help me to solve this

Paul Rowland said...

@Aman

I tried to this again a couple of months ago and ran into a few problems, so I went back to VHD resizer which worked perfectly.

Have a look here - http://serverfault.com/questions/6139/how-do-i-change-the-size-of-a-vhd

New Comer said...

Yes! it worked perfectly.