Virtual Hard Disks or VHD’s are not just the format used to hold a hard disk for use with they also have at least three other uses I know of:
I use this a lot in building demo environments because I can mount a VHD on a running environment (physical or virtual) and copy stuff to and from it.
First of all I need to create a VHD which can either be done under the hyper-V role or under disk management in server manager (which I find is faster). I simply go to the actions and select create VHD:
in the wizard specify it’s size, location and what kind of disk (dynamically expanding or fixed). In the demo world dynamically expanding is fine and even though I have specified 10Gb the VHD will start at 4Kb until I start to do anything with it.
Click OK to finish and the VHD now shows up in Disk Manager(with a pale blue icon to show it’s a VHD)..
Now you can initialise it , create partition(s), format it and assign it a drive letter as you would any physical disk(in this case I now have disk manager open in server manager)..
So now I can copy whatever I want into it such as installation files databases scripts etc.
When I have all the stuff I need on the VHD, I just come back to disk manager and detach it, by selecting it, right clicking and choosing detach
as I can’t use the same vhd in more than OS at the same time.
Now it’s detached I can attach it a virtual machine. The virtual machine must be off to do this So this is unlike an .iso file which you can mount at anytime but is of course read only once you’ve made it.
Anyway I can now go to the settings of a non running virtual machine in server manager in this case my windows 7 client virtual machine. I select the IDE controller 0 and the option to add a hard disk
I specify the path of the resources VHD I created above…
..and click OK to attach it to the VM.
No I can start the VM and see my resource disk with all the stuff I put on it..
At this point I have usually forgotten to add something to this VHD that I needed. All I need to do now is stop the VM, attach the VHD on the physical OS again, copy the extra stuff, detach and start the VM again.
It gets better in that the VHDs can be reused in this way on any VM and I could even do all this attach/detach business in PowerShell. BTW If you want to use PowerShell then refer to this excellent post from Taylor Brown a member of the Windows Server core team.
You can do all of this in Virtual PC as well and move a VHD’s between the two.
don't forget that DISM and DJOIN work with vhd files also!
don't forget dism and djoin work with vhd files also!
and the cool support of diskpart fro vhd's
on my wishlist:
support fro mounting dynamic disks in a vhd and not only basic disks with disk mamager/diskpart
+ 2TB size ...
If you want to copy things to and from the VHD you can also use "Shared Folders" (if supported) or share out a directory on your hard drive and access it from the VM.