Note: This article is based on Hyper-V 2.0 and might not apply to Hyper-V 3.0 (Server 2012) This information is sourced from this Virtual PC Guy blog post, and is a work-in-progress. Please add other troubleshooting tips and best practices.
The files that comprise a virtual machine include:
Understanding data roots
Hyper-V has a concept of the “virtual machine data root” and the “virtual machine snapshot root”. These are the locations where the virtual machine configuration (.XML) and saved state (.BIN & .VSV) files are stored. For example – a virtual machine which had a virtual machine data root of “D:\Foo” and a snapshot data root of “D:\Foo” and had two snapshots would have a file structure like this:
D:\Foo D:\Foo\Snapshots D:\Foo\Snapshots\[Snapshot #1 GUID directory] D:\Foo\Snapshots\[Snapshot #1 GUID].XML D:\Foo\Snapshots\[Snapshot #2 GUID directory] D:\Foo\Snapshots\[Snapshot #2 GUID].XML D:\Foo\Virtual Machines D:\Foo\Virtual Machines\[Virtual Machine GUID directory] D:\Foo\Virtual Machines\[Virtual Machine GUID].XML
If the snapshots and the virtual machine had saved states associated with them – then the file structure would look like this:
D:\Foo D:\Foo\Snapshots D:\Foo\Snapshots\[Snapshot #1 GUID directory] D:\Foo\Snapshots\[Snapshot #1 GUID directory]\[Snapshot #1 GUID].BIN D:\Foo\Snapshots\[Snapshot #1 GUID directory]\[Snapshot #1 GUID].VSV D:\Foo\Snapshots\[Snapshot #1 GUID].XML D:\Foo\Snapshots\[Snapshot #2 GUID directory] D:\Foo\Snapshots\[Snapshot #2 GUID directory]\[Snapshot #1 GUID].BIN D:\Foo\Snapshots\[Snapshot #2 GUID directory]\[Snapshot #1 GUID].VSV D:\Foo\Snapshots\[Snapshot #2 GUID].XML D:\Foo\Virtual Machines D:\Foo\Virtual Machines\[Virtual Machine GUID directory] D:\Foo\Virtual Machines\[Virtual Machine GUID directory]\[Virtual Machine GUID].BIN D:\Foo\Virtual Machines\[Virtual Machine GUID directory]\[Virtual Machine GUID].VSV D:\Foo\Virtual Machines\[Virtual Machine GUID].XML
Some key things to highlight about data roots:
Understanding VHD and AVHD locations
.VHD files can be created pretty much anywhere you want. In Windows Server 2008 R2, .AVHD files are always created in the same location as their parent .VHD files.
Common Virtual Machine File Configuration #1 – Default Virtual Machine Data Root
A virtual machine with a default virtual machine data root is one where you created the virtual machine and accepted the default options in the new virtual machine wizard, specifically where you did not check to “Store the virtual machine in a different location” on the first page of the new virtual machine wizard:
In this configuration option the virtual machine data root and snapshot data root will be set to the path specified under the Hyper-V Settings in the “Virtual Machines” setting, and the virtual hard disk will be created under the path specified under the Hyper-V Settings in the “Virtual Hard Disks” setting:
These paths are normally set to “C:\ProgramData\Microsoft\Windows\Hyper-V” for the “Virtual Machines” setting and “C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks” for the “Virtual Hard Disks” setting. That said – I usually change these settings to “D:\Hyper-V\Configuration Files” and “D:\Hyper-V\Virtual Hard Disks” on my systems as I find this easier to work with.
Common Virtual Machine File Configuration #2 – External Virtual Machine Data Root
If you do select to “Store the virtual machine in a different location” you will get what we call a virtual machine with an external virtual machine data root.
With this option we create a new folder named after the virtual machine, and set the virtual machine data root and snapshot data root to this folder. We also default to creating the virtual hard disk in this new folder.
Common Virtual Machine File Configuration #3 – Exported / Imported virtual machine
If you export a virtual machine and then import it without checking the option to “Duplicate all files so the same virtual machine can be imported again”, you will end up with a virtual machine that looks like a virtual machine with an external data root – but there will be one difference.
Instead of having the virtual hard disks stored in the same location as the virtual machine data root – they will be stored in a “Virtual Hard Disks” folder under the virtual machine data root folder instead.
Changing a virtual machine to a default data root virtual machine
If you have an existing virtual machine that you want to change to a “default data root” configuration – the easiest way to do this is to export the virtual machine and then import it and check the option to “Duplicate all files so the same virtual machine can be imported again”. The resulting virtual machine will be a default data root virtual machine.
Changing a virtual machine to an external data root virtual machine
If you have an existing virtual machine that you want to change to an “external data root” configuration, you have two options:
Changing the snapshot data root for a virtual machine
The only way to change the virtual machine data root for a virtual machine is by using import / export. But the snapshot data root for a virtual machine can be changed at any time – as long as all snapshots are deleted first. If you have deleted all existing snapshots you can change the snapshot data root by changing the “Snapshot File Location” setting for the virtual machine under the virtual machine settings user interface.
Danny van Dam edited Revision 10. Comment: added hyper-v version to title
yottun8 edited Revision 9. Comment: Removed "(en-US)" in the title.
FZB edited Revision 5. Comment: typo
FZB edited Revision 4. Comment: typo
FZB edited Revision 3. Comment: typo
many thanks
good Article
On 2008 R2 Hyper-V, how can I change the "Location" for virtual hard disk. It seems to remember the one I have been using. I tried setting "Virtual Machines" setting in Hyper-V setting, but it only affected the first page where I specify name of the new VM. Is there a way to reset all setting in create wizard to origianl out of box?
Thanks for sharing!
Well.. When you find your drive is full of the temporary files in my documents or any default download folder, it may be due to dozens of duplicate files, which you download time by time and leave it there after viewing. This may cause a lot of drive space to cover. To manage this we have introduced an automatic method to help you. Which is using duplicatefilesdeleter.com saymahayen
Danny van Dam edited Revision 11. Comment: added note about that this might not apply to Hyper-V 3.0