Ubuntu Virtual Machine in a Synology NAS: In this article, you are going to learn how to create your very own Ubuntu-based Virtual Machine with a Sinology NAS.If you really enjoy this article, consider checking out my TechWizTime YouTube Channel.
-->Each virtual machine (VM) in Azure is created from an image that defines the Linux distribution and OS version. Images can include pre-installed applications and configurations. The Azure Marketplace provides many first and third-party images for most common distributions and application environments, or you can create your own custom images tailored to your needs. This article details how to use the open source tool Packer to define and build custom images in Azure.
Note
Ubuntu team announced the updated version of their operating system Ubuntu 18.04.1 Bionic Beaver. 'The Ubuntu team is pleased to announce the release of Ubuntu 18.04.1 LTS (Long-Term Support) for its Desktop, Server, and Cloud products, as well as other flavours of Ubuntu with long-term support. As usual, this point release includes many updates, and. The VMWare tools for Fusion-5 doesn't work on Ubuntu 14.04LTS. VMware is recommending using Fusion-6 to build a Ubuntu 14.04 image and using it on Fusion-5. Hence finding a pre-built image with VMware tools installed would be great. Much faster than any Virtual Machine, Docker allows you to run a Ubuntu image and gain interactive access to its shell, so you can have all your dependencies in an isolated Linux environment.
Azure now has a service, Azure Image Builder (preview), for defining and creating your own custom images. Azure Image Builder is built on Packer, so you can even use your existing Packer shell provisioner scripts with it. To get started with Azure Image Builder, see Create a Linux VM with Azure Image Builder.
Create Azure resource group
During the build process, Packer creates temporary Azure resources as it builds the source VM. To capture that source VM for use as an image, you must define a resource group. The output from the Packer build process is stored in this resource group.
Create a resource group with az group create. The following example creates a resource group named myResourceGroup in the eastus location:
Create Azure credentials
Packer authenticates with Azure using a service principal. An Azure service principal is a security identity that you can use with apps, services, and automation tools like Packer. You control and define the permissions as to what operations the service principal can perform in Azure.
Create a service principal with az ad sp create-for-rbac and output the credentials that Packer needs:
An example of the output from the preceding commands is as follows:
To authenticate to Azure, you also need to obtain your Azure subscription ID with az account show:
You use the output from these two commands in the next step.
Define Packer template
To build images, you create a template as a JSON file. In the template, you define builders and provisioners that carry out the actual build process. Packer has a provisioner for Azure that allows you to define Azure resources, such as the service principal credentials created in the preceding step.
Create a file named ubuntu.json and paste the following content. Enter your own values for the following:
Parameter | Where to obtain |
---|---|
client_id | First line of output from az ad sp create command - appId |
client_secret | Second line of output from az ad sp create command - password |
tenant_id | Third line of output from az ad sp create command - tenant |
subscription_id | Output from az account show command |
managed_image_resource_group_name | Name of resource group you created in the first step |
managed_image_name | Name for the managed disk image that is created |
This template builds an Ubuntu 16.04 LTS image, installs NGINX, then deprovisions the VM.
Note
Ubuntu Server Vm Image
If you expand on this template to provision user credentials, adjust the provisioner command that deprovisions the Azure agent to read -deprovision
rather than deprovision+user
.The +user
flag removes all user accounts from the source VM.
Build Packer image
If you don't already have Packer installed on your local machine, follow the Packer installation instructions.
Ubuntu Vm Image
Build the image by specifying your Packer template file as follows:
Ubuntu Vm Image
An example of the output from the preceding commands is as follows:
Open source format. It takes a few minutes for Packer to build the VM, run the provisioners, and clean up the deployment.
Create VM from Azure Image
You can now create a VM from your Image with az vm create. Specify the Image you created with the --image
parameter. The following example creates a VM named myVM from myPackerImage and generates SSH keys if they do not already exist:
If you wish to create VMs in a different resource group or region than your Packer image, specify the image ID rather than image name. You can obtain the image ID with az image show.
It takes a few minutes to create the VM. Once the VM has been created, take note of the publicIpAddress
displayed by the Azure CLI. This address is used to access the NGINX site via a web browser.
To allow web traffic to reach your VM, open port 80 from the Internet with az vm open-port:
Test VM and NGINX
Now you can open a web browser and enter http://publicIpAddress
in the address bar. Provide your own public IP address from the VM create process. The default NGINX page is displayed as in the following example:
Ubuntu Vm Images
Next steps
Ubuntu Virtual Machine Images
You can also use existing Packer provisioner scripts with Azure Image Builder.