Posey's Tips & Tricks

Why Hyper-V VMs Sometimes Fail to Stop

Here are some reasons why your Hyper-V virtual machines might fail to shut down and how you can troubleshoot this recurring issue.

Occasionally, you may find that when you attempt to use the Hyper-V Manager to shut down a virtual machine, the operation fails and the virtual machine continues to run. When this happens, the Hyper-V Manager simply displays a generic error message saying that an error has occurred while attempting to shut down the virtual machine. As you can see in Figure 1, the error's sub text unhelpfully goes on to say, "failed to stop."

[Click on image for larger view.] Figure 1. Sometimes Hyper-V virtual machines fail to shut down.

An error such as the one shown above can sometimes stem from a problem within the virtual machine itself. If, for example, the virtual machine's operating system has locked up then the Hyper-V Manager probably won't be able to initiate a graceful shut down. In my experience, such problems tend to be rare. Most of the time, errors like the one shown in the figure above are tied to the virtual machine's state and are easy to resolve.

This of course raises the question of how you can tell whether a problem is tied to a VM's operating system or to its state (or perhaps even to something else). The easiest way to tell what is causing the problem is to check the Windows Event Viewer.

To do so, open the Event Viewer on your Hyper-V host by entering the EventVwr command at the Windows Run prompt. When the Event Viewer opens, navigate through the console tree to Applications and Services Logs > Microsoft > Windows > Hyper-V Worker > Admin. If the problem is related to the virtual machine's state, then you should see an error event corresponding to your attempted shut down of the virtual machine. You can see and example of this in Figure 2.

[Click on image for larger view.] Figure 2. The Windows Event Viewer shows the reason why the virtual machine cannot be shut down.

As you can see in the figure above, the Event Viewer displays an error indicating that the machine is locked and cannot be shut down without a force operation. The Details pane does not yield any additional useful information about the problem.

So what is going on, and what can you do to fix the problem? This particular problem occurs as a result of someone opening a console session with the virtual machine. This is not to say that the console is still open (though it might be), but rather that the console left the VM in a state within which the Hyper-V Manager cannot perform a graceful shut down.

This type of situation is extremely common. Imagine for a moment that you needed to perform some sort of management operation on a Hyper-V virtual machine, so you open the virtual machine's console and log in. Next, you do whatever it was that you set out to do, but while the console is open you get distracted by a phone call. While you are on the phone, your inactivity causes the console to auto lock. When you eventually hang up the phone, you go ahead and close the console.

From Hyper-V's perspective, the problem with this chain of events is that you are still logged into the virtual machine. Being logged in isn't a problem in and of itself. The Hyper-V Manager will allow you to shut down a virtual machine even if you are logged into it. The problem is that the virtual machine's console was locked while someone was logged in.

As previously mentioned, this problem is easy to correct. In fact, you have two different options.

The first option is to simply open the console and log into the virtual machine to unlock it. At that point, you can initiate a shut down from within the VM console or you can use Hyper-V Manager to shut down the virtual machine.

The second option is to use PowerShell to force a shut down. Just open an elevated PowerShell session and enter the following command:

Stop-VM -Name <virtual machine name> -Force

You can see what this looks like in Figure 3.

[Click on image for larger view.] Figure 3. You can use PowerShell to shut down a virtual machine.

Incidentally, one more option is to just right click on the VM and select the Turn Off command. However, I recommend using this option as a last resort since it is analogous to yanking the power cord out of a physical machine.

About the Author

Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.

Featured

comments powered by Disqus

Subscribe on YouTube

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025