Capture an image of a Linux VM in Azure using CLI 2.0 | Microsoft Docs

Views: 873

I used the following instructions to create my first Azure VM Image.

  1. sudo waagent -deprovision+user
    

    Note

    Only run this command on a VM that you intend to capture as an image. It does not guarantee that the image is cleared of all sensitive information or is suitable for redistribution. The +user parameter also removes the last provisioned user account. If you want to keep account credentials in the VM, just use -deprovision to leave the user account in place.

  2. Type y to continue. You can add the -force parameter to avoid this confirmation step.
  3. After the command completes, type exit. This step closes the SSH client.

Step 2: Create VM image

Use the Azure CLI 2.0 to mark the VM as generalized and capture the image. In the following examples, replace example parameter names with your own values. Example parameter names include myResourceGroupmyVnet, and myVM.

  1. Deallocate the VM that you deprovisioned with az vm deallocate. The following example deallocates the VM named myVM in the resource group named myResourceGroup:
    Azure CLI
    az vm deallocate \
      --resource-group myResourceGroup \
      --name myVM
    
  2. Mark the VM as generalized with az vm generalize. The following example marks the the VM named myVM in the resource group named myResourceGroup as generalized:
    Azure CLI
    az vm generalize \
      --resource-group myResourceGroup \
      --name myVM
    
  3. Now create an image of the VM resource with az image create. The following example creates an image named myImage in the resource group named myResourceGroup using the VM resource named myVM:
    Azure CLI
    az image create \
      --resource-group myResourceGroup \
      --name myImage --source myVM
    

    Note

Source: Capture an image of a Linux VM in Azure using CLI 2.0 | Microsoft Docs

Leave a Reply