Condividi tramite


Understanding where your virtual machine files are [Hyper-V]

To be honest, I am surprised that I have not blogged about this before, but today I would like to talk about how virtual machine files are placed on the hard disk. 

Virtual Machine files

The first thing to know is what files are used to create a virtual machine:

  • .XML files
    • These files contain the virtual machine configuration details.  There is one of these for each virtual machine and each snapshot of a virtual machine.  They are always named with the GUID used to internally identify the virtual machine or snapshot in question.
  • .BIN files
    • This file contains the memory of a virtual machine or snapshot that is in a saved state.
  • .VSV files
    • This file contains the saved state from the devices associated with the virtual machine.
  • .VHD files
    • These are the virtual hard disk files for the virtual machine
  • .AVHD files
    • These are the differencing disk files used for virtual machine snapshots

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:

  • We always create a “Virtual Machines” folder under the virtual machine data root and store the virtual machine configuration files there.
  • We always create a “Snapshots” folder under the snapshot data rot and store the snapshot configuration files there.
  • We fully support multiple virtual machines having the same virtual machine and snapshot data root

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:

image

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:

image

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.

image

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 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.

image

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:

  • Spend some time scripting the import / export APIs in Hyper-V.  It is possible to do it this way – but it is not easy.
  • Move the virtual machine using System Center Virtual Machine Manager.  SCVMM will always transform a virtual machine into an external data root virtual machine in the process of moving it.

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.

And that is pretty much all there is to know about where virtual machine files are stored today :-)

Cheers,
Ben

Comments

  • Anonymous
    March 09, 2010
    It's amazing how complicated you guys have managed to make this :-)

  • Anonymous
    March 10, 2010
    Yes, it is more complicated than I would like it to be. Cheers, Ben

  • Anonymous
    March 10, 2010
    > If you have an existing virtual machine that you want to change to an “external data root” configuration, you have two options... and what about trivial export/import (w/o duplicating files)?

  • Anonymous
    March 10, 2010
    pronichkin - Unfortunately you need to script in order for this to work. Cheers, Ben

  • Anonymous
    March 10, 2010
    Sorry, I didn't get it.

  1. I create a New VM under default data root (i.e. leaving “Store the virtual machine in a different location” checkbox blank).
  2. I export VM to “C:MyCustomRoot”.
  3. I delete original VM in Hyper-V MMC.
  4. I import VM from “C:MyCustomRootNew Virtual Machine” using all default settings (i.e. “Move or restore the virtual machine (use the existing unique ID)” selected and “Duplicate all files so the same virtual machine can be imported again” cleared). What happened? I have my VM living under “C:MyCustomRootNew Virtual Machine” instead of default dara root (where it was originally created). Default data root (“c:ProgramDataMicrosoftWindowsHyper-VVirtual Machines”) contains no VM files (only symlink to my VM config at “C:MyCustomRootNew Virtual MachineVirtual Machines8976862F-BE8F-4E72-AF96-C6EB4BF43665.xml”). Doesn't that mean that I successfully converted a default data root VM into external data root VM? No scripting, just plain export/import.
  • Anonymous
    March 21, 2010
    Ben, We have Forefront Client Security installed on the host servers. We excluded VHD files in Forefront so it won't attemp to scan it everytime the VHD is being written. Do you suggest also excluding BIN, VSV and AVHD files you mentioned? Thanks!

  • Anonymous
    November 10, 2010
    I don't know if you are still getting these as this is old, but I have a more basic question.  Why are there two .bin files for each VM?  Specifically in "C:UsersAll UsersMicrosoftWindowsHyper-VVirtual Machines" and "C:ProgramDataMicrosoftWindowsHyper-VVirtual Machines" of the exact same size?  There are no snapshots.  Both files disapear when the VM is shut down.  Do I need both?  Is one reliant on the snapshot setting and will move if I change that setting?  Can these files be shrunk in any way regularly?

  • Anonymous
    November 15, 2010
    My avhd files are growing out of control. They're almost 400 gigs for a 60 gig exchange server. I'm running out of space and have no idea what to do.

  • Anonymous
    May 26, 2011
    How can I import virtual machines so the VHD and VM files end up in the default Hyper-V file locations?

  • Anonymous
    June 09, 2011
    How do I get a list of all VMs on a Hyper-V server and the data root for each one. One I know the location of the XML config file I'm good, but it is not clear to me how I would get the directory in the first instance. Yes, most likley it would be in the default directory - but it may not be.

  • Anonymous
    January 15, 2012
    this doesn't say where they are located!!! I need to delete them.... nowhere in this article it says where they are!!! :( the title of this article is misleading!!!!!

  • Anonymous
    September 19, 2012
    How we can achieve the same i.e. importing a VM in the user-defined folder using WMI class in WIndows 2012?

  • Anonymous
    October 10, 2012
    The comment has been removed

  • Anonymous
    February 28, 2013
    Can anybody tell me how to get these vm configuration paths using wmi command..Thanks

  • Anonymous
    November 04, 2013
    The comment has been removed

  • Anonymous
    March 28, 2014
    Ben, Thanks for this informative post

  • Anonymous
    May 20, 2014
    Is there a blog post update covering 2012 R2?  What's an *.hrl file in the Hyper-V storage folder?

  • Anonymous
    July 15, 2014
    Thank you Ben for this valuable information. Cheers mate.

  • Anonymous
    November 29, 2014
    I can't find %LocalAppData% anywhere on my drive. Where are the files?

  • Anonymous
    December 03, 2014
    What a disaster. Typically MS since about 2004. The sooner someone else comes up with a decent Server OS the better.

  • Anonymous
    December 12, 2014
    I have this file in D:Hyper-VVirtual MiscGuestNameSnapshots9C5136D7-5CA5-526F-BF3B-0513F5DF00FD9C5136D7-5CA5-526F-BF3B-0513F5DF00FD.vsv file that is older than 6 months and is static in size at 5k. My snapshot manager shows no snapshots active. Can I just delete this file?

  • Anonymous
    March 11, 2015
    VERY Helpful!!  Thanks!  One small correction: in these lines, I suspect you mean "#2" in all four places, not just two:  D:FooSnapshots[Snapshot #2 GUID directory][Snapshot #1 GUID].BIN  D:FooSnapshots[Snapshot #2 GUID directory][Snapshot #1 GUID].VSV

  • Anonymous
    March 18, 2015
    The comment has been removed

  • Anonymous
    May 10, 2015
    Tried to create each machine in its own folder:   D:SERVER1, D:SERVER2, etc. Hyper-V manager kept creating sub-folders, like   D:SERVER1SERVER1 and putting its files in there. Somewhere along the way, it even started making the sub-folders at the root of D: - D:Virtual Machines, etc. I finally worked it out, but it was anything but straightforward.   What you need to do is anticipate what Hyper-V Manager is going to do, and choose the location with that in mind. So, I chose d:, and it installed in d:SERVER1... With Microsoft, nothing is ever straightforward!

  • Anonymous
    July 27, 2015
    The only two files you really need then are.

  1. xmL
  2. .bin The others are just snapshots, not even a full clone or backup.   Probably best to turn that feature off.
  • Anonymous
    July 27, 2015
    "The only way to change the virtual machine data root for a virtual machine is by using import / export" That is not true, not the only way.   You can also just change the path in the manager and then manually delete the files on the C: drive.   I've done that.  I wanted my files on drive E: and did not want the snapshots.   In the HV manager (I use 5nine now) you can change the paths for all the files and it will auto create in the new drive.  

  • Anonymous
    February 16, 2016
    It's great that you are getting ideas from this article as well as from our argument made at this time.