Freigeben über


Browsing Hyper-V VM Folders in Hyper-V 2012: Think Datastores for VMware Admins

During my Pro Camp events I often get asked about Hyper-V “Datastores,” in that VMware administrators want to know how to access them, search through the contents, and move files around.   Since Hyper-V doesn’t really use the term “Datastores” I will often take a tangent at this point in the conversation to discuss the differences, as well as point out some of the similarities.

So for sake of this article I will use the term “Datastores” rather loosely.  Datastores hold not only the virtual disk files that a VM utilizes as virtual hard drives, but also the configuration file for the virtual machine itself(in VMware: the VMX file).   Sometimes the configuration files are held on different datastores than the virtual hard drives(in VMware: the VMDK files). So there are definitely occasions where the disk files and config file may not reside together which can make for a somewhat difficult time understanding the full make up of the virtual machine you might be investigating at the time.  Various third party utilities have emerged in the market to help with this process for VMware admins, like vKernel, Veeam, vFoglight, and Solarwinds for example.  However for those without these third party tools, the manual process of browsing must be followed. 

In VMware you normally browse datastores via the VI Client connected to an ESX host or Virtual Center.   In Virtual Center you can get to this screen in multiple ways, by click on the ESX host then clicking on the Browse Datastores links found on the summary page or in the Storage tabs.  There is a utility built into Virtual Center that allows for uploading disk files into the datastores, or downloading/moving files between datastores and the hosts.  What is important to remember here, when you move a VMDK file somewhere else you must also remember that the corresponding config file must be updated either through a text editor or the VI Client menus so that the VM will know where the disk files are now located. 

In Hyper-V, the config files and virtual disk files also reside in separate containers(by default) however these are labeled.  Take for instance the screenshot below.  Since Hyper-V does not require a different formatting of the underlying physical disk structure like VMFS(VMware’s proprietary disk format) we are able to browse the “datastore” with File Explorer(In Windows 8/Server2012…formerly known as Windows Explorer).

image

You can see the Virtual Hard Disks folder is separate from the Virtual Machines folder.   Also the Snapshots and Planned Virtual Machines folders are found on the physical drive as well.  Notice also that I manually created a VM and placed it in it’s own folder outside of this default structure.  We will not focus on that too much today, the point of this article is to look at the folder and file structures to better understand them. 

Looking inside the Virtual Hard Disks folder we will see the disk files, in this case I have only one disk file, but I also see another file.  The HRL file extension is something the system creates to track Replication.  So when I turned on replication this file got created in the same folder as my virtual machine’s disk file.

image

In the Virtual Machines folder we will see both a file and a subfolder with the same unique character sequence.  These pairs work together to manage the Virtual Machine configuration.  The XML file is named quite different than what we might expect as VMware admins. This is the Unique identifier for a virtual machine. This is an important difference between VMware and Hyper-V. In VMware the VMX file is named the same as the virtual machine name provided at creation. This tends to become quite a problem for admins that rename their virtual machines after creation, as there is really no cleanup practice automatically performed to match the VM configuration files with their newly renamed VM objects in Virtual Center.  

The flipside of this argument, when strolling through a large volume of Hyper-V VMs becomes a bit tedious without some way of knowing which unique identifier points to which actual VM.  In my case below its pretty simple because I have one virtual machine in the default container.  Lets first investigate the file to see how it works, then lets look at a better way to inventory large quantities of VM config files.

image

After opening the XML file in a text editor, in this case I will use Notepad, we can stroll through all of the various settings and other fields that control the appearance and architecture of the VM.  For instance after scrolling down to the “properties” section we can see the “name” property equates to “tommytest” which is the real name of the VM at present:

image

Near the beginning of the file we should also find the path to the virtual disk as well as the name of the VHD:

image

Now to make this effort of understanding which unique identifier refers to which VM a bit simpler, here is a vb script that we can run to identify all VMs on the host along with their unique identifier(GUID).   Paste the contents of this script into a text file and name it getvminfo.vbs:

____________Borrowed from Michael Michael’s TechNet Blog_________________

Option Explicit
Dim WMIService
Dim KvpComponents
Dim VMList
Dim VMSettingList
Dim VM
Dim item
Dim setting
Dim component

'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
'Get all the MSVM_ComputerSystem object
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")   
For Each VM In VMList  
if VM.Caption = "Virtual Machine" then      
  WScript.Echo "========================================"      
  WScript.Echo "VM Name: " & VM.ElementName      
  WScript.Echo "VM GUID: " & VM.Name     
  WScript.Echo "VM State: " & VM.EnabledState   

  ' Now get the BIOS GUID for this VM
  Set VMSettingList = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemSettingData")   
  For Each setting In VMSettingList
   Dim tempVMname
   tempVMName = "Microsoft:"  + VM.Name
   if setting.InstanceID = tempVMName then      
    WScript.Echo "VM BIOS GUID: " & setting.BIOSGUID  
   end if
  Next
end if
Next

____________Borrowed from Michael Michael’s TechNet Blog_________________

Now open a command prompt as an Administrator then run the script with the following syntax:

!!!Replace the <location> with the folder where the newly created vbs file resides, i.e. c:\temp\getvminfo.vbs!!!

cscript.exe <location>\getvminfo.vbs

The output should look like this:

image

Now we have a way to list out all VMs running on a given host as well as the corresponding GUID, so when we peruse a Hyper-V VM container we can now better understand the structure. 

I hope this helps provide a better understanding with the inner-workings of VM config and data files in Hyper-V.   If you haven’t given Hyper-V 2012 a spin yet, follow along in my online lab guide found here, where you shouldn’t need anything but some disk space on your laptop!  For those seeking to install Hyper-V on new hardware grab the bits here!