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. https://gordonscustomimages.blob.core.windows.net/scripts/mintrosa.txt – Inside your VM Navigate to it and download for easy reference.Each script block has a comment.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak;
sudo sed -i "s/[a-z][a-z].archive.ubuntu.com/azure.archive.ubuntu.com/g" /etc/apt/sources.list;

sudo apt-get update;
sudo apt-get -y install linux-image-virtual-lts-vivid linux-lts-vivid-tools-common;
# Say no to any prompts during daemon install
sudo apt-get -y install hv-kvp-daemon-init;

sudo apt-get update;
sudo apt-get -y dist-upgrade;

sudo apt-get update;
sudo apt-get upgrade;
sudo apt-get -y autoremove;
sudo reboot;

# change GRUB_CMDLINE_LINUX_DEFAULT in "/etc/default/grub"
# to GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300";
sudo gedit "/etc/default/grub";

sudo update-grub;

#Setup RDP access
sudo apt-get update;
sudo apt-get -y install xrdp;
sudo apt-get -y install vnc4server;
sudo gedit /etc/xrdp/startwm.sh;
sudo service xrdp restart;
ifconfig
#Test RDP Access

#Azure agent install
sudo apt-get update;
sudo apt-get -y install walinuxagent;

#check values here;
#ResourceDisk.Format=y
#ResourceDisk.Filesystem=ext4
#ResourceDisk.MountPoint=/mnt/resource
#ResourceDisk.EnableSwap=y
#ResourceDisk.SwapSizeMB=2048    
sudo gedit "/etc/waagent.conf";

sudo waagent -force -deprovision;
export HISTSIZE=0;
sudo shutdown 1;

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.

$vhdxpath = "C:UsersPublicDocumentsHyper-VVirtual hard disksMintXfce64.vhd"

Login-AzureRmAccount

#UPLOAD TO AZURE STORAGE ACCOUNT.  
#For a 10gb file typical timings are: 1) 1 minute to calculate md5 hash 2) 2 minutes for Empty block detection 3) 30 minutes to upload to Azure storage    
Write-Host "Starting Blob copy at $(get-Date -format r)" 
Add-AzureRmVhd -ResourceGroupName "customvhds" -Destination "http://gordonscustomimages.blob.core.windows.net/mint/MintXfceXrdp64.vhd" -LocalFilePath $vhdPath

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

$srcfileurl = "http://gordonscustomimages.blob.core.windows.net/mint/MintXfceXrdp64.vhd"
$srcstorageaccount = "gordonscustomimages"
$srcstoragekey = "myprimarystorageaccountkey"
$deststorageaccount = "msdtlvm178935967"
$deststoragekey = "myprimarystorageaccountkey"
$destcontainer = "uploads"

Login-AzureRmAccount

#Establish storage connections
$srcCtx = New-AzureStorageContext –StorageAccountName $srcstorageaccount -StorageAccountKey $srcstoragekey  
$destCtx = New-AzureStorageContext –StorageAccountName $deststorageaccount -StorageAccountKey $deststoragekey  
 
#Create container if needed
if ((Get-AzureStorageContainer -Name $destcontainer -Context $destCtx) -eq $null) {
    New-AzureStorageContainer -Name $destcontainer -Context $destCtx 
}
 
#Start copy

$destBlobFileName = ([uri]$srcfileurl).segments[-1]
Start-AzureStorageBlobCopy -srcUri $srcfileurl -SrcContext $srcCtx -DestContainer $destcontainer -DestBlob $destBlobFileName -DestContext $destCtx

#Check progress
Get-AzureStorageBlobCopyState $destBlobFileName -Context $destCtx -Container $destcontainer

Leave a Reply

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