Skip to content

Instantly share code, notes, and snippets.

@baude baude/ Secret
Created Oct 19, 2017

What would you like to do?
Azure writeup

Running Fedora images on Microsoft Azure

Microsoft's Azure Cloud Computing Platform is capable of running Windows and Linux instances. It offers their pre-ordained Linux and Windows images for quick deployment of server instances. At the time of this writing, no Fedora images are available in their catalog. But you can upload a customized image to Azure and run that too.

About the Azure Cloud environment

We recently did some cleanup work to make sure the Fedora Atomic and Cloud-based images provision correctly in Azure. Up until recently, most Linux images used the opensource WALinuxAgent to provision their instances. The WALinuxAgent, also often referred to as the WALA agent, is capable of provisioning an instance on Azure. It also provides advanced functions like diagnostics, VM extensions, and more. When provisioning, the agent can create users, setup SSH keys, set the hostname, and setup devices and storage. However, the key action the agent does during its provisioning process is set up the correct networking information and report back to the Azure fabric that it has successfully booted.

However, there is a trend now on Azure to provision Linux instances with cloud-init. Cloud-init has frankly assumed the defacto utility for provisioning on all kinds of platforms. It can perform many of the same provisioning functions that the WALinuxAgent can including the ability to report readiness to the Azure fabric. This use of cloud-init allows us to now take a stock Fedora Atomic or Cloud image and deploy it unchanged on Azure. Those changes are now part of the Fedora 27 release.

Obtain a Fedora 27 image

Both the Fedora 27 Atomic and Cloud images will provision and run nicely on Azure. As noted earlier, they both use cloud-init to provision by default. Begin by downloading the QCOW2 image.

Convert the QCOW2 to VHD

Azure requires its user-provide images to be in the VHD format. Additionally, the image image size must be aligned on a one MB boundary. Conversion between formats can be trivially done on almost any Linux distribution with standard utilities.

The conversion process is roughly as follows:

  1. Convert the image from the QCOW2 format to the RAW format.
  2. Round the RAW image size to a one MB boundary.
  3. Convert the RAW image to the VHD format.

The following bash script can be used for conversion from QCOW2 to VHD.

# Convert to RAW
qemu-img convert -f qcow2 -O raw Fedora-27-Cloud.qcow2 Fedora-27-Cloud.raw

# Obtain the size of the RAW image
size=$(qemu-img info -f raw --output json "Fedora-27-Cloud.raw" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')

# Calculate the 1MB rounded size for the VHD image
rounded_size=$((($size/$MB + 1)*$MB))

# Resize the RAW Image
qemu-img resize -f raw Fedora-27-Cloud.raw $rounded_size

# Convert the RAW image to VHD
qemu-img convert -f raw -o subformat=fixed,force_size -O vpc Fedora-27-Cloud.raw Fedora-27-Cloud.vhd

Once the the VHD image is created, you can delete the RAW image as it takes up a fair amount of disk space. The VHD image is the image you will upload to Azure.

Upload the VHD image to Azure

There are several different ways to upload an image to Azure. You can use Azure's web-based UI or any one of the several Azure CLI utilities. I use the Azure CLI based on NodeJS and provided by NPM which is available on most modern Linux distributions.

# azure vm create baude-atomic-2 -l "CentralUS" --resource-group baude-ci-tests --storage-account-name baudecitests4068 -I /subscriptions/2586c64b-38b4-4527-a140-012d49dfc02c/resourceGroups/baude-ci-tests/providers/Microsoft.Network/networkInterfaces/baude-nic2  -M ~/azure/ -y Linux -u bbaude --image-urn$IMAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.