This step by step guide will show you how to prepare a generalized image from an Ubuntu 16.10 image from the marketplace, using the newest managed disks that were released on 02/08/2017.
Generalized virtual machines are nothing more than a virtual machine installed from the Azure Marketplace then manually customized and prepared to become an image, if it is based on Windows, that means executing Sysprep as a final step, if it is Linux-based, that means de-provisioning the Linux agent (the Azure agent) as a final step.
In order to follow this guide, please deploy a new Ubuntu 16.10 virtual machine using managed disks instead of unmanaged disks (the old way with storage accounts), through the portal or any other deployment method, for this example, I customized the image by installing XRDP on it, by following the steps outlined in this document.
It is also assumed that you have Azure CLI 2.0 installed in a management computer by following the steps outlined here to perform the installation, all command line instructions below assumes you are executing them on Linux bash only. I’m using Bash on Ubuntu on Windows 10 to write this post.
Creating the generalized image from specialized image
- After you have your master Ubuntu virtual machine configured the way you need, please execute the following commands in order to make it available to be used as an image, this needs to be accomplished inside your virtual machine.
- From a management computer (where Azure CLI 2.0 is installed) shutdown your specialized virtual machine
- Generalize the virtual machine from Azure perspective
- Still from the management computer, create an image from the generalized virtual machine, must be in the same resource group as your master virtual machine.
Deploying a new VM from image using managed disks
Adjusting the automatically created Network Security Group
The customization made to this image was enabling RDP service on Ubuntu, since the az vm create command also creates a network security group by default, we need to change it to allow port 3389 which is the one that RDP uses.
The following steps will guide you through adding a new security rule to the existing NSG:
- To obtain the NSG associated with this new virtual machine, first let's get the ID of the network adapter
- Getting the network security group id
- Getting the network security group name
- Adding the network security rule to the existing NSG
Since XRDP does not come installed by default, this demonstrates that the new virtual machine came from the specialized image that you just created.
If you want to expand this scenario and execute a post deployment script on this newly deployed virtual machine, please refer to the post Executing Custom Script Extension using Azure CLI 2.0 on an Azure Linux Virtual Machine.
I hope you have enjoyed this short post and have fun creating your own custom images in Azure.
For more information, please refer to the following documents:
See you in the next post!