At Your Service! Out-of-Band VM Updates with Guest Services in Windows Server 2012 R2 Hyper-V

This month, my team of fellow IT Pro Technical Evangelists are publishing a series of articles on Why Windows Server 2012 R2? that highlights the key enhancements and new capabilities that we're seeing driving particular interest in this latest release of our Windows Server operating system in the field.  After reading this article, be sure to catch the full series at:

Hyper-V in Windows Server 2012 R2 has had a number of significant improvements, which we’ve been discussing in many of the articles throughout this series.  However, there’s a particular new Hyper-V feature that, while very useful, has had significantly less fanfare: Guest Services.

image
Hyper-V Guest Services: At Your Beck-and-Call for VM File Updates

In this article, I’ll provide an overview of Hyper-V Guest Services and also step through a real-world example of how it can be used to perform out-of-band file updates inside running virtual machines.

What is Hyper-V Guest Services?

Guest Services is introduced in Windows Server 2012 R2 Hyper-V as a new component of Hyper-V Integration Services, the virtual machine tooling that get installed inside each VM to provide tight integration with the underlying host environment.  If you have kept a keen eye after upgrading to R2, you may have seen Guest Services show up on 2012 R2 Hyper-V Hosts within the settings of each VM on the Integration Services page. 

image
Guest Services in Hyper-V Integration Services on Windows Server 2012 R2 Hyper-V

You’ll note that while Guest Services is present as a new Integration Services component, it’s unchecked by default on VM’s. Guest services can be enabled on a per-VM basis on Windows Server 2012 R2 Hyper-V simply by checking the related checkbox and clicking the Apply button.  Alternatively, we’ll walk through a method later in this article to enable and disable Guest Services on several VM’s at once via PowerShell.

But … What does Guest Services do?

When enabled, Guest Services provides the ability to copy files into running VM’s using a process that is out-of-band to any virtual network connections those VM’s may have.  This means that we can copy and update files inside VM’s even in situations where those VM’s are disconnected from any virtual networks, are connected to Private virtual network switches, or are located on networks that are isolated from the underlying host using VLANs or Hyper-V Network Virtualization (HNV).

How does Guest Services perform out-of-band file copies?

Instead of using virtual network switch connections and shared folders to transfer files into each VM, Guest Services instead copies the files across the Hyper-V Virtual Machine Bus (VMBus) to which each VM is connected for high-speed host device driver access.  By leveraging the VMBus for file copies, Guest Services makes it really easy to keep files inside VM’s up-to-date regardless of the state of VM network connectivity.

What are some sample scenarios for Guest Services?

There’s several scenarios where Guest Services can come in handy, such as copying or updating files inside VM’s that are configured for:

  • Isolated development environments
  • Web or FTP servers that are on a perimeter network
  • Virtual networks that are in isolated security zones
  • Lab networks used for preparing VM images

… and MORE!

How do I use Guest Services?

In order to use Guest Services, this component first needs to be enabled on each VM to which you’ll be copying files.  To enable Guest Services on each VM, you can configure the checkbox setting noted in this article above for each VM. Alternatively, you can enable Guest Services from within a PowerShell script by using the Enable-VMIntegrationService cmdlet.

Get-VM –Name VM_NAME | Enable-VMIntegrationService -Name "Guest Service Interface"

Once Guest Services is enabled, the Hyper-V Guest Service Interface service inside the enabled VM is started automatically.  You can confirm this on Windows VM's by using the Get-Service cmdlet:

Get-Service -ComputerName VM_NAME –DisplayName “Hyper-V Guest Service Interface”

For efficiency, you can also enable Guest Services for all VM’s on a Hyper-V host in one command line by simply omitting the VM_Name parameter, such as:

Get-VM | Enable-VMIntegrationService -Name "Guest Service Interface"

And … you can then check to make sure it was properly enabled across all VM’s with the Get-VMIntegrationService cmdlet.

Get-VM | Get-VMIntegrationService

After Guest Services is enabled on one or more VM’s on a Hyper-V host, the Copy-VMFile cmdlet can be used to copy files from the host into the VM’s.  For example, to copy the Server Manager ServerList.xml file referenced in my prior article this week to all VM’s on a Hyper-V host, you can use the following command line:

Get-VM | Copy-VMFile -SourcePath "$env:APPDATA\Microsoft\Windows\ServerManager\ServerList.xml" -DestinationPath "$env:APPDATA\Microsoft\Windows\ServerManager\ServerList.xml" -CreateFullPath -FileSource Host -Force

This single command line will copy a centralized ServerList.xml file to each VM, so that when Server Manager is launched from within any VM, it will be working from the same exact set of managed servers.

While this is a simple example pertaining to the Server Manager management tool, a similar approach could be used to deploy new Web.Config files across IIS Web Server VM's or standard Visual Studio solution files into development environment VM’s. There's lots of cool scenarios where Guest Services can make it super-easy to keep files inside VM's up-to-date!

After you’ve completed the process of updating files inside the VM’s, Guest Services can be disabled, if preferred.  You can disable Guest Services on each VM by using the Disable-VMIntegrationService cmdlet.

Get-VM | Disable-VMIntegrationService -Name "Guest Service Interface"

By leveraging these few cmdlets, it’s really easy to build a set of small PowerShell scripts that can be used to quickly perform out-of-band file updates to VM’s on a regular basis.

Share Your Scenarios!

What are you thoughts regarding the new Guest Services component in Windows Server 2012 R2 Hyper-V? Do you have other unique scenarios for which this could be useful? Feel free to share your thoughts in the Comments area below!

Other resources in which you may have interest …