Tag Archives: Windows Server 8

SMB Bandwidth Limits and Shared Nothing Live Migration

This week I have been discussing the network QoS options available for a Windows Server private cloud.  On Wednesday I talked about the SMB bandwidth limit capability – that allows you to specify separate bandwidth limits for virtual machine storage and live migration traffic over SMB.  One interesting thing to understand is how this effects shared nothing Live Migration.

A shared nothing live migration performs a synchronized storage migration and memory migration for the virtual machine.

In this scenario, the storage migration traffic of a shared nothing Live Migration (and indeed any storage migration traffic) is tracked by the virtual machine storage SMB bandwidth limit – not the Live Migration SMB bandwidth limit.  The Live Migration SMB bandwidth limit only applies to the memory transfer of any virtual machine Live Migration.

Cheers,
Ben

Converged Network QoS and Live Migration over SMB

On Monday I gave you a pointer to a great resource on configuring network QoS in converged networking configurations.  One thing that this documentation does not cover is how to configure QoS for Live Migration over SMB.

If you are using Live Migration over SMB, and storing virtual machine hard drives on SMB shares, then both of these traffic flows will be covered by the SMB QoS policy.  However, they should not be treated the same.  Live Migration is designed to use all the network bandwidth it can – and some of that bandwidth needs to be reserved for virtual machine storage traffic.  Fortunately, Windows Server 2012 R2 includes tools that allow you to do just this.

Jose Barreto discusses this in detail on his blog post here: http://blogs.technet.com/b/josebda/archive/2014/08/11/smb3-powershell-changes-in-windows-server-2012-r2-smb-bandwidth-limits.aspx

The SMB Bandwidth Limits feature can be installed with either Server Manager or PowerShell.  Once installed – you can use the “Set-SMBBandwidthLimit” parameter to restrict the maximum throughput of Live Migration.

But what is the right limit to set?  That is hard to say, and varies from deployment to deployment.  On one hand – if you set the limit too low, you will slow down Live Migration in your environment. If you set it too high – you will see storage performance impacts while Live Migrating virtual machines.  Personally, I would recommend setting this to between 60 and 80% of the available network bandwidth. 

Cheers,
Ben

Getting QoS Right with Hyper-V and Converged Networking

Back in the “olden days” of Windows Server 2008 R2, getting networking right for a Hyper-V private cloud was simple.  Annoying – yes.  But simple.  Basically – you just had to have a separate network adapter (or two) for every class of traffic possible.

Thankfully with Windows Server 2012 (and 2012 R2) there are a number of ways to converge networking and you can now effectively run on only two of four network adapters.  While this is nice – it does raise a problem: how do you make sure that everyone gets the network bandwidth that they need?

You see – the different classes of traffic in a Hyper-V private cloud have very different behaviors and requirements.

  • Some are low bandwidth – but critical (like the cluster heart beat and remote management)
  • Some are medium to high bandwidth – and fairly constant (like virtual machine storage)
  • Some are high bandwidth – but sporadic (like live migration)

And making everything work smoothly can be challenging.  Fortunately we have some great documentation that is available here:

https://technet.microsoft.com/en-us/library/jj735302.aspx

This steps through some of the common converged network configuration that we see – and tells you how to configure QoS (quality of service) settings to ensure that the right thing happens in your environment.

Cheers,
Ben

 

Microsoft Virtual Machine Converter 3.0 Now Available

Yesterday we released the Microsoft Virtual Machine Converter 3.0.  You can download it here: http://www.microsoft.com/en-us/download/details.aspx?id=42497

It has a staggering amount of features.  Including the ability to convert physical computers to virtual machines and to convert VMware virtual machines to Hyper-V virtual machines online and offline.

Cheers,
Ben

Programmatically Detecting when a VM Changes State

Every now and then I get asked how to detect whenever a virtual machine changes state.  Usually, people who ask about this have written some code that periodically queries Hyper-V to see what state different virtual machines are in (stopped, running, etc.).  What they find is that this is not efficient – and it sometimes misses a virtual machine that has quickly changed state (e.g. stopped and started again).

Luckily, there is a way to be notified of virtual machine state changes without polling for information.

To do this – you want to use WMI instance modification events:

# WMI Query that specifies what events we will watch for

$Query = "Select * from __InstanceModificationEvent within 3 where TargetInstance ISA 'MSVM_ComputerSystem' `

          and TargetInstance.EnabledState  PreviousInstance.EnabledState"

 

# Script block that will run whenever the event fires

[ScriptBlock]$Action = {

   $VMName = $Event.SourceEventArgs.NewEvent.TargetInstance.ElementName

 

   switch ($Event.SourceEventArgs.NewEvent.TargetInstance.EnabledState)

      {

        2 {$vmState = "running"}

        3 {$vmState = "turned off"}

        9 {$vmState = "paused"}

        6 {$vmState = "in a saved state"}

        10 {$vmState = "starting"}

        4 {$vmState = "stopping"}

        default {$vmState = "in an unknown state..."}

       }

 

   if ($Event.SourceEventArgs.NewEvent.TargetInstance.EnabledState -eq 1)

      {$vmState = $Event.SourceEventArgs.NewEvent.TargetInstance.OtherEnabledState}

 

   write-host "The virtual machine '$($vmName)' is now $($vmState)."}

 

# Register for the events

Register-WMIEvent -Query $Query -Action $Action -Namespace rootvirtualizationv2

 

# To clean up - run "Get-EventSubscriber | Unregister-Event"

This code will print out a message whenever a virtual machine changes state.

Cheers,
Ben

Setting up non-administrative control of Hyper-V through PowerShell–Updated

Yesterday, I told you about how it was now easier to allow a non-administrative user to control Hyper-V.  This is nice – but it does mean that this script that I blogged about 4 years ago no longer works.  Here is a new one:

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()

$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

 

# Get the security principal for the Administrator role

$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

 

# Check to see if we are currently running "as Administrator"

if ($myWindowsPrincipal.IsInRole($adminRole))

   {

   # We are running "as Administrator" - so change the title and background color to indicate this

   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"

   $Host.UI.RawUI.BackgroundColor = "DarkBlue"

   clear-host

   }

else

   {

   # We are not running "as Administrator" - so relaunch as administrator

 

   # Create a new process object that starts PowerShell

   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";

 

   # Specify the current script path and name as a parameter

   $newProcess.Arguments = $myInvocation.MyCommand.Definition;

 

   # Indicate that the process should be elevated

   $newProcess.Verb = "runas";

 

   # Start the new process

   [System.Diagnostics.Process]::Start($newProcess);

 

   # Exit from the current, unelevated, process

   exit

   }

 

# Prompt for the virtual machine to use

$Domain = Read-Host "Specify the domain of the user to add to Hyper-V Administrators (use $($env:ComputerName) for this computer)"

 

# Prompt for the path to export to

$User = Read-Host "Specify the username of the user to add to Hyper-V Administrators"

 

$HvAdmins = [ADSI]"WinNT://$env:COMPUTERNAME/Hyper-V Administrators,group"

$HvAdmins.Add("WinNT://$($Domain)/$($user),user")

This script will add any user you specify to the local “Hyper-V Administrators” group.

Cheers,
Ben

Allowing non-Administrators to control Hyper-V–Updated

A long time ago, I did a post about how to allow non-Administrative users to control Hyper-V.  Then I did a post that showed you how to script this whole configuration.  Finally, I did a post that showed you how to setup a “Hyper-V Administrators” group to make the whole process easier.

Well, time has passed and we have made things significantly easier for you here.

With Windows 8, Windows 8.1, Windows Server 2012 and Windows Server 2012 R2 you will now find that the Hyper-V Administrators group is already present:

image

All you need to do these days is to add your user account to the Hyper-V Administrators account, and you can do everything with Hyper-V without having to be a local administrator on the system.

Cheers,
Ben

Looking for Wasted Space inside Virtual Machines

Recently, I tried to update the operating system installed inside of one of my virtual machines.  I quickly received an error message stating that I did not have enough free space available to perform the upgrade.  My immediate thought was that I would need to expand the size of the virtual hard disk – but after a bit of investigation I was surprised to discover that the virtual hard disk had already been expanded.  I just hadn’t expanded the partition to take advantage of it.

Clearly, I had been planning to do this at some other time – and had gotten distracted in the middle of the process.

This made me wonder: do I have any other virtual machines that are sitting on unpartitioned, wasted space?

Luckily, this is an easy question to answer.  You see, the virtual hard disk object that is returned by “Get-VHD” includes a “MinimumSize” property.  This property will tell you how much unpartitioned space is available at the end of the disk.  So the following command:

Get-VM | Get-VMHardDiskDrive | Get-VHD | Select path, @{Name=”Free Space (GB)”;Expression={“{0:N2}” -f (($_.Size – $_.MinimumSize)/1GB)}}

Will tell you exactly what is going on with your system.  When I ran this on my server:

image

I discovered that I had two extra virtual machines with wasted space!

Cheers,
Ben

Exporting a Virtual Machine Checkpoint

Something neat that you can do in Windows Server 2012 / Windows 8 or later is to export a virtual machine checkpoint.  You can do this by either:

  1. Selecting the checkpoint in the UI and selecting Export from the action pane
  2. Using the Export-VMSnapshot cmdlet

When you do this, we will actually create an exported virtual machine that represents just the checkpoint you selected.  This means that we will merge all the changes from the checkpoint into a single set of virtual hard disks – so that you can create a new virtual machine from that point in time without having to include other checkpoints.

Cheers,
Ben

Importing a VM with VHDs in Different Paths

I was recently given an interesting challenge.  I was asked to show how you could use PowerShell to import a virtual machine; where the virtual hard disks were stored in multiple different locations.  Now, if the virtual hard disks were all in a single location, you could just use the “VHDSourcePath” parameter on Import-VM to let Hyper-V know where to look.  But this does not work if the virtual hard disks are in multiple different locations.

To handle this situation – you need to use Compare-VM (as I discussed here).

import vhds

The process I followed to do this is:

  1. Use Compare-VM to create a virtual machine compatibility report.  Like this:

    $vmReport = compare-vm “C:Usersbenja_000DesktopExported VMImport Test VMVirtual MachinesCCAE6F7E-B9FD-474B-9D08-A7011940C217.XML” -Copy –GenerateNewId

  2. List the incompatibilities and see that there are two virtual hard disks that have not been found.
  3. Look at .Source.Path on each incompatibility to determine which virtual hard disk is missing
  4. Use Set-VMHardDiskDrive to correct the location for the first virtual hard disk:

    Set-VMHardDiskDrive $vmReport.Incompatibilities[0].Source -Path “C:Usersbenja_000DesktopExported VMImport Test VMVirtual Hard DisksaImport Test VM.vhdx”

  5. Use Set-VMHardDiskDrive to correct the location for the second virtual hard disk:

    Set-VMHardDiskDrive $vmReport.Incompatibilities[1].Source -Path “C:Usersbenja_000DesktopExported VMImport Test VMVirtual Hard DisksbAnother VHDX.VHDX”

  6. Finally use Import-VM with the corrected virtual machine compatibility report

Now the virtual machine is imported and ready to go.

Cheers,
Ben