Monday, March 9, 2009

How-to Rezise Virtual Hard Disk (VHD)

One of the problems that I face is dealing with Virtual Machines that were created with no expansion in mind. I’m talking, of course, about virtual hard drives that are incorrectly sized. Before we get started, let me just say, the best rule of thumb…make your hard drives much larger than you think you’ll need, but make them expand dynamically. Yeah, you will have a hit on disk performance as it expands, but it’s negligible and much easier than having to try to resize.

Having said that, let’s get started. You will need a couple of things to get this done. First you will need the VHD Resizer tool, located here:
http://vmtoolkit.com/files/default.aspx. You will need to register, but totally worth it for the tool. Second, make sure you have your Virtual Environment along with 1-1/2 times more space than your current VHDD. This is because you will need to have a temporary second drive to get through this process (it’ll make sense in a bit).

Creating unallocated space

  1. Once you download the VHD Resizer tool, unzip it and run the installer (.msi)
  2. You should find a folder called vmToolKit in your start menu, select the vhdResizer application to get it started
  3. You should be prompted to select the VHD to resize, navigate to and select your VHD
  4. You should now be at the main application page of the VHD Resizer
  5. On the Destination Vhd, select Save As
  6. You should be able to create a folder on the popup screen, create one and call it New VHD
  7. Navigate to the New VHD folder and type in a name for your new VHD and select, Save
  8. Now, make sure you select Dynamic next to Type. This will create a new VHD the same size as the one you have now, except, it will also provision the additional space you will request in the next step
  9. Type in the New Size for your new drive. Because you have selected Dynamic above, your new HDD will be the same size but have additional unallocated space available. We’ll reallocate that space later. Be sure to put in a large enough number, like 120GB or something
  10. Click Resize to start (this will take some time…go get caffeine)

Getting your new space

  1. Start your Virtual PC Console
  2. Select your old VPC and open the configuration Settings
  3. Select Hard Disk 2 and then browse to the New VHD folder where you made the new VHD
  4. Select the new VHD and then select Open and then OK to close the Settings. NOTE: Now you should have the old VHD still attached as the primary drive and the new VHD (created above) attached as the secondary. This means that your Virtual Machine will boot as the old VHD being the primary and the new VHD being the secondary. It’s important that your new VHD is your secondary and not the bootable drive
  5. Start your Virtual Machine and login
  6. Start the Disk Management tool (right-click on My Computer and select Manage)
  7. Select Disk Management. At this point, if you get an error “Unable to Logical Disk Manager Service”, you will need to go to your services and locate the Local Disk Manager Service. Make sure it’s startup type is Automatic and that the service is Started. You will have to restart your Disk Management tool in order for this to take effect
  8. You should see two disks on this screen, Disk 0 (the old VHD) and Disk 1 (the new VHD). Disk 1 will also display the new amount of unallocated space
  9. Right click the active space on the new VHD and select Change Drive Letter and Paths…
  10. Click Add and then Assign the following drive letter. In my case, I’m selecting E:
  11. Open a command prompt (click Start->Run->Type CMD->Click OK)
  12. In the command prompt, type diskpart. You should see the prompt display DISKPART>
  13. Type in List Volume and hit Enter.
  14. From the list locate your new VHD by the Ltr which you assigned it. In my case, E
  15. Select your VHD to modify by typing in the command: Select Note: Volume will be the volume number to the left of the Ltr for your new VHD. In my case, E is next to Volume 1, so my syntax will be Select Volume 1. You should see the response; Volume 1 is the selected volume.
  16. Once selected, type in the command: Extend. This should take a minute with the response, DiskPart successfully extended the volume
  17. Go back to the Disk Management and you will now notice that your new VHD has all of its disk space allocated
  18. Shutdown your Virtual Computer
  19. Go back to your Virtual PC Console and back to the Settings
  20. Select Hard Disk 2 and select None to dismount it
  21. Now select Hard Disk 1 and browse to the new VHD, the one in the New VHD folder and select it, then click Open and then OK to select it as your new drive
  22. Start your virtual machine with the new VHD, this will have to go to a reboot as the system has to account for the new space

At this point, you are done. You have a new resized VHD that will dynamically grow as you use it and you can (if you want) delete the old VHD

2 comments:

  1. I did all the steps.
    When i restarted it says "A disk read error occured" Press Ctrl + Alt +Del to restart

    ReplyDelete
  2. Unable to connect to the download site, do you have a copy?

    ReplyDelete