Advertisements

Archive

Archive for July, 2009

Converting Hyper-V VHD hard disk files from dynamic to fixed, while at the same time shrinking the size of the VHD files

July 12, 2009 Leave a comment
  • System Notes: Dell PowerEdge 2950, Windows 2008 Server Standard x64

After attending a Hyper-V seminar recently, I learned that the recommended setup for any production server includes using a fixed size for any VHD file (as opposed to dynamic; see this link). I had originally set up all of my virtual servers with dynamic disks, in an effort to save space. I also specified much larger drive sizes than I would have otherwise needed. The VHD files in question needed to be converted to fixed format, and several of them needed to be cut in half in size.

I did several searches on this problem, and tested out a few tools that were supposed to allow conversion between dynamic and fixed VHD formats, as well as allowing size changes. Alas, they would only allow an increase in size, and not a decrease. So I ultimately came up with my own solution, using the partition management features of BootItNG and the DriveImage XML imaging program to accomplish what I needed. Here are the steps involved:

  1. Boot the virtual server to a BootItNG ISO.
  2. Use the BootItNG “Work with Partitions” option to do a non-destructive resize the partition to the desired size. When complete, shut down the virtual server.
  3. From the Hyper-V settings for the virtual server, create a new fixed-size VHD file and attach it as a secondary drive.
  4. Boot the virtual server, and chkdsk should run on your resized primary drive. Allow it to complete.
  5. Using the Windows disk management tools, partition and format the new fixed-size VHD secondary drive.
  6. Shut down the virtual server. Now you will be booting into whatever method you want for launching DriveImage XML. I use a BartPE boot disk, but there are several ways to accomplish this. Once you have DriveImage XML up and running, use the Drive To Drive option to duplicate the dynamic VHD onto the new fixed VHD.
  7. Shut down the virtual server and use the Hyper-V settings to remove the primary dynamic VHD drive and the secondary fixed VHD. Attach the new fixed VHD as the primary drive.
  8. Boot into the BootItNG ISO with the new primary fixed VHD attached.
  9. Use the BootItNG “Work with Partitions” option to set the partition in the new primary fixed VHD as active. If you don’t do this, when you attempt to boot the virtual server with the new fixed VHD, you will get the “Boot failure. Reboot and select proper boot device” error message and it will not boot.
  10. Shut down and then restart the virtual server. Assuming everything has worked correctly to this point, you should be prompted by your Windows installation to restart after you have logged in and it has added the details for the new primary fixed VHD.

Additional Notes:
One problem I ran into with DriveImage XML is that it cannot copy an old partition into a new partition that is smaller than the older one. Hence the need for using the partition management features of BootItNG to reduce the size of a dynamic VHD first, before imaging it. Make sure the new size is just slightly smaller than the size of your new fixed VHD, or you will run into this problem. DriveImage XML is smart enough to add any extra space in the partition when it writes the copy to the new fixed VHD. I had originally tried to use the Gparted partition management software (version 0.4.5-3; available here), but could not get it to see more than 127 GB of a disk under Hyper-V. I believe Symantec Ghost supports writing to smaller size partitions without needing to resize the partition first, but I do not have it available and cannot verify this.

Advertisements
Categories: Hyper-V, resize, VHD