Blog

Hanu How-To: Building a Virtual Machine Using Hybrid Use Benefit in Microsoft Azure

If you’ve been looking for a how-to guide regarding building virtual machines using the Hybrid Use Benefit, you’ve come to the right place. This blog will provide you with the guidance you’re looking for on how to build an Azure Virtual Machine using the Azure Hybrid Use Benefit. If you have questions or comments, don’t hesitate to reach out to us and ask in the comments below or via our contact us page.

What is Hybrid Use Benefit (HUB):

  • The Azure Hybrid Use Benefit is where you can bring your own on-premises Windows Server licenses and Windows OS sys-prepped image covered with Software Assurance to license Azure hosted Windows Server virtual machines.
  • For each Windows Server 2 processor license with Software Assurance, you can run two virtual machines with up to 8 cores each, or one virtual machine with up to 16 cores.
  • Software Assurance or an Enterprise Agreement subscription is required for the Azure Hybrid Use Benefit to apply.

Options to Use Azure HUB:

Option 1 – Hybrid Use Benefit Images (requires Enterprise Agreement subscription):

  • Deploy pre-built HUB Windows Server images straight from Azure Marketplace. (Search for “[HUB] Windows Server”)
  • OR Deploy them using command line using the new Azure CLI t0 preview or the Azure PowerShell

 

image552

 

image553

 

Option 2 – Upload your own custom VHD Windows Server image into Azure for use with HUB (requires Software Assurance):

Follow the steps to Sys-prep the machine and upload it to Azure:

Sys-prep as the Source Machine:

  • Login to the Virtual machine where you want to convert it into template.
  • Sys-prep the machine using the command line.
    • From command prompt, navigate to CD c:\windows\system32\sysprep\sysprep.exe
    • Select Generalize and OOBE and Shutdown.
  • Once Sys-prep is completed VM will be in stopped state in the Azure Portal.
  • Install Azure ARM modules in your machine using the below URL(s):

 

Capture Image:

  • Once RM modules are installed, execute the following commands:
#ARM logon

Login-AzureRmAccount

# Deallocate the virtual machine

Stop-AzureRmVM -ResourceGroupName "test" -Name "clonetestvm1" -Force

# Set the Generalized state to the virtual machine

Set-AzureRmVM -ResourceGroupName "test" -Name "clonetestvm1" -Generalized

# Capture the image to storage account.

Save-AzureRmVMImage -ResourceGroupName "test" -Name "clonetestvm1" '

-DestinationContainerName "tempbackup" `

-VHDNamePrefix "template" -Path "d:\temp\CaptTemplate.json"
  • The final command will not only save the JSON template to the path specified but also will show it on screen. Also in the storage account will be a folder structure called system\Microsoft.Computer\Images\<your container name> which will contain the VHD and JSON file.

 

Creating VM from Template for HUB:

$imageURI = "https://test123.blob.core.windows.net/win2k16standard/win2k16standard.vhd"

$strgrgName = "AZ-StRG"

$location = "East US"

$rgName = "AZ-VMRG"

# Enter a new user name and password to use as the local administrator account

# for remotely accessing the VM.

$cred = Get-Credential


$vnet = Get-AzureRmVirtualNetwork -Name "vnet" -ResourceGroupName "NetworkRG"

 

$nicName = "azvmnic1"


$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[3].Id



$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName "AZ-NetworkRG" -Name "vnet"

 

# Name of the storage account where the VHD is locget-azrated. This example sets the

# storage account name as "myStorageAccount"
$storageAccName = “vmhub"

# Name of the virtual machine. This example sets the VM name as "myVM".

$vmName = "AZHUBVM-01"

# Size of the virtual machine. This example creates "Standard_D2_v2" sized VM.

# See the VM sizes documentation for more information:
# https://azure.microsoft.com/documentation/articles/virtual-machines-windows-sizes/

$vmSize = "Standard_DS4_v2"

# Computer name for the VM. This examples sets the computer name as "myComputer".

$computerName = "AZHUBVM-01"

# Name of the disk that holds the OS. This example sets the

$osDiskName = "azhubvm-01-os.vhd"
# Assign a SKU name. This example sets the SKU name as "Standard_LRS"

# Valid values for -SkuName are: Standard_LRS - locally redundant storage, Standard_ZRS - zone redundant storage, Standard_GRS - geo redundant storage, Standard_RAGRS - read access geo redundant storage, Premium_LRS - premium locally redundant storage.

$skuName = "Standard_GRS"

# Get the storage account where the uploaded image is stored

$storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $strgrgName -AccountName $storageAccName

# Set the VM name and size

$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize

#Set the Windows operating system configuration and add the NIC

$vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName  -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

# Create the OS disk URI

$osDiskUri = '{0}vhds/{1}-{2}.vhd' `

     -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName

# Configure the OS disk to be created from the existing VHD image (-CreateOption fromImage).

$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri `

     -CreateOption fromImage -SourceImageUri $imageURI -Windows

# Create the new VM

New-AzureRmVM -ResourceGroupName $rgName -Location $location  –LicenseType   “Windows_Server” -VM $vm

Verification:

Option 1: Using PowerShell:

Get-AzureRmVM -ResourceGroupName “ResourceGroup11” -Name “WindowsServer07”

Look for LicenseType : Windows_Server such as below:

image559

 

Option 2: Using Azure Resource Explorer:

1) Go to http://resources.azure.com

2) Drill down to the VM you created and under properties section you should see “licenseType”: “Windows_Server”, like below on the JSON view:

 

image560

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *