LinuxCommandLibrary

az-image

Manage virtual machine images in Azure

TLDR

List the custom images under a resource group

$ az image list --resource-group [resource_group]
copy

Create a custom image from managed disks or snapshots
$ az image create --resource-group [resource_group] --name [name] --os-type [windows|linux] --source [os_disk_source]
copy

Delete a custom image
$ az image delete --name [name] --resource-group [resource_group]
copy

Show details of a custom image
$ az image show --name [name] --resource-group [resource_group]
copy

Update custom images
$ az image update --name [name] --resource-group [resource_group] --set [property=value]
copy

SYNOPSIS

az image create --name --resource-group [--data-disk-sources ] [--hyper-v-generation {V1,V2}] [--location ] [--os-disk ] [--os-type {linux,windows}] [--source ] [--storage-account ] [--tags ] [--zone-resilient {false,true}]

PARAMETERS

--name
    Required.
The name of the image.

--resource-group
    Required.
The name of the resource group.

--data-disk-sources
    A list of data disk image resource IDs or URIs.

--hyper-v-generation {V1,V2}
    The hypervisor generation of the Virtual Machine. Allowed values: V1, V2.

--location
    Location. Values from: `az account list-locations`. You can configure the default location using `az configure --defaults location=`.

--os-disk
    The OS disk image resource ID or URI.

--os-type {linux,windows}
    The OS type of the image. Allowed values: linux, windows.

--source
    The source virtual machine ID or URI. Creating an image from a VM requires the VM to be deallocated before the image creation. Alternatively you can use a managed snapshot. This allows capturing an image without the downtime of deallocating the source VM.

--storage-account
    The storage account to use for storing the image. If omitted, a new storage account will be created.

--tags
    Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--zone-resilient {false,true}
    Indicates whether the image is zone resilient or not. Default: false.

DESCRIPTION

The `az image` command in the Azure CLI is used to manage virtual machine images within your Azure subscriptions. This includes creating, deleting, updating, and listing VM images. Images are templates for creating virtual machines, encapsulating the operating system, installed software, and configuration settings. Using `az image`, you can streamline the process of deploying multiple VMs with consistent configurations.

You can create images from existing VMs, captured snapshots of VMs, or even from generalized operating system disks. This provides flexibility in building and managing standardized VM environments. Common tasks include creating custom images with pre-installed software for development or testing purposes or creating golden images for consistent deployments across your organization. The command supports various options for specifying the source of the image, its location, and other properties, making it a powerful tool for infrastructure management.

CAVEATS

Creating an image from a running VM without proper generalization (using `waagent -deprovision+user` on Linux or `sysprep` on Windows) can lead to issues with duplicate machine IDs and potential conflicts on the network.

IMAGE GENERALIZATION

Before creating an image from a virtual machine, it's crucial to generalize the operating system. Generalization removes machine-specific information, such as user accounts, computer names, and security identifiers (SIDs). On Linux, use the `waagent -deprovision+user` command. On Windows, use the System Preparation Tool (Sysprep) with the `/generalize` option. Failure to generalize properly can result in deployment issues and security risks.

IMAGE STORAGE

Azure VM images are stored as Managed Images in Azure. These Managed Images offer advantages over unmanaged images in terms of storage management, resiliency, and availability. When creating an image, you can specify the storage account to use. If you don't specify one, Azure creates a storage account for you.

For zone-resilient images, the storage account selected is often zone-redundant to ensure high availability.

HISTORY

The `az image` command is part of the Azure CLI, which has been actively developed by Microsoft to provide a command-line interface for managing Azure resources. The command has evolved alongside the Azure platform, with new features and capabilities added to support the changing needs of cloud users.

SEE ALSO

az vm(1), az snapshot(1), az disk(1)

Copied to clipboard