• 5 min read

VM Image

Drum roll, please.  With our most recent Microsoft Azure Runtime release, we are happy to announce the successor to OS Images, the new VM Image entity.  Wait a minute… yes, some of you may be…

Drum roll, please.  With our most recent Microsoft Azure Runtime release, we are happy to announce the successor to OS Images, the new VM Image entity.  Wait a minute… yes, some of you may be thinking this sounds familiar.  This feature was indeed one of the many exciting new items that was featured a little over a week ago at the //build conference in San Francisco.  The engineering team has been working hard to release this new entity and I am happy to kick off a set of posts describing what it is, how to use it, and all the small, practical details.

In one sentence, you can think of VM Images as a more comprehensive image for Microsoft Azure Virtual Machines.  The new and improved VM Image encompasses the full definition of a virtual machine’s storage, containing the OS disk and all data disks.  It captures the disk properties (such as host caching) you need in order to deploy a VM in a reusable unit.  Similar to OS Images, a VM Image is a collection of metadata and pointers to a set of VHDs (one VHD per disk) stored as page blobs in Azure Storage.

Right about now, you may be thinking that VM Images and OS Images are comparable.  You are indeed correct!  A VM Image containing a single VHD with a generalized operating system is essentially the OS image you are familiar with today.  Over time, you will notice that VM Images will become the main image construct for Microsoft Azure Virtual Machines.

There are two types of VM Images – generalized and specialized – each serving their own purpose.  A generalized VM Image contains an OS disk, which, as the name suggests, has been generalized (for Windows, you have run Sysprep and for Linux, you have executed ‘waagent –deprovision’) and needs to be provisioned during deployment time.  OS Images today are generalized.  This type of VM Image is meant to be used as a “model” to quickly stamp out similar virtual machines, such as scaling out a front-end to your application in production or spinning up and tearing down similar development and test environments quickly.

A specialized VM Image contains an OS disk, which is already provisioned.  It is similar to a disk today in that it is “ready-to-use”, but unlike a disk, the VHDs of a VM Image are treated as read-only and copied when deploying a new virtual machine.  A specialized VM Image is meant to be used as a “snapshot” to deploy a VM to a good known point in time, such as checkpointing a developer machine, before performing a task which may go wrong and render the virtual machine useless.  It is not meant to be a mechanism to clone multiple identical virtual machines in the same virtual network due to the Windows requirement of Sysprep for image replication.

How Do I Create a VM Image

Once you have a virtual machine set up and configured as you want, you can capture the instance as a VM Image.  During the capture process, all relevant properties of the virtual machine and disks are stored and copies of the backing VHD page blob(s) are made.  The copy of each VHD is stored in the same storage account and container as the original VHD being copied.  If you are interested in finding the copied VHDs in Azure Storage, search for page blobs with the following naming convention: for the OS VHD, we use -os-YYYY-MM-DD and for the copied data VHDs, we use -datadisk–YYYY-MM-DD(-ZZ).  The date is when the VM Image was captured and the -ZZ is a number, added only if there is a collision, to make the name unique.  During capture, no in-memory state is saved and as such, this feature is not meant to replace the current backup and restore options for Microsoft Azure.  If you are interested in more information about backup and restore, you can visit https://msdn.microsoft.com/library/azure/jj573031.aspx.

If the OS has been generalized/deprovisioned, the virtual machine must be shut down in order to capture it as a VM Image.  Once the VM has been captured as a VM Image, the virtual machine will automatically be deleted.  If the OS is specialized, the virtual machine can be captured while it is running or shut down.  The captured virtual machine remains untouched.  If an application consistent or cross-disk capture is needed, we recommend the virtual machine is shut down prior to capturing the VM Image.

How Do I Use a VM Image

You can use a VM Image when creating a virtual machine as part of a new or existing deployment.  To deploy a new VM, make sure the virtual machine and VM Image location are the same and then simply provide the name of the VM Image to use.  If the VM Image is generalized, provisioning information and network configuration should also be provided, like with an OS Image today.  Once the virtual machine has been deployed, it behaves the same as any other VM created from OS Images or OS disks.  The role can be updated, additional disks may be attached, or the existing disks detached.

If the VM Image is specialized, no provisioning information is needed, like with an OS disk today.  When a virtual machine is deployed from a VM Image, a copy of the VHDs are made for the new VM; in other words, the existing VHDs are not attached directly.  After deploying a virtual machine from a specialized VM Image, the VM will spin up and look to be in a running state very quickly after deployment, since provisioning was not required.  However, the virtual machine may still be booting up, requiring a few additional minutes for remote desktop/SSH to be ready. Once again, after the virtual machine is deployed and running, it behaves the same as any other VM created from OS Images or OS disks.  One small caveat to this statement is when you deploy a new virtual machine from a specialized Windows VM Image that was captured from a running VM. When using such a VM Image, you may see a dialog pop up stating the VM was not properly shutdown when you first remote desktop into the newly deployed VM.

PowerShell

Just to whet your appetite and get you started with VM Images, I have provided a few PowerShell snippets that illustrate how to create and use VM Images.  Don’t worry if this leaves you wanting more. We will shortly follow-up with a comprehensive ‘How To’ blog post on VM Image PowerShell.

Save-AzureVMImage

To capture an existing virtual machine named ‘myVMToCapture’ as a VM Image named ‘myAwesomeVMImage’, use the Save-AzureVMImage cmdlet:

Save-AzureVMImage –ServiceName “myServiceName” –Name “myVMtoCapture” –OSState “Generalized” –ImageName “myAwesomeVMImage” –ImageLabel “This is my Virtual Machine Image”

Note, this is the same cmdlet you would use to capture a VM as an OS Image.  There is now an additional parameter set that allows you to decide between capturing your VM as an OS Image or a VM Image.  The OSState parameter is a new and required parameter to capture VM Images.

Get-AzureVMImage

To list all VM Images in the image repository, use the Get-AzureVMImage cmdlet:

Get-AzureVMImage

This cmdlet will return a combined list of OS Images and VM Images.  OS Images will be returned first, followed by VM Images.

If you are interested in only VM Images, you can remove OS Images, by using several properties that will always be null for an OS Image to filter them out:

Get-AzureVMImage | where {(gm –InputObject $_ -Name DataDiskConfigurations) -ne $null} | Select -Property Label, ImageName

New-AzureVMImage

To deploy a VM in West US using the VM Image ‘myAwesomeVMImage’

New-AzureQuickVM –Windows –Location “West US” –ServiceName “MySvc1” –Name “myVM1” –InstanceSize “Medium” –ImageName “myAwesomeVMImage” –AdminUsername “admin”–Password “adminPassword123” -WaitForBoot

Let me know if you have any questions,

Christine

Update on 5/20/2014: PowerShell snippet to filter OS Images using Get-AzureVMImage has been modified.