Windowns Hyper-V Virtual Machine shutdown instead of restarting as commanded

rebootshutdownvirtual-machineswindows-server-2012-r2windows-server-2016

I am running a Windows 2016 Hyper-V host with the following VM's
2x Windows 2012 R2
2x Ubuntu 16.04

Whenever I carry out a restart of the VM's after an update they nearly always shut down and remain in an 'OFF' state instead of restarting.

I have tried different methods of restarting with both the cmd line and GUI in the case of the Windows VM's, and with sudo shutdown -r now in the case of the Linux servers (it makes no difference whether I run the command as a regular user with sudo privileges or root on the Linux servers).

Why does the VM shutdown instead of restarting?

Best Answer

There are two primary requirements for guests to restart after a host shutdown.

  1. As noted by Vick Vega in the comments on the question, you must have the latest integration services installed in the guest OS.
  2. You have to configure the guest in Hyper-V Manager for the appropriate shutdown and startup type.

For most modern guest operating systems officially supported by Microsoft running on Hyper-V 2016 or newer, integration services come prepackaged in the OS. You can enable integration services in the guest settings. You can access these settings by right clicking on the guest in Hyper-V Manager and selecting "Settings" and then under "Management" select the "Integration Services" option. Settings here allow you to configure which integration services you want to be available within the guest.

To configure how a guest operating system reacts when the host is shut down, you access the guest settings the same way and select "Automatic Stop Action". The settings in here include "saving" the virtual machine state (essentially buffering the running state to disk and restoring that running state upon guest startup), turning off the virtual machine (equivalent to instantly cutting power to it, a non-graceful shutdown), or to shut down the guest operating system which attempts to perform a graceful shutdown using the integration services.

To configure how a guest operating system reacts when the host is powered on, access the guest settings the same way and select "Automatic Start Action". The options here include "Do nothing", automatically start the VM if it was running when the host shut down, or always automatically start the VM. You can also configure a startup delay to give the host or other VMs a chance to finish booting before starting a particular guest - this is useful if you want to boot your DC first, you can set your member servers to have a 5 minute startup delay.

There are a few cases where these settings don't work as designed:

That last one is fun since the default timeout period is 2 minutes (120 seconds) so any guest that takes longer than that to shut down will wind up getting full-stopped. This can happen a lot if you have slower hardware or OS updates queued on the guest. To date (to the best of my knowledge) as of Server 2019 the only way to adjust this timeout period is to edit the registry. The registry key (as of Server 2016) is located in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization and is named ShutdownTimeout.

For non-standard scenarios - like running a guest OS that doesn't have integration services preloaded, like older or obscure distros of Linux, you'll need to find the appropriate integration services download for that OS. Integration services are NOT available for every guest OS and Microsoft doesn't make it easy to run guest operating systems that aren't officially supported.

The above instructions may vary slightly with different versions of Hyper-V or if you're using Hyper-V Client on a Windows 8+ desktop OS. This can also all be configured using PowerShell if you're running Server 2016/Windows 10 or later.

Better late than never! Hope that helps :)