Thursday, April 21, 2016

Hyper-V: The operation failed because the file was not found.

TL;DR: Give permission for the local user named SERVICE to access the files in question.



The long version:

Hyper-V is a powerful hypervisor. It's a shame it has to run on such a stupid OS with so loosely defined user accounts. The Hyper-V service (as it exists by default on Windows Server Core 2012r2, and probably everywhere else) runs as the user "Local System". As is the case on all OSs, a user must be given permission to access and manipulate a file (in this case, VHD files). You'd think that giving access to "Everyone" or "LOCAL SERVICE" would do the trick, but you'd be wrong. Apparently, the real name of "Local System" is "SERVICE", and I don't know why services.msc doesn't just say that.

Since I first set up Hyper-V, I've been getting an error message that looks like this:
Window Title: Virtual Machine Connection
Main Instruction: The application encountered an error while attempting to change the state of 'VM name'.
Content: 'VM Name' failed to change state.
The operation failed because the file was not found. 
Searching the great and powerful Google lead me nowhere. Thankfully, I was able to solve it pretty easily. In my case, I'm using a Core install so I don't waste any more resources on the big stupid Windows than I have to. This means I have to do everything remotely. Obviously you'll need a machine with the permission and ability to manipulate the permissions of these files. I did it from an SMB/CIFS share of the VHD repo, but you can remote in and do it locally, or temporarily enable Admin Shares, or better yet: SSH in and run chmod or chown--just kidding, that would be too easy.
  1. From any machine with a full Windows installation (I haven't tried doing this from any other OS) navigate to the folder holding the "file not found" files. I used Windows 7 to fix my 2012r2 Core, but you can use whatever is handy.
  2. Right-click on their parent folder (or several grand-parents down, whatever) and go to Properties. 
  3. Click the "Security" tab.
  4. Click "Edit..."
  5. Click "Add..."
  6. Click "Advanced"
  7. Click "Locations..."
  8. Select the actual host of this folder, not your local computer, not a Domain Controller. It should be the top-most item on the Location tree.
  9. Click "OK"
  10. Click "Find Now"
  11. This should show every single user, group, and security principal local to that machine. Press the S key to be brought to the 'S' section of this alphabetically sorted list.
  12. Look for a group called "SERVICE".
  13. Double-Click the "SERVICE" group to choose it.
  14. Click "OK"
  15. Now back at the "Permissions for [folder]" window, give the "SERVICE" group full control.
  16. Click "OK" a bunch, and you're done.
Start up your VM and cross your fingers.

This worked for me, and I didn't see it posted anywhere else, so I figured I'd share it. As with anything, Your Mileage May Vary.

4 comments:

  1. Great! worked on our environment. Problem happened after they changed the hostname of the main vm host.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hello there,

    thank you for the post, appreciate if you could explain " From any machine with a full Windows installation (I haven't tried doing this from any other OS) navigate to the folder holding the "file not found" files. I used Windows 7 to fix my 2012r2 Core, but you can use whatever is handy. Right-click " quoted.

    Thanks

    ReplyDelete