Troubleshoot a VMs operating system disk
This script mounts the operating system disk of a failed or problematic virtual machine as a data disk to a second virtual machine. This can be useful when troubleshooting disk issues or recovering data.
To run this sample, install the latest version of the Azure CLI. To start, run az login
to create a connection with Azure.
Samples for the Azure CLI are written for the bash
shell. To run this sample in Windows PowerShell or Command Prompt, you may need to change
elements of the script.
If you don't have an Azure subscription, create a free account before you begin.
Script explanation
This script uses the following commands to create a resource group, virtual machine, and all related resources. Each command in the table links to command specific documentation.
Command | Notes |
---|---|
az vm show | Return a list of virtual machines. In this case, the query option is used to return the virtual machine operating system disk. This value is then added to a variable name ‘uri’. |
az vm delete | Deletes a virtual machine. |
az vm create | Creates a virtual machine. |
az vm disk attach | Attaches a disk to a virtual machine. |
az vm list-ip-addresses | Returns the IP addresses of a virtual machine. |
Next steps
For more information on the Azure CLI, see Azure CLI documentation.
Additional virtual machine CLI script samples can be found in the Azure Linux VM documentation.