This article shows you how to capture an Azure virtual machine running Linux so you can use it like a template to create other virtual machines. This template includes the OS disk and data disks attached to the virtual machine. It doesn't include networking configuration, so you'll need to configure that when you create the other virtual machines that use the template.
Azure treats this template as an image and stores it under Images. This is also where any images you've uploaded are stored. For more information about images, see About Virtual Machine Images in Azure.
These steps assume that you've already created an Azure virtual machine using the classic deployment model and configured the operating system, including attaching any data disks. If you haven't done this yet, see these instructions:
Connect to the virtual machine using an SSH client of your choice. For details, see How to Log on to a Virtual Machine Running Linux.
In the SSH window, type the following command. Note that the output from
waagent may vary slightly depending on the version of this utility:
sudo waagent -deprovision
This command will attempt to clean the system and make it suitable for re-provisioning. This operation performs the following tasks:
rootuser's password from /etc/shadow (if Provisioning.DeleteRootPassword is 'y' in the configuration file)
Deprovisioning deletes files and data in an effort to "generalize" the image. Only run this command on virtual machines that you intend to capture as a new image template. It does not guarantee that the image is cleared of all sensitive information or is suitable for redistribution to third parties.
Type y to continue. You can add the
-force parameter to avoid this confirmation step.
Type Exit to close the SSH client.
From your client computer, open Azure CLI and login to your Azure subscription. For details, read Connect to an Azure subscription from the Azure CLI.
Make sure you are in Service Management mode:
azure config mode asm
Shut down the virtual machine which is already deprovisioned in the steps above with:
azure vm shutdown <your-virtual-machine-name>
When the virtual machine is stopped, capture the image with the command:
azure vm capture -t <your-virtual-machine-name> <new-image-name>
Type the image name you want in place of new-image-name. This command creates a generalized OS image. The
-t subcommand deletes the original virtual machine.
The new image is now available in the list of images that can be used to configure any new virtual machines. You can view it with the command:
azure vm image list
On the Management Portal, it will appear in the IMAGES list.
The image is ready to be used as a template to create virtual machines. You can use the Azure CLI command
azure vm create and supply the image name you just created. See Using Azure CLI with the Service Management API for details about the command. Alternatively, you can use the Management Portal to create a custom virtual machine by using the From Gallery method and selecting the image you just created. See How to Create a Custom Virtual Machine for more details.
See Also: Azure Linux Agent User Guide