How To: Create A Generalized Image


Intro

To create multiple copies of a virtual machine (VM) for use in Azure for development and test, capture a managed image of the VM or of the OS VHD. To create, store and share images at scale, see Shared Image Galleries.

One managed image supports up to 20 simultaneous deployments. Attempting to create more than 20 VMs concurrently, from the same managed image, may result in provisioning timeouts due to the storage performance limitations of a single VHD. To create more than 20 VMs concurrently, use a Shared Image Galleries image configured with 1 replica for every 20 concurrent VM deployments.

 


Documentation

 

 


Steps

 

  • SSH to the machine and deprovision the virtual machine using the Azure Linux Agent command

sudo waagent -deprovision+user WARNING! The waagent service will be stopped. WARNING! Cached DHCP leases will be deleted. WARNING! root password will be disabled. You will not be able to login as root. WARNING! /etc/resolvconf/resolv.conf.d/tail and /etc/resolvconf/resolv.conf.d/original will be deleted. WARNING! azureuser account and entire home directory will be deleted. Do you want to proceed (y/n)y

 

  • Deallocate the virtual machine, and then mark it as generalized.

az vm deallocate --resource-group rg1lod16727460 --name app-server az vm generalize --resource-group rg1lod16727460 --name app-server

 

  • Create an image of the VM resource

az image create --resource-group rg1lod16727460 --name app-server-image --source app-server {\ Finished .. "extendedLocation": null, "hyperVGeneration": "V1", "id": "/subscriptions/6474fbd5-eeef-432f-94ec-861410d81d1d/resourceGroups/rg1lod16727460/providers/Microsoft.Compute/images/app-server-image", "location": "eastus", "name": "app-server-image", "provisioningState": "Succeeded", "resourceGroup": "rg1lod16727460", "sourceVirtualMachine": { "id": "/subscriptions/6474fbd5-eeef-432f-94ec-861410d81d1d/resourceGroups/rg1lod16727460/providers/Microsoft.Compute/virtualMachines/app-server", "resourceGroup": "rg1lod16727460" }, "storageProfile": { "dataDisks": [], "osDisk": { "blobUri": null, "caching": "ReadWrite", "diskEncryptionSet": null, "diskSizeGb": 30, "managedDisk": { "id": "/subscriptions/6474fbd5-eeef-432f-94ec-861410d81d1d/resourceGroups/rg1lod16727460/providers/Microsoft.Compute/disks/app-server_disk1_e02f2c13267c46bfa836c48d12f98b6d", "resourceGroup": "rg1lod16727460" }, "osState": "Generalized", "osType": "Linux", "snapshot": null, "storageAccountType": "Premium_LRS" }, "zoneResilient": null }, "tags": {}, "type": "Microsoft.Compute/images" }

 

Â