Views: 875
I used the following instructions to create my first Azure VM Image.
-
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.
- Type y to continue. You can add the -force parameter to avoid this confirmation step.
- 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 myResourceGroup, myVnet, and myVM.
- 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
- 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
- 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