Edit

Share via


Create Azure Local VM image by using existing Azure Local VMs enabled by Azure Arc

Applies to: Hyperconverged deployments of Azure Local 2408.2 and later

This article describes how to create Azure Local VM images using Azure Command-Line Interface (CLI) and existing Azure Local VMs. Learn to use the operating system (OS) disk of an Azure Local VM to create a gallery image on your Azure Local.

Prerequisites

Before you begin, make sure that you:

  • Review and complete the Azure Local VM management prerequisites.

  • Connect to your Azure Local by using the instructions in Connect to Azure Local via Azure CLI client.

  • Connect to the source VM with your credentials and run this command:

    azcmagent disconnect --force-local-only
    

    Caution

    Running the azcmagent disconnect --force-local-only command deletes the VM's corresponding Azure resource and resets the local agent's configuration. This action is irreversible.

  • Prepare the VHDX image by using sysprep /generalize /shutdown /oobe. For more information, see Sysprep command-line options. This step applies to both Windows and Linux VM images.

    Caution

    Running Sysprep on an Azure Local VM renders the VM unusable. Sysprep resets system identity, removes user profiles, may invalidate Windows product activation, and can cause instability for applications that rely on machine-specific configuration. This action is irreversible.

  • Power off the source VM before you attempt to create the VM image.

Create VM image from existing Azure Local VM

Create a VM image starting from the OS disk of the Azure Local VM. Then use this image to deploy VMs on your Azure Local.

Follow these steps to create a VM image by using the Azure CLI.

Sign in and set subscription

  1. Connect to a machine on your Azure Local instance.

  2. Sign in and enter the following command:

    az login --use-device-code
    
  3. Set your subscription.

    az account set --subscription <Subscription ID>
    

Set some parameters

Set your subscription, resource group, location, path to the image in local share, and OS type for the image. Replace the parameters in < > with the appropriate values.

$subscription = "<Subscription ID>"
$resource_group = "<Resource group>"
$location = "<Location for your Azure Local>"
$custom_location = "<Custom location for your Azure Local>"
$osType = "<OS of source VM>"
$imageName = "<VM image name>"
$sourceVmName = "<Name of source VM in the storage account>"

The parameters are described in the following table:

Parameter Description
subscription Subscription for the Azure Local instance that you associate with this image.
resource_group Resource group for the Azure Local instance that you associate with this image.
location Location for your Azure Local. For example, eastus.
custom-location Custom location ID for your Azure Local.
name Name of the VM image created starting with the image in your local share.
Note: Azure rejects all the names that contain the keyword Windows.
source-vm Name of an existing Azure Local VM that you use to create the VM image.
os-type Operating system associated with the source image. For example, Windows or Linux.

Here's a sample output:

PS C:\Users\azcli> $subscription = "mysub-id"
PS C:\Users\azcli> $resource_group = "mylocal-rg"
PS C:\Users\azcli> $location = "eastus"
PS C:\Users\azcli> $custom_location = "mylocal-cl"
PS C:\Users\azcli> $osType = "Windows"
PS C:\Users\azcli> $imageName = "mylocal-image"
PS C:\Users\azcli> $sourceVmName = "mysourcevm"

Add VM image from an Azure Local VM

Create the VM image from an existing VM. Run the following command:

az stack-hci-vm image create -resource-group $resource_group --location $location --custom-location $custom_location --os-type $osType --source-vm $sourceVmName --name $imageName

A deployment job starts for the VM image. The image deployment takes a few minutes to complete.

Here's a sample output:

{
  "extendedLocation": {
    "name": "/subscriptions/mysub-id/resourceGroups/mylocal-rg/providers/Microsoft.ExtendedLocation/customLocations/mylocal-cl",
    "type": "CustomLocation"
  },
  "id": "/subscriptions/mysub-id/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/galleryImages/mylocal-image",
  "location": "eastus",
  "name": "mylocal-image",
  "properties": {
    "cloudInitDataSource": null,
    "containerId": null,
    "hyperVGeneration": null,
    "identifier": null,
    "imagePath": null,
    "osType": "Windows",
    "provisioningState": "Succeeded",
    "sourceVirtualMachineId": "/subscriptions/mysub-id/resourceGroups/mylocal-rg/providers/Microsoft.HybridCompute/machines/mysourcevm/providers/Microsoft.AzureStackHCI/virtualMachineInstances/default",
    "status": {
      "downloadStatus": {
        "downloadSizeInMb": null
      },
      "errorCode": "",
      "errorMessage": "",
      "progressPercentage": null,
      "provisioningStatus": {
        "operationId": null,
        "status": null
      }
    },
    "version": {
      "name": null,
      "properties": {
        "storageProfile": {
          "osDiskImage": {
            "sizeInMb": null
          }
        }
      }
    }
  },
  "resourceGroup": "mylocal-rg",
  "systemData": {
    "createdAt": "2024-09-26T20:16:17.625002+00:00",
    "createdBy": "a5e473cb-e3e7-4035-b4da-290a65350ae1",
    "createdByType": "Application",
    "lastModifiedAt": "2024-09-26T20:16:17.625002+00:00",
    "lastModifiedBy": "a5e473cb-e3e7-4035-b4da-290a65350ae1",
    "lastModifiedByType": "Application"
  },
  "tags": null,
  "type": "microsoft.azurestackhci/galleryimages"
}

Next steps