How to capture Linux VM in Azure

Images are used in Azure to provide a new virtual machine with an operating system. An image might also have one or more data disks. Images are available from several sources:

  • Azure offers images in the Marketplace. There are recent versions of Windows Server and distributions of the Linux operating system. Some images also contain applications, such as SQL Server. MSDN Benefit and MSDN Pay-as-You-Go subscribers have access to additional images.
  • The open source community offers images through VM Depot.
  • You also can store and use your own VM or OS images in Azure, by either capturing an existing Azure virtual machine for use as an image or uploading an image

There is a little difference between VM image (newer type) and OS image. VM image can include disk with generalized OS (sysprep in the Windows Server’s world) and data disks attached to the VM. OS image includes only OS disk.

I’ll show you how to make a new VM image from Linux VM created in Azure Resource Manager. You can use this image to create VMs across any resource group within your subscription (thanks to azure managed disks).

Before we start download and install the latest Python

Launch CMD , verify Python’s version and install Azure CLI 2.0

python --version
pip install --user azure-cli

azurecli_01

Open SSH to your VM (use azure public ip, root creds) and start VM’s deprovision (read WARNINGS!)

sudo waagent -deprovision+user -force

azurecli_02

Now VM is ready for generalizing

Switch back to CMD and change directory to C:\Users\yourusername\AppData\Roaming\Python\Python35\Scripts
Login to the Azure Account using Azure CLI (use received code to authenticate)

az login

azurecli_03

Select subscription in which source VM is running

#To list all subscriptions and get IDs
az account list

#To select target subcription
az account set --subscription subid

azurecli_04

Stop and deallocate the source VM

az vm deallocate --resource-group "groupname" --name "vmname"

azurecli_05

Time to generalize VM and create VM image

az vm generalize --resource-group "groupname" --name "vmname"
az image create --resource-group "groupname" --name "ImageName" --source "SourceVMName"

Get image list from CLI (copy Image ID):

azurecli_07

Azure side (Images):

azurecli_06

Now we are ready to create VM or bunch of VMs from this image

az vm create --resource-group "groupname" --name "VMname" --image "imageid" --admin-username username --authentication-type password --admin-password "cleartexthere"

azurecli_08

Note: VM Size , Storage type will be selected automatically by Azure. You need to manually define them if it’s required (see examples below)

Simple script that creates bunch of VMs with naming test-VM-0x , predefined VM size and storage type

for /L %%n in (1,1,9) do (
az vm create --resource-group "groupname" --name test-VM-%%n --storage-sku "StorageTypeHere (example: Standard_LRS)" --size "VMsize (example: Basic_A4)" --image "image id here" --admin-username adminname --authentication-type password --admin-password "password here"
)

Result:vms

Linux Integration Services Version 4.0 for Hyper-V

Here is the new version of Linux IS for Hyper-V

http://www.microsoft.com/en-us/download/details.aspx?id=46842

Current version: 4.0.11 Please refer to the Linux Virtual Machines on Hyper-V topics for up to date information on the LIS feature set, all supported Linux distributions, availability and download locations.

When installed in a supported Linux virtual machine running on Hyper-V, the Linux Integration Services provide:

 Name  Description
Driver support Linux Integration Services supports the network controller and the IDE and SCSI storage controllers that were developed specifically for Hyper-V.
Fastpath Boot Support for Hyper-V  Boot devices now take advantage of the block Virtualization Service Client (VSC) to provide enhanced performance.
Time Keeping The clock inside the virtual machine will remain accurate by synchronizing to the clock on the virtualization server via Timesync service, and with the help of the pluggable time source device.
Integrated Shutdown Integrated Shutdown: Virtual machines running Linux can be shut down from either Hyper-V Manager or System Center Virtual Machine Manager by using the “Shut down” command.
Heartbeat This feature allows the virtualization server to detect whether the virtual machine is running and responsive.
Symmetric Multi-Processing (SMP) Support Supported Linux distributions can use multiple virtual processors per virtual machine. The actual number of virtual processors that can be allocated to a virtual machine is only limited by the underlying hypervisor.
KVP (Key Value Pair) Exchange Information about the running Linux virtual machine can be obtained by using the Key Value Pair exchange functionality on the Windows Server 2008 virtualization server.
Integrated Mouse Support Linux Integration Services provides full mouse support for Linux guest virtual machines.
Live Migration Linux virtual machines can undergo live migration for load balancing purposes.
Jumbo Frames Linux virtual machines can be configured to use Ethernet frames with more than 1500 bytes of payload.
VLAN tagging and trunking Administrators can attach single or multiple VLAN ids to synthetic network adapters.
Static IP Injection Allows migration of Linux virtual machines with static IP addresses.
Linux VHDX resize Allows dynamic resizing of VHDX storage attached to a Linux virtual machine.
Synthetic Fibre Channel Support Linux virtual machines can natively access high performance SAN networks.
Live Linux virtual machine backup support Facilitates zero downtime backup of running Linux virtual machines.
Dynamic memory ballooning support Improves Linux virtual machine density for a given Hyper-V host.
Synthetic video device support Provides improved graphics performance for Linux virtual machines.
PAE kernel support Provides drivers that are compatible with PAE enabled Linux virtual machines.