I believe in Hyper-V!

VirtualizationCategory Archives

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

Convert single VMware virtual disk (.vmdk) to Hyper-V virtual disk (.vhd) with Microsoft Virtual Machine Converter (MVMC)

In this blog post I’ll explain how to convert .vmdk to .vhd and how to create new Hyper-V virtual machine with converted disk.
What is Microsoft Virtual Machine Converter (MVMC)? The Microsoft Virtual Machine Converter Solution Accelerator is a stand-alone solution for the IT Pro or solution provider who wants to convert VMware based virtual machines to Hyper-V based virtual machines. The MVMC solution can perform full conversion of VMware based virtual machines as well as conversions of VMware virtual disks to Hyper-V virtual disks.
Supported & Free – Quick and easy to download, use and start conversions of VMware VMs
Convert to 2012 – Converts and deploys virtual machines or virtual disks from VMware to Hyper-V hosts including Hyper-V on Windows Server 2012
Scriptable –  Fully scriptable command-line interfaces for performing virtual machine and disk conversions that integrates well with data center automation workflows and Windows PowerShell scripts
OS Support – Supports Windows Server 2008 R2, Windows Server 2008, Windows Server 2003 SP2 and Windows Vista & Windows 7 as well as Windows 8

Microsoft Virtual Machine Converter is a FREE tool! You can download from here.
1

With a GUI we can convert VMware based VMs only if have vCenter server, ESX server, or ESXi server.
2

But, what if I have VMware workstation based VMs? Can I convert these VMs? NO, we can’t convert these VMs on that way but can convert virtual disks (.vmdk) (with CLI) and then can create new VM in Hyper-V.
So, this is detailed how to…

Step 1. Convert .vmdk to .vhd
Open command prompt as administrator and navigate to

C:\Program Files (x86)\Microsoft Virtual Machine Converter Solution Accelerator>mvdc.exe “sourcedisk\vmdkdisk\vmdisk.vmdk” “destinationdisk\newvhddisk\newvhd.vhd” press Enter.

3

Step 2. Create Hyper-V virtual machine with converted virtual disk

4

And voila, we have Hyper-V virtual machine up & running ;)

5

MVMC Capabilities

  • Converts VMware VMs to Hyper-V VMs
  • Supports converting to WS2012 Hyper-V
  • Wizard Driven UI for conversion
  • Includes CLI for VM and virtual disk conversion
  • Supports offline conversion of .vmdk to .vhd
  • Removes VMware tools for a clean migration
  • Installs Hyper-V integration services

This isn’t only way for conversion, we can do that in a few ways, but it is one of the simplest.

Enjoy the day!