Hyper-V Automatic Start and Stop Action

Virtual Machines running on Hyper-V can be configured to start automatically when Hyper-V Server starts or in case if something goes wrong with the Hyper-V Server and it restarts.

Automatic Start Action

The “Automatic Start Action” feature is very helpful for virtual machines which need to be started first before any other virtual machines can be started. This option is designed by keeping a few IT scenarios in mind. For example, you might want to start a domain controller virtual machine before you start messaging (Exchange Server) virtual machine which requires Active Directory authentication. Similarly, in a “three-tier” architecture, you must make sure clustered database virtual machines are up and running before you start the middleware virtual machines running Internet Information Server (IIS).

There are three options provided with the “Automatic Start Action” feature which can be configured per virtual machine as shown in the below screenshot:

 

Nothing” option, as the name suggests, do nothing when the Hyper-V Server starts for this virtual machine particularly.

Option “Automatically start if it was running when the service stopped” can be used if you want Hyper-V Virtual Machine Management Service (VMMS.EXE) to start the virtual machine automatically only if it was running when the Hyper-V Virtual Machine Management Service was stopped.

Well, I think this is not the option organizations would like to go with for any of the production virtual machines. First of all, in any production environment, there is a process defined even for starting up virtual machines either manually or automatically. It depends on the type of virtual machine and how critical it is for the business. For example, this option might not be a good option for virtual machines which are running banking applications which store their data on a clustered virtual machine. In this case, you would always want to start the clustered database virtual machine first before starting the banking application virtual machine. This option might be a good fit for virtual machines which are non-critical and must be started automatically.

By default, all the newly created virtual machines are configured with this option.

Always start this virtual machine automatically” instructs Hyper-V Virtual Machine Management Service to always start this virtual machine automatically when the Hyper-V server restarts. Use this option only when you think the services offered by the virtual machine are very critical to the business and the virtual machine needs to be up and running as soon as possible. This is actually helpful if Hyper-V Server restarts from an unexpected failure.

The “Startup Delay” option is helpful when you have Root and Child domain controllers set up in a virtual environment. Let’s say, all of a sudden something happens to the Hyper-V Server and it restarts. As part of the initialization process, which is explained later in this article, all the virtual machines will be initialized/started by the Hyper-V Virtual Machine Manager Service. If you have not set “Startup Delay” option then all the Root and Child domain controller virtual machines will start concurrently. This might cause some failures if the Root domain controller virtual machines are not up and running before Child domain controller virtual machines start. In this case, it is necessary to use either “Automatically start if it was running when the service stopped” or “Always start this virtual machine automatically” option with a “Startup Delay” value to make sure Root domain controller virtual machines start first before the Child domain controller virtual machines can be started.

This is more explained in the logic explained below. When the Hyper-V Server is restarted, the following events occur:

  1. Hyper-V initializes hypervisor code on the hardware.
  2. Hypervisor creates virtual environment.
  3. After creating the Virtualization environment, the control is returned to the Parent Partition.
  4. The Parent Partition, in turn, returns the control to its component called VMMS.exe or Hyper-V Virtual Machine Management Service.
  5. VMMS.exe is a multi-threaded application. It can initialize and start a virtual machine and get the control back to initialize and start other virtual machines. VMMS.exe does not have to wait for the virtual machine to be up and running before starting the next one. VMMS.exe performs two operations for a virtual machine at start up; (1) initialize the virtual machine to make sure its VHD files and configuration files are intact and (2) Start the virtual machine.
  6. VMMS.exe initializes and starts the virtual machines based on the following logic:
  • Filter all the virtual machines which are set to always start automatically or using “Always start this virtual machine automatically” option.
  • Filter all the virtual machines which have been configured with “Automatically start if it was running when the service stopped” option.
  • Get the “Startup Delay” value for the virtual machines which are using above two options.
  • Get all the virtual machines which are using “Nothing” option.
  • Once VMMS.exe has the list of virtual machines, it performs the following logic to start these virtual machines:
    • Start all the virtual machines for which “Startup Delay” is set to ZERO. That means do not wait for seconds to elapse and start the virtual machines immediately.
    • Initialize all the virtual machines for which “Startup Delay” is set to a value other than ZERO and wait for the seconds to elapse before starting the virtual machines.
    • Initialize all other virtual machines which are using “Nothing” option but do not start them.

Automatic Stop Action

Let’s talk about the “Automatic Stop Action”. As shown in the below screenshot, there are three options available even for “Automatic Stop Action”.

Save the virtual machine state” option instructs Hyper-V Virtual Machine Management Service to save the virtual machine state on the local disk when the Hyper-V Server shuts down.

Option “Turn Off the virtual machine” is used by the Hyper-V Management Service (VMMS.exe) to gracefully turn off the virtual machine.

Option “Shut down the guest operating system” is successful only if the “Hyper-V Shutdown” guest service is running in the virtual machine. The guest service is required to be running in the virtual machine as the Hyper-V VMMS.EXE process will trigger Windows Exit message which is received by the service. Once the message is received by the guest service, it takes the necessary actions to shut down the virtual machine.

Note: “Automatic Stop Action” feature is not helpful if Hyper-V Server goes down due to an unexpected failure. The VMMS.exe process must receive the “Windows Exit” message from Operating System before these options can be useful.

Conclusion

In this article, we learned about the different options available with “Automatic Start Actions” and “Automatic Stop Actions” which can be used by each virtual machine running on the Hyper-V. We saw how these options help achieve the different IT scenarios in a virtual environment. We also learned the logic Hyper-V Virtual Machine Management Service (VMMS.exe) utilizes to initialize and start the virtual machines which are configured to use the “Automatic Start Actions” options.

While I was writing this article, it reminded me to convey a message to the organizations which are running their “critical” business applications in a virtual environment. What I want to convey here is that the Hyper-V Server may also crash. As part of the crash, it impacts all the virtual machines running on the Hyper-V Server which, in turn, impacts the data and applications running inside the virtual machines. So it is always a good practice to perform regular backups of the virtual machines. In case of a sudden failure, you can at least recover your virtual machines and data if you have a good backup copy. Altaro has recently released Altaro Hyper-V Backup 4.0. The new version will not only include the new features but also use the robust algorithm to backup virtual machines running on the Hyper-V which helps in reducing the overall backup size. You download a copy here. It’s a full 30-day trial which lets you back up 2 Hyper-V VMs for free, forever.

 

Altaro Hyper-V Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

39 thoughts on "Hyper-V Automatic Start and Stop Action"

  • Stephane Gagne says:

    Hi,
    Have you noticed difference between Hyper-V 2 vs 3 on the “automatic stop action”?
    I was able in version 2 to modify the stop action while the vm is up but can’t in Hyper-V 3…

    • Nirmal Sharma says:

      Hi Stephane, I don’t have Hyper-V 2.0 running in my lab. All are running W2012 or W2012 R2!

      I need to check on that one!

      Thanks!
      Nirmal

  • Ramkumar says:

    Hi Nirmal,

    I was wondering why the VMs weren’t starting automatically though the appropriate option was selected.

    The selected option was “Always start this virtual machine automatically”.

    Kindly advise.

    • Zoran says:

      Hi Ram,
      In general you are correct, these VMs should start when this setting is enabled. One option is to check that there is enough available resources (memory, cpu, etc.) on the host to start the VM. Another reason could be if these VMs are marked as “Low Priority”, then they may be waiting for available resources. To investigate this further, please check out the Hyper-V event log and you should see details about if those VMs are attempting to start and why they failed.

      Thanks,
      Symon Perriman
      Altaro Editor

    • Hi Ramkumar,
      This is interesting, I haven’t seen this problem myself. It can sometimes take a little bit of time before each VM starts as Hyper-V is smart enough not to try booting lots of VMs all at the same time. However, if the VMs still aren’t starting after a few minutes something is amiss. There’s this Technet forum discussion thread where someone has the same problem as you, due to the iSCSI connected storage not having loaded when Hyper-V tried to start the VMs. What storage are your VMs disks on?

      Paul Schnackenburg, Altaro DOJO Technical Editor

  • Jonathan Knightly says:

    I think it is important to mention that when using the ‘Save the virtual machine state’ option as an Automatic Stop Action that a .VMRS file will be created for each VM using this setting. Each .VMRS file is connected to a specific VM and contains that VM’s RAM/Machine State, while the VM is on.

    The size of a .VMRS file is equal to the amount of RAM assigned to the VM it is associated to, regardless of how much RAM that VM is actually using. For example, if VM-1 is assigned 20GB of RAM, but is only using 4GB of RAM, your .VMRS file will still be 20GB while VM-1 is running.

    When the VM is not running, it’s .VMRS file is reduced to 48k. According to my research, the use of Dynamic Memory settings does not effect the behavior or size of the .VMRS file, although I have not personally tested this.

    Long story shorty, if you want to use the ‘Save the virtual machine state’ Automatic Stop Action, make sure to plan your disk space accordingly.

    *Note* It is not recommended to exclude .VMRS files from you server backups, as this can cause that VM to give a ‘The VM was shut down unexpectedly’ error message when you boot a VM restored from backup.

    Source: https://support.microsoft.com/en-us/topic/hyper-v-vss-backs-up-a-large-vmrs-file-when-you-back-up-a-virtual-machine-5e282626-f4a8-a5f3-a3ff-10e3794d98cc

Leave a comment or ask a question

Your email address will not be published. Required fields are marked *

Your email address will not be published.

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.