Can't Start Virtual Machine After Overwriting Virtual Hard Disk
I have been working on a personal project recently. My goal is to completely automate the process of building a virtual machine - without using templates.
As I have been working on this process, I have been making and deleting the same virtual hard disk over and over.
This causes an interesting problem. If you have a virtual machine all configured and ready to go - but you then replace the virtual hard disk file (i.e. delete the current .VHD file and create a new one in the same place with the same name) - when you try to start the virtual machine it will fail.
Instead of starting you will get an error message like this:
The problem here is the permissions on the new virtual hard disk. When you attach a virtual hard disk to a virtual machine Hyper-V will change the permissions (access rights) on the virtual hard disk. This needs to be done because Hyper-V virtual machines run under their own account, and this account needs to have permission to access the virtual hard disk. When you switch the virtual hard disk file of a virtual machine you lose these permissions.
Fixing this problem is simple - but not obvious. What you need to do is:
- Open the virtual machine settings (through the Hyper-V manager)
- Find the virtual hard disk in question
- Remove the virtual hard disk (use the remove button)
- Apply the changes
- Add a new virtual hard disk and configure it to point at the same virtual hard disk as before
- Apply the changes
This should only take a couple of seconds to do, and it fixes the virtual hard disk permissions so the virtual machine will start again.
Cheers,
Ben
Comments
Anonymous
June 22, 2011
So, it's same even if you use Hyper-V v3.. Why don't you simply check ACL of the VHD before starting process? It adds a few seconds only and should be acceptable if you are not in hurry.Anonymous
June 22, 2011
icacls.exe can help to automate this, i.e. icacls E:NewClient.vhd /grant "NT VIRTUAL MACHINEVM_GUID:(R,W)" VM_GUID can be obtained from Hyper-V host WMI. In cluster configuration, icacls.exe must be executed on the host where VM has been created.Anonymous
June 22, 2011
Dmitri - That is correct, and thanks for the extra information. Cheers, Ben