Hyper-V now has Virtual Machines with Batteries

In the Windows 10 Fall Creators update we added a new feature.  Hyper-V now has virtual machines with batteries!

In Windows 10, Hyper-V now has virtual machines with batteries

Why does Hyper-V now have Virtual Machines with Batteries?

You might be wondering: why did we add batteries to virtual machines?  The answer is that over the last year we have spent a lot of time talking to developers about how they use virtual machines, and have tried to understand what they would like to see to make Hyper-V easier to use.  We have learned a whole bunch of stuff while doing this. One set of data is as follows:

  1. Many developers use virtual machines on their laptops.
  2. When using virtual machines on their laptops, developers tend to run them in full screen mode.
  3. When running virtual machines in full screen mode on their laptops, many developers have run out of power without realizing it.

The result is lost work and much anger at Hyper-V.  The solution is to expose a battery into the virtual machine, so that even when it is in full screen mode you can still see what is going on.

How do you get a battery in your virtual machine?

A virtual machine battery is a new piece of virtual hardware.  To get it you need to have a virtual machine with the latest version.  8.2 to be specific.  There are two ways to get an 8.2 version virtual machine. You can:

  1. Create a new virtual machine after installing the Windows 10 Fall Creators update.
  2. Use either Hyper-V Manager or Hyper-V PowerShell to upgrade an existing virtual machine.  Note; in order to do this the virtual machine must be turned off.

Once you have done this,  if the virtual machine is started on a physical computer with a battery it will have a virtual battery.

How exactly do we create Virtual Machines with Batteries?

At a high level, we have created a virtual battery that is now connected to the virtual machine.  This virtual battery reflects information from the physical computer into the virtual machine.  Any operating system that supports having a battery will display battery information, because this is done at the virtual hardware layer.

To give you some insight into what we do at a lower level, I am going to use the BatteryInfoView tool from NirSoft.  Here you can see it running side-by-side on my laptop.  The window on the left is running inside the virtual machine.  The window on the right is running on the physical computer.

A battery diagnosis tool in the host and in a virtual machine showing information.

Looking at this you can see a bunch of differences, and some similarities.  Both systems have the same Power State (“AC Power” in this case).  Both systems also show the same Current Capacity (in %).  After that though, pretty much everything else is different.

There are a number of reasons for this:

  1. Percentage Charge and Power State are the only two things we need to provide to solve the primary problem; low battery power catching users by surprise.
  2. People move virtual machines around.  We want to make sure that as virtual machines move between systems with different batteries, there are no problems.
  3. We do not want to have any hardware specific software trying to tinker with the virtual battery.
  4. Some systems have rather complicated batteries.  For instance, some laptops have multiple batteries (when we are on such systems – we calculate the sum total percentage charge).

My favorite detail about our virtual battery is the Chemistry.  It is “Virt” powered, not something like Lithium Ion.

What are the edge cases to know about with Virtual Machines with Batteries?

There are a couple areas where things are not quite perfect.  The first one is around estimates for amount of battery time remaining.  Below I have another picture of the BatteryInfoView tool, but this time I have unplugged the power from my laptop.

A battery diagnosis tool in the host and in a virtual machine showing information - when the power is disconnected from the host.

Both systems know that they are disconnected.  They also both know that the current battery charge rate is 94%.  However, the virtual machine believes it only has 1:05:34 until the battery is flat while the physical computer believes that it has 1:30:46.  This is a side effect of how we “virtualize” the battery capacity, etc… and is ultimately harmless.

Another situation is if you move a virtual machine between computers with and without batteries.

When you start a virtual machine, we check to see if the physical computer has a battery.  If it does, we attach a battery to the virtual machine.  If it does not, we do not.  But what happens if you start a virtual machine, put it into a saved state, move it to another computer, and then start it again?

Well –

  1. If both physical computers have batteries – nothing happens.
  2. Similarly, If both physical computers do not have batteries – nothing happens.
  3. However, If the source physical computer does not have a battery and the destination computer has a battery, then the virtual machine will have no battery.  Until it is turned off and booted again.
  4. Finally, If the source physical computer has a battery and the destination computer does not have a battery – this happens:

What you see inside the virtual machine if it thinks it has a battery, but the host does not.

The virtual machine is plugged in and the battery is… a bit overcharged.  The battery will be removed when the virtual machine is turned off and booted again.

One final tip for working with Virtual Machines with Batteries

If you are the sort of person who regularly takes your laptop to the limit and often see Windows shutting down on you as you are out of power, you may want to consider this tip.  Go into the Power Options inside the virtual machine and set Windows to shutdown when the battery hits 15%.  This will ensure that your virtual machine is shutdown cleanly when your physical computer hits the default 10% battery alert.


Leave a Reply


XBOX one stats

Steam – Recently Played

No Steam games played recently


GiottoPress by Enrique Chavez