Showing posts with label virtual hard disk. Show all posts
Showing posts with label virtual hard disk. Show all posts

Thursday, June 25, 2009

Converting Hyper-V VHDs

I recently was assigned the task of rebuilding our Team Foundation Server with TFS 2010 for many reasons. One of those is because the old one has a VHD that is consuming far more resources than it should be (it's a 100 gigabyte vhd and only 8 gigabytes are in use). I seemed to recall somewhere that Hyper-V could "compact" a virtual hard drive, but I couldn't remember where. After doing a bit of searching around Hyper-V, I found what I needed.

Here's a few facts about this before getting started.
First, shrinking a hard drive only applies to Dynamically sizing disks. Since these do no shrink on their own (there's a lot of reasons why) but only grow, they might need to be compacted later to free up host space. It only reduces the .vhd file size by shrinking the 'shell' (if you will) to take up the drive space that is not being used by the guest OS.

In my situation, I was dealing with a drive that was not dynamically sizing but was static. If the vhd is static, the Compact button will not show up when you go to edit the drive.
In my case, I did not have to compact the drive. As I said, a drive cannot be compacted unless it is dynamic. Since mine was static, I converted it to dynamic to regain the compacting functionality but because of the way the conversion process works, it automatically 'compacts' the .vhd. My original static .vhd was 100 gigabytes. The output was 15.5 gigabytes.

Though I did not have to compact my .vhd because the conversion process did it for me, I'm going to put the instructions on how to compact the .vhd anyways.

For starters, the virtual machine that the hard drive is attached to must be turned off. Once the server is offline, from within the Hyper-V Manager (it's an mmc snap-in) go to the virtual machine's properties (right click the machine and select properties). Select the drive you want to shrink on the left panel that lists the various devices attached to the virtual machine. After selecting the drive, on the right panel, select Edit. This will bring up a window that tells you what editing a drive does and gives you the option to not show that screen again. Click Next. From here you should have three options (unless the .vhd is static). Select Compact and click Next. Finally, click Finish and Hyper-V Manager will shrink the .vhd as much as it can.

Tuesday, June 9, 2009

Converting Disks in Hyper-V

I recently have been running into space issues. I had a four hundred gigabyte hard drive that had almost not space remaining. It stored 8 running servers with dynamically expanding disks that had a maximum size of 40 gigabytes (on the host it was almost 42 gigabytes). I also had to store a backup server image (sysprepped) for copying to quickly create a new server if needed. Additionally, one of the hard drives was 70 gigabytes, not 40. All around, the total came to 459 gigabytes if each hard drive expanded to its largest.I suggested to my boss that we should convert each disk to fixed rather than dynamic disks to improve performance. He agreed and I began my search for how to convert disks. Much to my delight, converting a disk is a relatively painless (albeit slow) process.
Here's how:

For starters, open up the Hyper-V Manager. If you have been working with Hyper-V for any amount of time, you should know where this is. If you're totally new to this, Hyper-V Manager should be located in Administrative Tools. If you can't find it there, open a run window (Windows Key + R) and type mmc. From the window that comes up, Click File -> Add/Remove Snap-in... From the window that comes up, scroll down in the Available snap-ins list and double click Hyper-V Manager. Click OK.

*NOTE* A server must be either off or paused to convert the disk (I chose off for my conversions)

Alright, now that that's out of the way, right click the server you want to convert.

From there, click settings. In the window that comes up (Settings for ), click the hard drive you want to convert. In my case I only had one hard drive 'attached' to my servers.
From here, click Edit











The window that comes up (Edit Virtual Hard Disk Wizard) will start on the "Locate Disk" step but should continue to the next step automatically in a few seconds. On the "Choose Action" step, check the radio button next to the "Convert" option (second down from the top).













Click Next. This will take you to the "Convert Disk" step. Here you need to set the destination filename for the conversion. In my case, I just selected the old file from the browse window and added a "_fixed" at the end of the filename. Any naming scheme works though of course.

Click Next yet again. This will bring you to the summary window. Make sure everything you entered is correct and click Finish.







From here, just sit back and relax.


The conversion speed at the beginning can be a little deceiving. Mine got almost 25% done in the first five minutes. It actually took it about an hour to complete for forty gigabytes though. Reminds me of a cell phone. It reads full battery power until it has none left and then it says it has none five minutes before turning off.