Automatic Start and Stop Actions for Hyper-V Virtual Machines
Hyper-V allows you to control the automatic start and stop behavior of virtual machines. This means that you can decide how a virtual machine will react before a host gracefully shuts down or after it boots up. Hyper-V treats virtual machines that are running on non-clustered hosts differently to those that are running on Hyper-V clusters (highly available virtual machines). I will discuss how virtual machines that are running on a non-clustered host will behave in this post. The behavior of highly virtual machines will be dealt with in a following post.
Hyper-V Automatic Start Action
If you edit the settings of a virtual machine, browse to Automatic Start Action. This allows you to configure what a virtual machine will do when its host starts up. There are three options:
- Nothing: The virtual machine will remain offline after the host boots up.
- Automatically Start If It Was Running When The Service Stopped: This option is useful in a test lab. You might have a mixture of virtual machines that are either running or stopped when the host shuts down. Hyper-V will automatically start up this virtual machine if this option is selected and the virtual machine was running when the host was shutdown.
- Always Start This Virtual Machine Automatically: This is the option you are likely to use for production virtual machines. You want to minimize downtime so the virtual machine will be started up when Hyper-V starts. Note that there is a sub-option to delay this start up by X seconds. This allows you to control contention for resources (mainly storage bandwidth) and to order the start of virtual machines (for example, start the domain controller, then SQL, application server, and then web server).
Hyper-V Automatic Stop Action
If you just pull the power of a host or it crashes, the virtual machines will simply stop running as if you had pulled the power from them too. So you should always try to gracefully shutdown your hosts.
You can choose to configure your virtual machines to react to this action by editing the Automatic Stop Action options in the properties of each virtual machines. Here you will find three options, which Hyper-V will execute on a per-virtual machine basis before shutting down the host:
- Save The Virtual Machine State: This option helps you minimize virtual machine downtime. The virtual machine is frozen in time, writing the memory and processor stack out to a file that is stored with the virtual machine. After that write is complete the virtual machine stops running. When the virtual machine starts up, it will read in that file and start executing, “auto-magically” continuing as if nothing had happened. The guest OS doesn’t need to boot up, services don’t need to initialize, caches don’t need to be repopulated; things within the virtual machine just continue as they were before the virtual machine stopped running.
- Turn Off The Virtual Machine: This option will pull the plug on the virtual machine. No state information is saved. The guest OS will act as if the virtual machine lost power if/when it is started up again. You will use this option on selected virtual machines if you don’t care about the state of a virtual machine and you need a quicker host shutdown.
- Shutdown The Guest Operating System: The guest OS of the virtual machine will be gracefully shut down when before the host will be shut down. No state is saved. The downside is that the guest OS and its services will take time to start up when the host restarts. You should consider delaying and ordering the start up of virtual machines if you select this option.
There is a catch to the option to save a virtual machine state. If you have virtual machines with a sum of 250 GB RAM, then Hyper-V will need to write out up to (roughly) 250 GB RAM to disk to save their states to disk. You need to size for 250 GB of additional disk capacity beyond the normal storage requirements of virtual machines. You also need to be aware that Hyper-V maintains a .BIN file for each virtual machine to guarantee this space will be available. So that 250 GB is actually consumed even if the virtual machine is running.
This .BIN file was always present before Windows Server 2012 (WS2012) Hyper-V. Since WS2012, this .BIN file is maintained for a virtual machine only if you select the Save The Virtual Machine State automatic stop action for that virtual machine. This allows you to save the hypothetical 250 GB of disk capacity, but it means that you either turn off your virtual machines (not recommended) or cleanly shutdown your guest OSes when a host is shut down.
More in Hyper-V
How to Install Hyper-V on Windows Server Core
Mar 16, 2022 | Michael Reinders
Microsoft Says There Will Be No Hyper-V Server 2022 Free Edition
Dec 13, 2021 | Michael Reinders
How to Stop an Unresponsive Hyper-V Virtual Machine
Jun 29, 2021 | Russell Smith
How to Enable Nested Virtualization in Hyper-V
Jun 28, 2021 | Russell Smith
Disaster Recovery with Azure Backup for SQL Server VMs
May 28, 2019 | Michael Otey
Leveraging Virtualization for Improved Availability and Disaster Recovery
Apr 29, 2019 | Michael Otey
Most popular on petri