Right… This has been driving me crazy today. Not really sure why it happened but I’ve managed to sort if out now and wanted to share!
Our hyper-v server hosting our domain controller and a couple of Linux machines decided today that it didn’t want to admit to having any machines hosted on it. When opening hte hyper-v management tools on my Win 7 laptop I was getting the message “No Virtual Mahines were found on this server”. That was quite a worry and made me reluctant to re-boot the host machine through fear of not being able to control the hosted machines any more.
My first hurdle was getting access to the Hyper-v R2 Event Log. For some reason the firewall was not configured to allow me to access this. This was a simple fix of opening the fiewall on the hyper-v server to allow WMI access. The alternative is to drop the fire wall for the duration of this fix (netsh firewall set opmode disable) and re-enable it after (netsh firewall set opmode enable).
Ok the real crux of the problem. For some reason the security permissions on the hyper-v configuration files had been lost or reset. It took me an age to fix this but finally managed to piece together enough information to fix it.
The Virtual Machine Management Service uses some configuration files from the directory %SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\. The xml files in this directory are in fact symlinks and should be named the same as the xml configuration files for the virtual machines them selves.
We store our virtual machines in the directory v:\VMs. So for example our machine test-01 has it’s xml file stored as V:\VMs\test-01\Virtual Machines\<guid>.xml.
Each virtual machine on the host has a similar set up. To fix the permissions you need to recreate the symlinks in the directory %SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\. To do that you need to execute the following commands for each machine.
mklink “%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\<vm_guid>.xml” “V:\VMs\win2k8r2\Virtual Machines\<vm_guid>.xml”
icacls “%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\<vm_guid>.xml” /grant “NT VIRTUAL MACHINE\<vm_guid>”:F /l
The one part that I missed initially was the “/l” on the end of the icacls command. This is very important and tells icacls to apply the security permission to the link rather than the destination file.
If any of your VM’s have snapshots you need to repeat a similar procedure for the snapshots directory.
mklink “%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\<snapshot_guid>.xml” “V:\VMs\test-01\Snapshots\<snapshot_guid>.xml”
icacls “%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\<snapshot_guid>.xml” /grant “NT VIRTUAL MACHINE\<vm_guid>”:F /l
When you have repaired all the files in the directories simply restart the Virtual Machine Management Service” by using the following two commands:
net stop vmms
net start vmms
You should now be able to view the files in the Hyper-v management console.