Enabling Jumbo Frames on Hyper-V 2008 R2 Virtual Switches

Enabling Jumbo Frames on Hyper-V 2008 R2 Virtual Switches

When using a Core version of Hyper-V 2008 R2, be it Hyper-V Server 2008 R2 or Windows Server 2008 R2 Standard Core, you are doing a good thing to conserve resources and minimize the attack footprint of your virtualization hosts. However this comes at a price. One of the most obvious misses in this matter is the enabling of Jumbo Frames on the Virtual Switch Interface. This enables your guests to reach out to storage directly using jumbo frames (mtu size of greater than 1500 bytes – however in this article we will be working specifically with 9000 bytes).

Basic Hyper-V Networking

So first let’s familiarize ourselves with basic Hyper-V networking. When a virtual network is created in Hyper-V it separates out the network interface of the parent partition (which is the source for the virtual switch) and duplicates that connection (Figure 1). The parent partition is then attached to the Virtual Switch in the same way as a guest is. Now for simplicity I like to name everything consistently. I generally have 2 storage networks (for multipathing) and before creating the switch I rename the interface to “Storage Primary (Switch)” or “Storage Secondary (Switch)” and then rename the newly created interface to “Storage Primary (Interface)” or “Storage Secondary (Interface)” this keeps my head on straight as far as what interfaces are the switches and what are the interfaces for the parent.

Figure 1 – Diagram of Hyper-V guest and parent network connectivity via virtual switch

Enabling Jumbo Frames on a non-core Hyper-V system

Now in order to enable jumbo frames on your network you must enable jumbo frames on the sender, the receiver and all network equipment in between. Now if I wanted to enable jumbo frames between VM1 and VM2 (on the same server) then I enable it on both guests and the Hyper-V switch and viola. So keep in mind that your storage and switches will need a bit of magic to get them going. So to display the procedure I will demonstrate on a non-core version (Figure 2).

Figure 2 – Steps to enable Jumbo Frames when using non-core version of Hyper-V

Enabling Jumbo Frames on a core Hyper-V system

Enabling jumbo frames on core is not easy. In fact it can be downright difficult. This change consists of two parts, enable jumbo frames on the interface, and enable jumbo frames in the registry. I recommend you do this when there is not a Virtual Switch created on the interface, it simplifies the registry portion.

Part 1 – Enable Jumbo Frames using netsh

netsh interface ipv4 set subinterface “Storage Primary (Switch)” mtu=9000 store=persistent

Part 2 – Enable Jumbo Frames using registry

Browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces each key in this location contains a GUID of a Network Interface. Looking inside each key we want to match the IPAddress to the interface GUID. We will need that GUID in a moment.

Figure 3 – Locating the Interface GUID

Now that we have found the GUID, browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\

You will see numerical 4-digit subkeys. Under each subkey find the “NetCfgInstanceID” string, you are looking for the subkey with the “NetCfgInstanceID” which matches the GUID you found earlier. Once you find this you can modify the “*JumboPacket” to show 9014 which will give it a 9000 mtu (14 are for the headers).

Give the host a reboot and enable jumbo frames on the guests and you should be able to verify with “ping -f -l 8972”

Script Please?

This sort of thing is begging to be scripted. So I have written a powershell script which will do both parts of the configuration automagically… You will need to ensure that you have a static IP address configured on the interface you want to configure.

Name       :  Set-JumboFrame.ps1
Version   :  1.1
MD5        :  59a1ef644035e268c6ed130e2258b8bc
SHA256  :  1a992307cd29d2460011a91c92b49a7e35563697be03d3c86f367cd8fc9e9d75
URL         :  http://code.allanglesit.net/powershell/Set-JumboFrame.ps1

# File Name: Set-JumboFrame.ps1
 # ========================================================
 # Created: March 24, 2010
 # Version: 1.1
 # Author: Matthew H. Mattoon
 # Website: http://blog.allanglesit.com
 # ========================================================
 # Purpose: Allows enabling/disabling of Jumbo Frames
 # settings automatically
 # PreReqs: 1) Interface must have a Static IP.
 # 2) To enable on a Hyper-V Virtual Switch
 # the Switch must not be created.
 # ========================================================
 # Examples: .\set-jumboframe.ps1
 # .\set-jumboframe.ps1 enable
 # .\set-jumboframe.ps1 disable
 # .\set-jumboframe.ps1 verify
 # ========================================================
 # v1.0 > v1.1 - March 29, 2010
 # 1) $FindAdapterProperties now only checks registry keys
 # for registry keys preceeded by a zero
 # 2) Added color to the Write-Hosts
 # ========================================================

param([string]$Mode = $(throw "Please specify enable, disable, or verify"),
 [string]$IPAddress = $(Read-Host -prompt "Enter the Static IP of the NIC to work with"))

Function VerifyJumboFrames ($IpAddress,$AdapterName,$CurrentJumboPacket)
 Write-Host -foregroundcolor yellow $IpAddress on $AdapterName currently has a MTU size of $CurrentJumboPacket

Function EnableJumboFrames ($IpAddress,$AdapterName,$CurrentJumboPacket,$AdapterProperties)
 $EnableRegJumboPacket = 9014
 $EnableCmdJumboPacket = "mtu=9000"
 Write-Host -foregroundcolor yellow $IpAddress on $AdapterName currently has a MTU size of $CurrentJumboPacket
 Write-Host -foregroundcolor cyan Modifying netsh MTU Settings...
 netsh interface ipv4 set subinterface $AdapterName $EnableCmdJumboPacket store=persistent
 Write-Host -foregroundcolor cyan Modifying Registry MTU Settings...
 Set-ItemProperty $AdapterProperties.PSPath -name "*JumboPacket" -value $EnableRegJumboPacket
 Write-Host -foregroundcolor red Enable Completed - Reboot is Required.

Function DisableJumboFrames ($IpAddress,$AdapterName,$CurrentJumboPacket,$AdapterProperties)
 $DisableRegJumboPacket = 1514
 $DisableCmdJumboPacket = "mtu=1500"
 Write-Host -foregroundcolor yellow $IpAddress on $AdapterName currently has a MTU size of $CurrentJumboPacket
 Write-Host -foregroundcolor cyan Modifying Registry MTU Settings...
 Set-ItemProperty $AdapterProperties.PSPath -name "*JumboPacket" -value $DisableRegJumboPacket
 Write-Host -foregroundcolor cyan Modifying netsh MTU Settings...
 netsh interface ipv4 set subinterface $AdapterName $DisableCmdJumboPacket store=persistent
 Write-Host -foregroundcolor red Disable Completed - Reboot is Required.

$FindInterfaceIndex = gwmi win32_networkAdapterConfiguration |where {$_.IPAddress -eq $IpAddress}
 $FindInterfaceGUID = gwmi win32_networkAdapter |where {$_.Index -eq $FindInterfaceIndex.Index}
 $GUID = $FindInterfaceGUID.GUID
 $FindAdapterName = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\$GUID\Connection"
 $AdapterName = $FindAdapterName.Name
 ## Legacy Code v1.0 $FindAdapterProperties = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\*\' |where {$_.NetCfgInstanceID -eq $guid}
 $FindAdapterProperties = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0*\' |where {$_.NetCfgInstanceID -eq $guid}
 $AdapterProperties = Get-ItemProperty $FindAdapterProperties.PSPath
 $CurrentJumboPacket = $AdapterProperties."*JumboPacket"

if ($Mode -eq "enable")
 EnableJumboFrames $IpAddress $AdapterName $CurrentJumboPacket $AdapterProperties
 elseif ($Mode -eq "disable")
 DisableJumboFrames $IpAddress $AdapterName $CurrentJumboPacket $AdapterProperties
 elseif ($Mode -eq "verify")
 VerifyJumboFrames $IpAddress $AdapterName $CurrentJumboPacket

Or thanks to Roberto Kekeny for the Portuguese translation as well as an appropriate write up available here.

Name       :  Configura-JumboFrame.ps1
Version   :  1.1
MD5        :  32674affc321d12fbc2843cc197612cf
SHA256  :  fb58e5ee5df459ac0d3316fd6616150734b7f2c0cbd4583ce4e4d7fc117d47ec
URL         :  http://code.allanglesit.net/powershell/Configura-JumboFrame.ps1


Install Powershell – “start /w ocsetup MicrosoftWindowsPowershell”

Enable Scripts to run in Powershell – “set-executionpolicy remotesigned”.

Execute Script Examples

· ./Set-JumboFrame.ps1 enable

· ./Set-JumboFrame.ps1 disable

· ./Set-JumboFrame.ps1 verify

After enabling jumbo frames you will need to create the virtual switch and reattach any guests to it.

So there you have it. This script provides a much simpler way of configuring jumbo frames on Hyper-V core virtual switches.

UPDATE Feb 2, 2013

I have migrated my scripts to a new location, and included MD5 and SHA256 sums on my code.