I believe in Hyper-V!

Romeo MlinarAuthor Archives

Virtual disks under Storage Spaces won’t stay attached after reboot!

Few days ago friend of mine asked me if I know how to fix this issue and I succeeded. Now I want to share with all of you.
The scenario is as follows…

Windows Server 2012 R2, one Storage Pool, few virtual disks. The behavior starts to happen after Windows Server 2012 R2 re-installation. Everything was fine until restart. Virtual Disks are present and attached but after restart the server they are detached.

Before restart.10

After restart
10

If you are looking under virtual disk Properties/Details/Property (look picture below) you will notice that IsManualAttach – Value is True. In other words, if you want virtual disk be attached you must do manually attach.

10

Resolution

Open PowerShell as administrator, type as follows and press Enter

Set-virtualdisk -FriendlyName <VirtualDiskName> -IsManualAttach $false

10

Refresh Server Manager Console and you Virtual Disks will be attached. After you restart your server Virtual Disks still be attached ;)

10
10

I wish you all the best in 2014!

Enjoy the day :)

Cheers!

Romeo

Create HA virtual network for Hyper-V in Windows Server 2012 R2

In this blog post I’d like to explain how to create highly available virtual network for Hyper-V virtual machines as well as for Hyper-V hosts and other services related on virtual machines.
Not that log ago practice was; you have to have at least four network adapters on Hyper-V host. One for the management, one for the live migration, one for a backup, virtual machines etc. But! What if network adapter for management or for virtual machines corrupt? We don’t have access to hosts or virtual machines!
To avoid this we will be create highly available virtual network. I have one Hyper-V host with three physical network adapter! I’ll first rename physical adapters then I’ll create NIC Team, Virtual Switch and Virtual Network Adapters.

1. Rename physical NICs
10 10
Why we need to rename NICs? If one or more network adapters spoil you don’t know which one is broken. On this way we will exactly know which one and in which PCI bus port is spoiled. Look picture below.

10

Here is PowerShell script!

Function Resolve-PCIBusInfo { 

param ( 
[parameter(ValueFromPipeline=$true,Mandatory=$true)] 
[string] 
$locationInfo 
) 
PROCESS { 
[void]($locationInfo -match  "\d,\d,\d") 
$busId,$deviceID,$functionID = $matches[0] -split "," 

new-object psobject -property @{ 
          "BusID" = $busID; 
          "DeviceID" = "$deviceID" 
          "FunctionID" = "$functionID" 
          } 
}         
} 



Function Rename-NicBusFunction { 
$Adapters = get-wmiobject win32_networkadapter -filter "netenabled=true"  | where {$_.PNPDeviceID -notlike "ROOT\*"}
foreach ($Adapter in $Adapters ) {
    $AdapterName = Get-WMIObject Win32_NetworkAdapter | where { $_.PNPDeviceID -eq $Adapter.PNPDeviceID }
    $OldName = $AdapterName.NetConnectionID
    write-host "Network Adapter name before:" $OldName
    
        $DeviceID = $Adapter.PnPDeviceID 
        $locationInfo = (get-itemproperty -path "HKLM:\SYSTEM\CurrentControlSet\Enum\$DeviceID" -name locationinformation).locationINformation 
        
        if ($locationInfo -match  "\d,\d,\d") {
            $BusInfo = Resolve-PCIBusInfo -locationInfo $locationinfo 

        $Bus = $BusInfo.BusID
        $Funct = $BusInfo.FunctionID 
        $NewName = "NIC-$Bus-$Funct"
        
        $AdapterName.NetConnectionID = "$newName"
        $rename = $AdapterName.Put()
        write-host "Network Adapter name after : $NewName"
        }
        else {
        $NewName = write-host "Network name not changed. Old name: $OldName"
        }
    Write-Host
}
}

Rename-NicBusFunction

The next step is to create NIC Team. We can do that on two ways, with GUI or with PowerShell. I prefer PowerShell

10

10

New-NetLbfoTeam -Name SMBTeam -TeamMembers NIC-2-0,NIC-3-0,NIC-4-0 -LoadBalancingAlgorithm Dynamic -TeamingMode SwitchIndependent

 

Now we have NIC Team called SMBTeam, Switch Independent, Dynamic crated from three physical network adapters.

In the next step we will create virtual switch. This kind of virtual switch we can create only with PowerShell. As you can notice I don’t have any virtual network switch created in Hyper-V.
10

So, let’s create one Converged Virtual Switch and four Virtual Network adapters.

10

This server will be Hyper-V Cluster node and I created four virtual network adapters. Heartbeat, LiveMigration, VmLan and one for Management. Now I have highly available virtual network. As you can see in the picture below, if I disable three of four virtual adapters or two of three physical adapter still can connect to Hyper-V host ;).

10

Cool, isn’t it ;)

 

Here you can find PowerShell script for Converged network.

New-NetLbfoTeam -Name SMBTeam -TeamMembers NIC-2-0,NIC-3-0,NIC-4-0 -LoadBalancingAlgorithm Dynamic -TeamingMode SwitchIndependent
New-VMSwitch -Name ConvergedHyperSwitch -NetAdapterName SMBTeam -AllowManagementOS $False -MinimumBandwidthMode Weight
Add-VMNetworkAdapter -ManagementOS -Name "Management" -SwitchName "ConvergedHyperSwitch"
Add-VMNetworkAdapter -ManagementOS -Name "VmLan" -SwitchName "ConvergedHyperSwitch"
Add-VMNetworkAdapter -ManagementOS -Name "LiveMigration" -SwitchName "ConvergedHyperSwitch"
Add-VMNetworkAdapter -ManagementOS -Name "Heartbeat" -SwitchName "ConvergedHyperSwitch"
Set-VMNetworkAdapter -ManagementOS -Name "Management" -MinimumBandwidthWeight 20
Set-VMNetworkAdapter -ManagementOS -Name "VmLan" -MinimumBandwidthWeight 20
Set-VMNetworkAdapter -ManagementOS -Name "LiveMigration" -MinimumBandwidthWeight 20
Set-VMNetworkAdapter -ManagementOS -Name "Heartbeat" -MinimumBandwidthWeight 20
New-NetIPAddress -InterfaceAlias "vEthernet (Management)" -IPAddress 192.168.0.130 -PrefixLength "24" -DefaultGateway 192.168.0.224 
Set-DnsClientServerAddress -InterfaceAlias "vEthernet (Management)" -ServerAddresses 192.168.0.203, 192.168.0.202 
New-NetIPAddress -InterfaceAlias "vEthernet (LiveMigration)" -IPAddress 192.168.30.30 -PrefixLength "24" 
New-NetIPAddress -InterfaceAlias "vEthernet (VmLan)" -IPAddress 192.168.28.30 -PrefixLength "24"
New-NetIPAddress -InterfaceAlias "vEthernet (Heartbeat)" -IPAddress 192.168.29.30 -PrefixLength "24"

 

In the next posts I’ll be write about Hyper-V Cluster, SMB Cluster, Storage Spaces and everything related on HA Hyper-V virtual machines.

P.S. Big thanks to my buddies Luka Manojlovič and Tomica Kaniški who helped me.

Stay tuned and be virtualized :)

Also, tomorrow is Christmas and I wish you all the best. Get rest and see you in 2014.

Cheers,

Romeo

Create New Generation 2 Virtual Machine with PowerShell – fundamentals

In this blog post I’d like to explain how to create Generation 2 Virtual Machine in few seconds with PowerShell. This .ps1 script is a very simple and you can create just one VM but you can edit it for your needs.
In the last two years on my lectures I noticed that many of attendees don’t understand the basics and also they are ashamed to ask in the front of other attendees. For that reason I want to help them!

This is my way how to create VM. I used PowerShell ISE for the better look

Step 1.

1

Step 2.

Type command like in the picture below, edit what you need to edit and press Run Script (F5).

2

### create client generation 2 virtual machine ###
New-VM -Name ATDGen2 -Path "C:\Hyper-V" -Generation 2 -SwitchName WiredLan
Set-VM -Name ATDGen2 -ProcessorCount 2 -DynamicMemory -MemoryStartupBytes 512MB -MemoryMinimumBytes 512MB -MemoryMaximumBytes 2048MB
New-VHD -Dynamic -SizeBytes 37GB -Path "C:\Hyper-V\ATDGen2\VirtualHardDisk\ATDGen2.vhdx"
Add-VMHardDiskDrive -VMName ATDGen2 -Path "C:\Hyper-V\ATDGen2\VirtualHardDisk\ATDGen2.vhdx"
Add-VMDvdDrive -VMName ATDGen2 -Path "D:\Software\Microsoft\Windows8.1Ent\en_windows_8_1_enterprise_x64_dvd_2791088.iso"
Set-VM -Name ATDGen2 -AutomaticStartAction StartIfRunning -AutomaticStopAction ShutDown
Start-VM -Name ATDGen2

And voila, in the few seconds VM is created. You will need approximately two minutes for OS installation on SSD. As you can see, VM is Up & Running.

3

You can expect more fundamental things related to virtualization very soon.

Enjoy the day ;)

Romeo