Download a Linux VHD from Azure
In this article, you learn how to download a Linux virtual hard disk (VHD) file from Azure using the Azure CLI and Azure portal.
If you haven't already done so, install Azure CLI.
Stop the VM
A VHD can’t be downloaded from Azure if it's attached to a running VM. You need to stop the VM to download a VHD. If you want to use a VHD as an image to create other VMs with new disks, you need to deprovision and generalize the operating system contained in the file and stop the VM. To use the VHD as a disk for a new instance of an existing VM or data disk, you only need to stop and deallocate the VM.
To use the VHD as an image to create other VMs, complete these steps:
Use SSH, the account name, and the public IP address of the VM to connect to it and deprovision it. You can find the public IP address with az network public-ip show. The +user parameter also removes the last provisioned user account. If you are baking account credentials in to the VM, leave out this +user parameter. The following example removes the last provisioned user account:
ssh azureuser@<publicIpAddress> sudo waagent -deprovision+user -force exit
Sign in to your Azure account with az login.
Stop and deallocate the VM.
az vm deallocate --resource-group myResourceGroup --name myVM
Generalize the VM.
az vm generalize --resource-group myResourceGroup --name myVM
To use the VHD as a disk for a new instance of an existing VM or data disk, complete these steps:
Sign in to the Azure portal.
On the left menu, select Virtual Machines.
Select the VM from the list.
On the page for the VM, select Stop.
Generate SAS URL
To download the VHD file, you need to generate a shared access signature (SAS) URL. When the URL is generated, an expiration time is assigned to the URL.
On the menu of the page for the VM, select Disks.
Select the operating system disk for the VM, and then select Disk Export.
Select Generate URL.
Under the URL that was generated, select Download the VHD file. **
You may need to select Save in the browser to start the download. The default name for the VHD file is abcd.