Shutting down a virtual machine

What happens when you use the Virtual PC / Virtual Server / Hyper-V user interface to shut down a virtual machine?

At the simplest level – we send a message over to the virtual machine that asks the guest operating system to shut down, and then we wait.

But this is where things get a little tricky.

We can send a request to shut down the guest operating system, and we can know whether the request to shut down was received or not.  But once the shut down process begins – we have no idea what is happening.  This comes from two issues:

  1. Almost no operating system today has a method for reporting shut down progress.  They just try to shut down as quickly as possible.
  2. At some stage during the shut down process the guest operating system will shut down the components that we have running inside the virtual machine that allow us to monitor what is going on.

So instead of trying to monitor the shut down process – we just fake it.

When you select to shut down a virtual machine – we send the request to shut down.  Once we receive confirmation that the operating system has started shutting down we display a progress bar in the user interface.  This progress bar is 100% fake.  All that we are doing is watching to see if the virtual machine turns off, and counting to 5 minutes.  We slowly increase the progress of the fake progress bar – and if we see the virtual machine turn off by itself we assume that shut down was successful.  We then set the progress bar to 100% and report that shut down was successful.

If the 5 minute timer is met and the virtual machine has not shut down – this can pose another problem for us.  It is highly likely that, while the virtual machine machine has failed to shut down, our integration services have been stopped.  This means that we may not be able to issue a second request to shut down.

Because of this, if the virtual machine is still running after 5 minutes – we report that shutdown has failed and that you should go and have a look at at.  This can lead to a strange experience if the virtual machine takes just over 5 minutes to shut down – as this will result in us displaying an error message moments before success.

We have discussed the idea of simulating an ACPI power off command instead of using an integration service.  This would make shutting down a virtual machine with the shut down button equivalent to hitting the power button on a modern computer.  The problem with this approach is that you can configure most operating systems to do nothing when the power button is pressed – which would be confusing for the end user.