Simple SMB share and multichannel for Hyper-V

SMB 3.0 file shares can be used as shared storage for Hyper-V in Windows Server 2012 R2 and Windows Server 2012. With this capability, Hyper-V can store virtual machine files, which includes configuration, virtual hard disk (VHD) files, and snapshots, on SMB file shares. There a lot of configurations for SMB and Hyper-V (cluster Hyper-V + stand-alone SMB share, or cluster Hyper-V <> scale-out and etc.). This article covers basic steps for configuration SMB share for Hyper-V through powershell.

My demo: 2 hyper-v hosts (HV01.democorp.ru, HV02.democorp.ru), 1 file server (dc01.democorp.ru . !! it’s not recommended to make a SMB share on domain controller. it’s just a lab!!).  2 network adapters per server. File Server roles are installed by default.

#Create new SMB share on your file server (dc01 - my file server)
PS C:\Users\Administrator&gt; New-SmbShare -Name Hyperv -Path S:\Shares\VM -FullAccess democorp\administrator,democorp\hv01$,democorp\hv02$,democorp\hvcl$

Name                          ScopeName                     Path                          Description
----                          ---------                     ----                          -----------
Hyperv                        *                             S:\Shares\VM

#Check permissions
PS C:\Users\Administrator&gt; Get-SmbShareAccess hyperv

Name                    ScopeName               AccountName             AccessControlType       AccessRight
----                    ---------               -----------             -----------------       -----------
Hyperv                  *                       DEMOCORP\Administrator  Allow                   Full
Hyperv                  *                       DEMOCORP\HV01$          Allow                   Full
Hyperv                  *                       DEMOCORP\HV02$          Allow                   Full
Hyperv                  *                       DEMOCORP\hvcl$          Allow                   Full

#Set NTFS permissions from SMB share
PS C:\Users\Administrator&gt; Set-SmbPathAcl -ShareName hyperv

#Create new vhd on smb share
PS C:\Users\administrator.DEMOCORP&gt; New-VHD -Path \\dc01\Hyperv\VMs\test\testsmb.vhdx -Dynamic -SizeBytes 15Gb -Verbose
VERBOSE: Performing the operation &quot;New-VHD&quot; on target &quot;\\dc01\Hyperv\VMs\test\testsmb.vhdx&quot;

ComputerName            : HV01
Path                    : \\dc01\Hyperv\VMs\test\testsmb.vhdx
VhdFormat               : VHDX
VhdType                 : Dynamic
FileSize                : 4194304
Size                    : 16106127360
MinimumSize             :
LogicalSectorSize       : 512
PhysicalSectorSize      : 4096
BlockSize               : 33554432
ParentPath              :
DiskIdentifier          : 82453f86-1d5a-421f-890b-0a76366f4cbb
FragmentationPercentage : 0
Alignment               : 1
Attached                : False
DiskNumber              :
Key                     :
IsDeleted               : False
Number                  :

#Create new VM on share
PS C:\Users\administrator.DEMOCORP&gt; New-VM -Name VMtest -SwitchName VM -VHDPath \\dc01\Hyperv\VMs\test\testsmb.vhdx -Path \\dc01\hyperv\vms -MemoryStartupBytes 1Gb -Generation 2 -Verbose

VERBOSE: New-VM will create a new virtual machine &quot;VMtest&quot;.

Name   State CPUUsage(%) MemoryAssigned(M) Uptime   Status
----   ----- ----------- ----------------- ------   ------
VMtest Off   0           0                 00:00:00 Operating normally

#Add VM to cluster
PS C:\Users\administrator.DEMOCORP&gt; Add-ClusterVirtualMachineRole -VirtualMachine VMTest -Name &quot;SMB TEST&quot; -Verbose
VERBOSE: Connecting to cluster on local computer HV01.

Name                                    OwnerNode                               State
----                                    ---------                               -----
SMB TEST                                HV01                                    Offline

#Check that VM was become HA
PS C:\Users\administrator.DEMOCORP&gt; (Get-ClusterResource).Name
Cluster IP Address
Cluster Name
Virtual Machine Configuration New Virtual Machine
Virtual Machine Configuration VMtest
Virtual Machine New Virtual Machine
Virtual Machine VMtest

#Move VM storage from local storage to the SMB share
PS C:\Users\administrator.DEMOCORP&gt; Move-VMStorage &quot;new virtual machine&quot; -DestinationStoragePath \\dc01\hyperv\VMs -ComputerName hv02 -Verbose
VERBOSE: Move-VMStorage will migrate the storage for virtual machine &quot;New Virtual Machine&quot;.

#Check smb connections on hv02
PS C:\Users\administrator.DEMOCORP&gt; Get-SmbConnection

ServerName          ShareName           UserName            Credential          Dialect             NumOpens
----------          ---------           --------            ----------          -------             --------
dc01                hyperv              DEMOCORP\Adminis... DEMOCORP.RU\Admi... 3.02                2
dc01                hyperv              DEMOCORP\HV02$      DEMOCORP.RU\HV02$   3.02                4
dc01                hyperv              NT VIRTUAL MACHI... DEMOCORP.RU\HV02$   3.02                2

#Checks that smb multichannel works
PS C:\Users\administrator.DEMOCORP&gt; Get-SmbMultichannelConnection

Server Name    Selected       Client IP      Server IP      Client         Server         Client RSS     Client RDMA
                                                            Interface      Interface      Capable        Capable
                                                            Index          Index
-----------    --------       ---------      ---------      -------------- -------------- -------------- --------------
dc01           True           192.168.1.96   192.168.1.201  23             13             False          False
dc01           True           10.10.25.22    10.10.25.1     22             12             False          False

#Get information about client networks interfaces
Get-SmbClientNetworkInterface

SMB Multichannel:

Virtual adapter vEthernet (CSV):

speed

+ Virtual adapter vEthernet (Management):

speed_1

~ 200 Mbps using 2×100 Mb adapters

smb-multi-channel

Troubleshooting

If you receive” “General Access denied error” during VM creation or migration, you have to check permissions on SMB share (my share is “Hyperv” + HV01 and HV02 are smb clients) and constrained delegation (notice that you must have installed Active Directory powershell module):

Get-SmbShareAccess Hyperv

Grant-SmbShareAccess -Name Hyperv -AccountName domain\comp$ -AccessRight Full

Enable-SMBDelegation -SmbServer dc01 -SMBClient HV01

Enable-SMBDelegation -SmbServer dc01 -SMBClient HV02

Enable-SMBDelegation -SmbServer dc01 -SMBClient HVCL

smb_hyperv_error

SMB Multichannel:

Multichannel should be enabled (see client and server configuration)

2 or more network adapters

OR

1 or more NICs capable with RSS

OR

1 or more NICs capable with RDMA

OR

NIC Teaming (at least 2 NICs)

PS C:\Users\Administrator&gt; Get-SmbClientConfiguration

.........
EnableMultiChannel                    : True
DormantFileLimit                      : 1023
EnableSecuritySignature               : True
ExtendedSessionTimeout                : 1000
FileInfoCacheEntriesMax               : 64

PS C:\Users\Administrator&gt; Get-SmbServerConfiguration

----
...................................

EnableLeasing                   : True
EnableMultiChannel              : True
EnableStrictNameChecking        : True
OplockBreakWait                 : 35
PendingClientTimeoutInSeconds   : 120
RequireSecuritySignature        : True
EnableSMB1Protocol              : True
EnableSMB2Protocol              : True
Smb2CreditsMax                  : 2048
Smb2CreditsMin                  : 128

PS C:\Users\Administrator&gt; Get-SmbServerNetworkInterface

Scope Name          Interface Index     RSS Capable         RDMA Capable        Speed               IpAddress
----------          ---------------     -----------         ------------        -----               ---------
*                   13                  True                False               100 Mbps            192.168.1.201
*                   13                  True                False               100 Mbps            fe80::590e:87d7:...
*                   12                  True                False               100 Mbps            10.10.25.1
*                   12                  True                False               100 Mbps            fe80::34ce:f145:...

Hyper-V 3.0 interaction with registry and how it was in 2008 R2

Russian version/Русская версия

Virtual machine configuration is stored in XML-file and Hyper-V (Virtual Machine Management Service) always maintains (read/write queries) this file when some changes occurs. No doubt, XML-file is the most important file for every VM. It’s true, but Hyper-V operates with registry so often as with XML. I prefer to say , Hyper-V has a “mirror of some VM configuration” in the registry (especially, in the previous versions of Windows Server) .The main target of this post is to show you  how Hyper-V works together with XML and registry. I use powershell cmdlets from Hyper-V module and some test VMs. At the end of article, I describe differences between registry hives , related with Hyper-V in 2008 R2 and 2012.

Let’s start with the the most simple operation for every Hyper-V administrator

Creating a basic VM (no vhd, no connected adapters):

PS C:\Windows\system32> New-VM -Name WikiTest1 -NoVHD -Generation 2

Name      State CPUUsage(%) MemoryAssigned(M) Uptime   Status
----      ----- ----------- ----------------- ------   ------
WikiTest1 Off   0           0                 00:00:00 Operating normally

Virtual Machine Management server (VMMS) sends a query CreateFile  that creates VM_GUID.XML  file in the folder  Virtual Machines (by default), in my case for my VM WikiTest1 was created file EF259B05-2CDE-4317-8ACF-E80CB364D66C.xml. If we add additional network adapter without VM switch connection, VMMS sends a query WriteFile and updates our XML-file with the new synthetic adapter  (note that PortName and SwitchName are empty):

<type_id type="string">Virtual Machines</type_id>
    <version type="integer">1280</version>
  </properties>
  <settings>
    <global>
      <logical_id type="string">EF259B05-2CDE-4317-8ACF-E80CB364D66C</logical_id>
    </global>
         .
    <PortName type="string"></PortName>
    <SwitchName type="string"></SwitchName>
         .
<vdev013>
      <device type="string">2fc216b0-d2e2-4967-9b6d-b8a5c9ca2778</device>
      <flags type="integer">1</flags>
      <instance type="string">1314FBB0-9385-44B7-8DDE-18D4118EFDDD</instance>
      <name type="string">Synthetic Ethernet Port</name>
    </vdev013>

Connecting VM to Hyper-V switch

PS C:\Windows\system32> Connect-VMNetworkAdapter -VMName WikiTest1 -SwitchName VM

VMMS sends query WriteFile and updates XML-file (IsConnected=True, PortName+SwitchName with GUIDs :

<IsConnected type="bool">True</IsConnected>
 <MacAddress type="string">00-00-00-00-00-00</MacAddress>
 <MacAddressIsStatic type="bool">False</MacAddressIsStatic>
 <PortName type="string">6FAC595A-2507-4690-A840-5746B09D81A1</PortName>
 <SwitchName type="string">FDDD2A3C-85E3-4807-9E28-7A40C8D494A7</SwitchName>

But It’s not enough and VMMS (with vmswitch.sys) creates new registry hives (RegCreateKey, RegSetValue queries) for every PortName in the SwitchName hive:

HKLM\System\CurrentControlSet\Services\VMSMP\Parameters\SwitchList\FDDD2A3C-85E3-4807-9E28-7A40C8D494A7\6FAC595A-2507-4690-A840-5746B09D81A1\

hyperv_regedit

Match PortName and SwitchName from XML and GUIDs in the registry hive – they are certainly identical. SwitchName  has a constant UID (one for every hyper-v switch) and it is fixed for all VMs. PortName characterizes each dedicated port (port is an interpretation of “Virtual Adapter” term) on the hyper-v virtual switch.

Note: HKLM\System\CurrentControlSet\Services is also a registry hive where Hyper-V keeps general settings for Integration Services and VMMS

Note: if you decide to disconnect VM from hyper-v switch ,  only “IsConnected” flag  in the XML configuration file sets from True to  False (PortName and SwitchName are with their last values ).And if you reconnect VM again , VMMS rewrites XML with the absolutely new PortName UID

Configuring VLANs on port

PS C:\Windows\system32> Set-VMNetworkAdapterVlan -VMName WikiTest1 -Trunk -AllowedVlanIdList 10-20 -NativeVlanId 15

VMMS creates new subhive under the virtual switch hive

HKLM\System\CurrentControlSet\Services\VMSMP\Parameters\SwitchList\FDDD2A3C-85E3-4807-9E28-7A40C8D494A7\6FAC595A-2507-4690-A840-5746B09D81A1\Properties\{952c5004-4465-451c-8cb8-fa9ab382b773} , for keeping VLAN settings for PortName 6FA.. on the Switch with UID FDDD…

VMMS also updates XML file with feature references and data block for VLANs (feature ID = UID of created RegValues):

  <Feature_952C5004-4465-451C-8CB8-FA9AB382B773>
        <DisplayName type="string">Ethernet Switch Port VLAN Settings</DisplayName>
        <Flags type="integer">0</Flags>
        <Setting_958A1AF7-327C-42F4-8864-517617BDE876>
        <Data type="bytes">AgAAAAAADwAAAAAAAAAAAAAAAAAAAAAACwAAACgAAAAAAAAAAAAAAAoACwAMAA0A
DgAPABAAEQASABMAFAA=
</Data>
</Setting_958A1AF7-327C-42F4-8864-517617BDE876>
       <Settings>
         <Id type="string">958A1AF7-327C-42F4-8864-517617BDE876</Id>
       </Settings>
     </Feature_952C5004-4465-451C-8CB8-FA9AB382B773>
     <Feature_C885BFD1-ABB7-418F-8163-9F379C9F7166>

Mirror of configuration” in the Registry (VLAN Settings in the REG_BINARY):

hyperv_regedit_1

How it was in 2008 R2?

​In 2008 R2 VM “mirror of configuration”  in the registry was different (even want to say “completely different”). When you create a VM and connect one to the virtual switch, VMMS updates in XML PortName + SwitchName values  and creates new RegValues in the registry with the only difference being that the setting VLAN (mostly) in pure form (REG_DWORD) are located in the registry. Within the XML we can see only references to GUIDs of these parameters. We do not see here any VLAN settings, neither feature with data blocks.

Reg_DWORD values for VLAN Settings (AccessVlanId = VLAN ID in the VM network adapter properties):

hyperv_regedit_2008

Ok, so what? As you know, the main difference between VM import/export in 2008 R2 and 2012 is the required existence of the EXP-file for a successful import (in 2012/R2 we do not need it). EXP-file is created in the process of exporting the VM and provides additional configuration information (guess what!?).

Hint (excerpt from exp-file for VM with VlanID 25):

<VALUE.OBJECT><INSTANCE CLASSNAME="Msvm_VLANEndpointSettingData"><PROPERTY NAME="AccessVLAN" TYPE="uint16"><VALUE>25</VALUE></PROPERTY>