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

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

  • Comments 18

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

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
  • It's amazing how complicated you guys have managed to make this :-)

  • Yes, it is more complicated than I would like it to be.

    Cheers,

    Ben

  • > 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)?

  • pronichkin -

    Unfortunately you need to script in order for this to work.

    Cheers,

    Ben

  • 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:\MyCustomRoot\New 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:\MyCustomRoot\New Virtual Machine\” instead of default dara root (where it was originally created).

    Default data root (“c:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines”) contains no VM files (only symlink to my VM config at “C:\MyCustomRoot\New Virtual Machine\Virtual Machines\8976862F-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.

  • 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!

  • 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:\Users\All Users\Microsoft\Windows\Hyper-V\Virtual Machines" and "C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual 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?

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

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

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

  • 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!!!!!

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

  • Creating large snapshot files regardless if a snapshot has ever been used or not, and providing no means to disable snapshots, or those large files, is piss-poor design. There is no need for a VM that has a 3GB HDD and 4GB of RAM to require 7GB of HDD space.

  • Can anybody tell me how to get these vm configuration paths using wmi command..Thanks

  • very useful for nothing article, like most from Microsoft, nothing like right click on the vm and show in properties where the hell the xml file is...

Page 1 of 2 (18 items) 12