Using the edge Azure CLI in a Centos VM

If you’re wanting to use the Edge (developer, nightly build) of the Azure CLI tools I can definitely recommend using an Azure VM.
Firstly, the advantages are

  • Using a developer AZ CLI build in isolation from your main work machine
  • VM’s in Azure can using Managed Service Identity to easily authenticate with the control plane
  • You can run it on a really cheap B series VM ($9/$18 a month!)

See here for the GitHub repo:

VM Spec

I’m running a CentOS Standard_B1ms VM which gives me 1 core 2GB RAM, 800 IOPS with a 32GB standard managed disk which offers a capped IOPS of 500. This costs approx. $18/month for 24×7 compute and approximately $2/month for my disk.


I have two IP’s opened up on port 22 so I can SSH on. Everything else is locked down.

VM Updates

The VM is enrolled for update management, as I’ve gone for the B-series the VM will be kept up 24×7 so I don’t need to worry about turning it on to get patched.

Managed Identity

The VM has a system managed identity in Azure Active Directory and I have given it limited Contributor access to one resource group and reader access to a few other resource groups.

Setup script

On a fresh CentOS VM here’s what I run to install the CLI and login to Azure.

Whenever I log into the VM I run this command to update to the latest build

Next steps

I kinda like having a VM running all the time, i’m putting myself through a very basic IaaS experience using fundamental Azure components. I could make use of the Docker build of the AZ CLI and run it up on a Azure Container Instance on-demand…. Maybe next week, eh 🙂

Linux Mint on Azure

Azure’s got a nice set of supported Linux distros.
The Azure Marketplace also has a pretty comprehensive list of where you can get started quickly with various Linux distros.
There’s even a couple of nice templates in the Quickstart templates GitHub where you can have Gnome or Xfce desktops installed, and RDP enabled.

I’ve had the issue of needing to get a desktop build of Linux Mint (17.3 Rosa) running in Azure. I’m writing this post to help avoid some of the pitfalls that I have experienced and worked around. I’ve also got a handy script file that makes the process a lot quicker.

The first thing to point out is that i’m using Hyper-V 10 (on my x64 Windows 10 build) to create the disk images locally before uploading them to Azure. You can use Virtualbox or other workstation hypervisors to build your disk image.

Which ISO?

The first choice you need to make is the right image iso to use.I wasted a lot of time with x86 images. Don’t. They don’t work correctly in Azure. My Azure boot diagnostics showed that it wouldn’t progress past "Waiting for Network".
My Linux Mint testing (Ubuntu derived distro) didn’t even show this message.

You need to download x64 ISO images only

Hyper-V settings

Before creating a VM, you should create the hard disk.

  • VHD, not VHDx
  • Fixed size

Next, create the VM.

  • Make sure you have your Virtual Switch created first as you’ll need network connectivity.
  • Generation 1 VM as Azure cannot accept a Generation 2 VM
  • Choose a small disk as this will speed up the upload later. I tend to go for 10GB.
  • Opt for 2048mb of allocated memory (not dynamic)

Mint installation settingsChoose your own partition/disk config. The default setup will include a Swap partition – which you don’t need.OS ConfigurationAs soon as the Ubuntu has installed and the VM has rebooted, you’re ready to get it configured for Azure. There’s a good guide on the Azure site, but I’ve shortened it down to a single script file, with various little tweaks that make the process a little easier. It’s structured that you can run in blocks by copy and pasting into terminal.

Here’s my script file. – Inside your VM Navigate to it and download for easy reference.Each script block has a comment.

Sending the VHD to Azure

Once the VM is off, we’ll want to do the final preparation before uploading into Azure storage. Since my host environment is Windows, I use Powershell. First step is to make the disk static is size (so the vhd file takes up the full 10GB of disk space). Then we can upload into Azure Storage.

Testing the VM Image

By far the quickest way to test the creation of a VM from a VHD is by using DevTest labs. They have their own storage account, so if you need to copy it into the lab storage account

Shutting down Azure VMs based on Resource Group tags

Shutting down your non-production VM’s when you’re not using them in a great way to save money. There’s a couple of good Powershell scripts that make this easy to do by Resource Group – but when you want to be a little more granular, and actually automate across resource groups you need a smarter script – this is where Resource tagging comes in.

This script in basically my v1, simple powershell script designed to be run on demand manually. I’ll be publishing the more fully featured version in the Azure Automation Runbook Gallery shortly. That script has had to have a few workarounds put in to deal with issues arising from being a Powershell Workflow and running in Parallel, so I thought it worthwhile to share the simpler version here.