Repair a Windows VM by using the Azure Virtual Machine repair commands - Azure (2024)

  • Article

If your Windows virtual machine (VM) in Azure encounters a boot or disk error, you may need to repair the disk offline. A common example would be a failed application update that prevents the VM from being able to boot successfully. This article details how to use Azure VM repair commands to automatically attach a broken OS disk to another Windows VM for offline repair. Through this procedure, the failed OS disk will automatically be unlocked on the second VM, called a repair VM, if the disk is encrypted with Azure Disk Encryption. When the failed disk is attached to the repair VM, you can fix any errors and then rebuild your original VM with the repaired disk.

Important

  • The scripts in this article only apply to the VMs that use Azure Resource Manager.
  • Outbound connectivity from the VM (port 443) is required for the script to run.
  • Only one script may run at a time.
  • A running script cannot be canceled.
  • The maximum time a script can run is 90 minutes, after which it will time out.
  • Do not modify the tags that are created on the repair VM. The tags are neccessary for the restore command to function correctly.
  • For VMs using Azure Disk Encryption, only managed disks encrypted with single pass encryption (with or without KEK) are supported.

Repair process overview

You can now use Azure VM repair commands to change the OS disk for a VM, and you no longer need to delete and recreate the VM.

Follow these steps to troubleshoot the VM issue:

  1. Launch Azure Cloud Shell
  2. Run az extension add/update.
  3. Run az vm repair create.
  4. Run az vm repair run, or perform mitigation steps.
  5. Run az vm repair restore.

To view all available VM repair commands and parameters, see az vm repair.

To run the commands, you need a role that can create the following types of resources in the subscription:

  • Resource Groups
  • Virtual Machines
  • Resource Tags
  • Virtual Networks
  • Network Security Groups
  • Network Interfaces
  • Disks
  • Public IP Addresses (Optional)

Repair process example

  1. Launch Azure Cloud Shell

    The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It includes common Azure tools preinstalled and configured to use with your account. If you run a script that will take longer than 20 minutes (for example: win-sfc-sf-corruption script), you may prefer to run the commands locally. To run the commands locally, Azure CLI version 2.0.67 or later version is required. Run az --version to find the version. If you need to install or upgrade your Azure CLI, see Install Azure CLI.

    To open the Cloud Shell, select Try it from the upper-right corner of a code block. You can also open Cloud Shell in a separate browser tab by visiting https://shell.azure.com.

    Select Copy to copy the blocks of code, then paste the code into the Cloud Shell, and select Enter to run it.

    If you prefer to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.67 or later. Run az --version to find the version. If you need to install or upgrade your Azure CLI, see Install Azure CLI.

    If you need to login to Cloud Shell with a different account than you are currently logged in to the Azure portal with you can use az login az login reference. To switch between subscriptions associated with your account you can use az account set --subscription az account set reference.

  2. If this is the first time you have used the az vm repair commands, add the vm-repair CLI extension.

    az extension add -n vm-repair

    If you have previously used the az vm repair commands, apply any updates to the vm-repair extension.

    az extension update -n vm-repair
  3. Run az vm repair create. This command will create a copy of the OS disk for the non-functional VM, create a repair VM in a new Resource Group, and attach the OS disk copy. The repair VM will be the same size and region as the non-functional VM specified. The Resource Group and VM name used in all steps will be for the non-functional VM. If your VM is using Azure Disk Encryption, use --unlock-encrypted-vm to unlock the encrypted disk so that it is accessible when attached to the repair VM. For more information, see confirm that ADE is enabled on the disk. If you need to troubleshoot your VM in a nested Hyper-V environment, use --enable-nested and the repair VM will created with the Hyper-V role enabled along with a nested VM using the OS disk copy.

Important

The run and restore commands will require all inputs to be entered using the same case as used in the create command, make note or refer to the tags on the repair VM to see what was used.

Repair VM example

az vm repair create -g MyResourceGroup -n myVM --repair-username username --repair-password 'password!234' --verbose

Repair VM with Nested Hyper-V example

az vm repair create -g MyResourceGroup -n myVM --repair-username username --repair-password 'password!234' --enable-nested --verbose
  1. Run az vm repair run. This command will run the specified repair script on the attached disk via the repair VM. If the troubleshooting guide you are using specified a run-id, use it here. Otherwise, you can use az vm repair list-scripts to see available repair scripts. The Resource Group and VM name used here are for the non-functional VM used in step 3. Additional information about the repair scripts can be found in the repair script library.

    az vm repair run -g MyResourceGroup -n MyVM --run-on-repair --run-id win-hello-world --verbose

    Optionally you can perform any needed manual mitigation steps using the repair VM, then proceed to step 5.

  2. Run az vm repair restore. This command will swap the repaired OS disk with the original OS disk of the VM. The Resource Group and VM name used here are for the non-functional VM used in step 3.

    az vm repair restore -g MyResourceGroup -n MyVM --verbose

Verify and enable boot diagnostics

The following example enables the diagnostic extension on the VM named myVMDeployed in the resource group named myResourceGroup:

Azure CLI

az vm boot-diagnostics enable --name myVMDeployed --resource-group myResourceGroup --storage https://mystor.blob.core.windows.net/

Next steps

  • If you are having issues connecting to your VM, see Troubleshoot RDP connections to an Azure VM.
  • For issues with accessing applications running on your VM, see Troubleshoot application connectivity issues on virtual machines in Azure.
  • For more information about using Resource Manager, see Azure Resource Manager overview.

If you have questions or need help, create a support request, or ask Azure community support. You can also submit product feedback to Azure feedback community.

Repair a Windows VM by using the Azure Virtual Machine repair commands - Azure (2024)

FAQs

How do I create a repair VM in Azure? ›

Repair process overview
  1. Launch Azure Cloud Shell.
  2. Run az extension add/update.
  3. Run az vm repair create.
  4. Run az vm repair run, or perform mitigation steps.
  5. Run az vm repair restore.
Mar 27, 2024

How do I run Azure commands on Windows VM? ›

Go to a VM in the Azure portal and select Run command from the left menu, under Operations. You see a list of the available commands to run on the VM. Choose a command to run. Some of the commands might have optional or required input parameters.

What is VM patching in Azure? ›

Enabling automatic VM guest patching for your Azure VMs helps ease update management by safely and automatically patching virtual machines to maintain security compliance, while limiting the blast radius of VMs.

How to create VM in Azure command line? ›

If you don't have an Azure subscription, create a free account before you begin.
  1. Launch Azure Cloud Shell. ...
  2. Define environment variables. ...
  3. Log in to Azure using the CLI. ...
  4. Create a resource group. ...
  5. Create the virtual machine. ...
  6. Enable Azure AD Login for a Linux virtual machine in Azure. ...
  7. Store IP address of VM in order to SSH.
Mar 19, 2024

How to repair Virtual machine in VMware? ›

How to Repair VMDK File in VMware?
  1. First, save a backup of the original VMDK file.
  2. After that, set up a pointer for that file in the system.
  3. Then, edit the necessary fields and save those changes.
  4. In the end, restart the virtual machine to fix the damaged file.
Nov 25, 2023

What is the command to start Azure Virtual Machine? ›

Start a VM

You have to change the parameter -g (or --resource-group) with your value. Same for -n (or --name) with the name of your VM. You can start all VMs in a resource group with the command below.

What is the PowerShell command to start Azure VM? ›

Create virtual machine

Create a VM with New-AzVM. Provide names for each of the resources and the New-AzVM cmdlet creates if they don't already exist. Cost information isn't presented during the virtual machine creation process for PowerShell like it is for the Azure portal.

How do I run an Azure function from the command line? ›

There's also a Visual Studio Code-based version of this article.
  1. Configure your local environment. ...
  2. Install the Azure Functions Core Tools. ...
  3. Create and activate a virtual environment. ...
  4. Create a local function. ...
  5. Run the function locally. ...
  6. Create supporting Azure resources for your function. ...
  7. Deploy the function project to Azure.
Mar 5, 2024

How do I patch a virtual machine? ›

Try it yourself
  1. Create one or more machine groups that contain the virtual machines and virtual machine templates in your organization. ...
  2. Supply credentials for the virtual machines. ...
  3. Use the machine group in a patch scan. ...
  4. Review the scan results and then deploy missing patches.

How do I check my Azure VM patch status? ›

Check updates on a single VM

Sign in to the Azure portal. On the Azure Update Manager | Overview page, select your subscription to view all your machines, and then select Check for updates.

How do I troubleshoot a VM problem? ›

In this article, you will learn some basic steps to troubleshoot virtual machine boot issues and restore your VMs to normal operation.
  1. 1 Check the VM status. ...
  2. 2 Review the VM logs. ...
  3. 3 Verify the VM settings. ...
  4. 4 Repair the VM files. ...
  5. 5 Scan for malware. ...
  6. 6 Restore from backup. ...
  7. 7 Here's what else to consider.
Dec 26, 2023

How would you troubleshoot a VM that isn't booting? ›

Identify the reason why the boot disk isn't booting
  1. Verify that your boot disk is not full. ...
  2. Examine your virtual machine instance's serial port output. ...
  3. Enable interactive access to the serial console. ...
  4. Verify that your disk has a valid file system. ...
  5. Verify that the disk has a valid master boot record (MBR).

How do you solve problems in Azure? ›

Open App Service diagnostics

In the left navigation, click on Diagnose and solve problems. For Azure Functions, navigate to your function app, and in the top navigation, click on Platform features, and select Diagnose and solve problems from the Resource management section.

How do I create a test VM in Azure? ›

To deploy a VM from the Azure Compute Gallery (formerly know as Shared Image Gallery) image:
  1. Open the Azure Compute Gallery image version.
  2. Select Create VM.
  3. Provide a Virtual Machine Name and select a VM Size.
  4. Select Review + create. Once validation is passed, select Create.
Nov 30, 2023

How do I create a recovery service vault in Azure? ›

To create a Recovery Services vault:
  1. Sign in to the Azure portal.
  2. Search for Backup center, and then go to the Backup center dashboard.
  3. On the Overview pane, select Vault.
  4. Select Recovery Services vault > Continue.
  5. On the Recovery Services vault pane, enter the following values:
Aug 14, 2023

How do I create an ARM VM in Azure? ›

How to create an Azure Virtual Machine with ARM Template.
  1. Create your ARM Template file. ...
  2. Create PowerShell Script that will run our ARM Template. ...
  3. Create a Resource Group. ...
  4. Create storage account. ...
  5. Create Virtual Network. ...
  6. Setup IP Address and Network Interface. ...
  7. Create our Virtual Machine. ...
  8. Deploy the ARM Template.

How do I create a disaster recovery in Azure? ›

On the Azure portal, from Home > Virtual machines menu, select a VM to replicate. In Operations, select Disaster recovery. From Basics > Target region, select the target region. To view the replication settings, select Review + Start replication.

Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5820

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.