Mikrotik CHR in Microsoft Azure (ARM)

At the time of writing, Mikrotik's current CHR build is 6.35rc49.

While purported to work in a Hyper-V VM, there are no instructions I could find to get one up and running in Microsoft Azure (with ARM).

Knowing that it should be theoretically possible, given Azure utilises a hypervisor with the same origins as Hyper-V, I went down the rabbit hole.

The salient points are as follows:

  • It works! We have stable CHRs in ARM VMs supporting production workloads.
  • You must convert the Mikrotik supplied VHDX to a VHD before uploading to Azure's blob storage, as Azure doesn't support the newer format. (I installed the Hyper-V role on my Windows box, which includes a utility to do the conversion)
  • You must use the -CreateOption Attach parameter with the Set-AzureRmVMOSDisk cmdlet, otherwise you'll end up with an Azure VM object stuck in a "Provisioning" or "Creating" state. You can just use the URL for the VHD you upload to blob storage for the -VhdUri parameter.
  • The CHR VM doesn't respond to Stop or Restart requests from the Resource Manager Portal or PowerShell cmdlets. Attempting these actions can put the CHR VM into an inconsistent state.
  • You can safely delete CHR VMs and the disks are left intact in blob storage and can be re-attached to a new VM. (Would need to re-license)
  • You can restart the router from within Winbox / CLI as well as perform upgrades. (Back up your config first, sometimes the upgrades fail)
  • A lot of scenarios will require IP forwarding to be enabled on your CHR NIC. This can only be done with PowerShell, set the EnableIPForwarding property to true on a NIC object and then update with Set-AzureRmNetworkInterface. Update: IP Forwarding can now be enabled from the Azure Portal in the NIC IP Properties.

If Mikrotik are not forthcoming with some proper Azure instructions, I'll try and expand on these notes with a full set of step by step instructions.

NB: If you're at the point where you're still choosing your cloud provider, CHR is presently much more mature in AWS on EC2 instances.


9 Comments Mikrotik CHR in Microsoft Azure (ARM)

    1. pebkac

      Once you have logged in, the basics are as follows:

      $OSDiskCaching = "ReadWrite"
      $OSCreateOption = "Attach"
      $SourceImageUri = "https://[storageaccount].blob.core.windows.net/vhds/[CHR IMAGE].vhd"

      $StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName
      $VNet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $ResourceGroupName
      $Interface = Get-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName
      $VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
      $VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
      $VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $SourceImageUri -Caching $OSDiskCaching -CreateOption $OSCreateOption -Linux

      New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

      You'll have to populate the other variables according to your environment.

  1. Dinesh


    This looks great. However I see error after
    New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

    The error is "Required parameter 'networkProfile' is missing"

    I also noticed $VNet is not being used anywhere.

        1. pebkac

          Have you created a NIC in ARM to add to the machine? What line of the script do you run in to the problem?

          1. Dinesh

            Yes, I have created NIC. The specified NIC is attached to a NSG and has public IP.
            The error of networkProfile missing comes after this
            New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

          2. pebkac

            I've just tried to replicate in my environment but everything worked fine. It can sometimes take a while for new resources in Azure to become ready, perhaps this was the issue.

Leave a Reply

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