Our first guest post (http://blogs.technet.com/tonyso/archive/2008/10/07/your-hyper-v-blog-post-here.aspx) comes from Jeremy Hagan. Thanks Jeremy!
One problem I have had when trying to do my first round of P2Vs for my Hyper-V implementation that I didn’t notice in testing is that you can’t size the VHD of the VM smaller than the corresponding physical disk of the original machine. Since it is best practice to have one LUN per VM and it is also best practice to have fixed VHDs, this can cause a lot of wasted SAN space. In my planning for the P2V process I monitored the target servers for 1 month so that I could get an idea of the CPU and memory use, but also the data growth. I decided to plot the percentage of data growth, extrapolate this for 3 years and then add a 15% premium on top of this then rounded up to the nearest 5 GB. This ended up being the SAN LUN size for each VM. The problem I then had was that I didn’t have enough SAN space available to P2V my machines.
What I decided I needed to do was to P2V each machine to a sufficiently large scratch LUN, then shrink down the VHDs to be the size I wanted then migrate the VM off the scratch LUN to the desired LUN. Easy right? Well maybe not. After much searching I have managed to come up with a recipe for doing this. See the example below. In this case it was a Windows XP machine with a 40 GB hard disk, but only 9.5 GB of data. If you want to play with this I recommend making a copy of the VHD file as a backup rather than taking a snapshot. Snapshots will interfere with final step using VHDResizer to create the final fixed VHD file.
Steps (assumes a single disk with a single partition):
Now if you think that is laborious and annoying, you’d be right. Hopefully Microsoft will come up with a better way to do this in the future. Now before I get a million comments about this, I did try to just use WinPE and DISKPART SHRINK, but no matter how many times I defragmented, precompacted and compacted I couldn’t get the partition to shrink down to less than about 24 GB.
There is quite a lot of documentation ( http://technet.microsoft.com/en-us/library/cc794762.aspx ) and