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

Azure Stack Preview 3 is available

Azure Stack is a hybrid cloud platform that lets you deliver Azure services from your organization’s datacenter. Microsoft Azure Stack Technical Preview 3 is being made available as a Proof of Concept (POC). The POC is an ideal environment for learning and demonstrating Azure Stack features.

Microsoft is also announced that Azure Stack will be available via Enterprise Agreement (EA) and Cloud Solution Provider Program (CSP) 

azure-stack-architecture

In addition to bug fixes and other improvements, here’s the list of new features:

  • Active Directory Federation Services (AD FS) support provides identity options for scenarios where network connectivity is limited or intermittent.
  • You can use Azure Virtual Machine Scale Sets to provide managed scale out of workloads.
  • Use Azure D-Series VM sizes for increased performance and consistency.
  • Deploy and create templates with Temp Disks that are consistent with Azure.
  • Marketplace Syndication allows you to use content from the Azure Marketplace and make available in Azure Stack.
  • Isolated administrator and user portals and APIs provide enhanced security.
    Use enhanced infrastructure management functionality, such as improved alerting.
  • Using the Windows Azure Pack connector, you can view and manage IaaS virtual machines that are hosted on a Cloud Platform System (CPS) stamp. For this preview release, you can try this only with a CPS environment and additional configuration is required.