Azure Linux Support Team

Support for Linux on Azure

AZ CLI: How to delete and re-deploy a VM from VHD

Before moving further, please, make sure you have the Azure CLI tools installed:
Install the Azure CLI

For the steps to work properly, please, make sure you are logged in to the Azure CLI:
az login

NOTE: You will get a code which you then have to type in the box using the link and proceeding with logging in to your Azure account. Once you go through that you can go back to the prompt.

In this example, the following variables will be used:

Resource Group: ARMGROUP
Original VM Name: LinuxVM
Location: southcentralus
NIC Name: LinuxVM-NIC

If you want to keep some information from the VM before deleting:

az vm show –resource-group CLI –name ubuntunew > ORIGINAL_VM.txt

Deleting a VM on ARM using the CLI:

az vm delete –resource-group ARMGROUP –name LinuxVM

Recreating the VM from the Original VHD:

az vm create –resource-group ARMGROUP –name LinuxVM –nics LinuxVM-NIC –use-unmanaged-disk
–attach-os-disk –size Standard_D1_V2 –location southcentralus
–os-type Linux

After the command is executed you should be able to see the VM on the Azure Portal. You might need to re-enable diagnostics in the particular VM.