Troubleshooting, Image capturing of VM

Varshney, Aayushi 0 Reputation points
2025-04-08T13:47:02.1366667+00:00

User's image

I am trying to capture image of a vm and save it into gallery and getting this error any assistance please??

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,036 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Arko 4,150 Reputation points Microsoft External Staff Moderator
    2025-04-16T15:07:38.14+00:00

    Hello Varshney, Aayushi, the 400 Bad Request error typically indicates that some parameter passed to the az sig image-version create command is either invalid, malformed, or missing. In your case, based on the verbose part of the URL, --sku ""v1.0"" is invalid — double quotes inside double quotes.

    It should be --sku v1 or any non-empty string without special quotes. Also managed image $IMAGE_NAME is not found or incorrectly referenced. You need to reference either a managed image resource ID or an existing VM name (if using --source)

    or you might have incorrect --hyper-v-generation vs source image compatibility i.e. if you have set --hyper-v-generation V2 but your source image is V1 or doesn’t support secure boot.

    Please reference from the below steps and let me know

    
    az vm create \
    
      --resource-group arkorg \
    
      --name mySourceVM \
    
      --image Canonical:UbuntuServer:18_04-lts-gen1:latest \
    
      --size Standard_D2s_v3 \
    
      --admin-username azureuser \
    
      --generate-ssh-keys \
    
      --security-type Standard \
    
      --enable-secure-boot false \
    
      --enable-vtpm false
    
    

    Note- Only Gen1 images work here. Gen2 images often cause SecureBootClientError if they are unsigned. You can list Gen1 images using-

    
    az vm image list \
    
      --publisher Canonical \
    
      --offer UbuntuServer \
    
      --sku 18_04-lts \
    
      --all \
    
      --location westeurope \
    
      --output table
    
    

    enter image description here

    Generalize the VM

    
    az vm deallocate --resource-group arkorg --name whatever_is_ur_vm_name
    
    az vm generalize --resource-group arkorg --name whatever_is_ur_vm_name
    
    

    enter image description here

    Create a shared image gallery & definition

    
    az sig create \
    
      --resource-group arkorg \
    
      --gallery-name myGallery
    
    az sig image-definition create \
    
      --resource-group arkorg \
    
      --gallery-name myGallery \
    
      --gallery-image-definition myImageDef \
    
      --publisher myPublisher \
    
      --offer UbuntuServer \
    
      --sku v1 \
    
      --os-type Linux \
    
      --os-state Generalized \
    
      --hyper-v-generation V1
    
    

    Please note- default is Gen2 with TrustedLaunch. Use --hyper-v-generation V1 explicitly and omit security flags if using az sig image-definition.

    enter image description here

    Create an image version from the generalized VM

    
    az sig image-version create \
    
      --resource-group arkorg \
    
      --gallery-name myGallery \
    
      --gallery-image-definition myImageDef \
    
      --gallery-image-version 1.0.0 \
    
      --managed-image /subscriptions/<SUB_ID>/resourceGroups/arkorg/providers/Microsoft.Compute/images/myManagedImage
    
    

    Alternatively, if you're using a VM directly the run this-

    
    az sig image-version create \
    
      --resource-group arkorg \
    
      --gallery-name myGallery \
    
      --gallery-image-definition myImageDef \
    
      --gallery-image-version 1.0.0 \
    
      --source mySourceVM
    
    

    Reference MS documents-


  2. Alex Burlachenko 10,255 Reputation points
    2025-05-05T16:06:30.33+00:00

    Hi Varshney, Aayushi, thank you for posting your question on the Q&A portal regarding the VM image capture issue. The error you encountered ("Bad Request") often occurs due to misconfigured parameters or syntax issues in the Azure CLI command.

    For troubleshooting, ensure:

    • The IMAGE_DEFINITION variable is correctly referenced in the image-version create command.

    The VM is generalized (using sudo waagent -deprovision+user for Linux) before capturing.

    Capture a VM image using Azure CLI

    Let me know if you need further clarification!

    Best regards,
    Alex
    P.S. If my answer help to you, please Accept my answer
    PPS That is my Answer and not a Comment
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.