Swapping the OS disk of an Azure VM is very useful for certain scenarios, like troubleshooting issues or upgrading the operating system. In this article, we will walk you through all those approaches.
Table of Contents
How To Swap OS Disk In Azure Virtual Machine
Let us dive deep into these two approaches individually.
- Approach -1: Using Azure Portal
- Approach – 2: Using Azure PowerShell
Approach -1: Using Azure Portal
Follow the below steps
1. Log in to Azure Portal (https://portal.azure.com/).
2. Search for Virtual Machine and click on the search result in Virtual Machines as shown below.

3. Now, you will see the lists of Azure Virtual machines that you have created. Click on the one for which we will swap the OS disk.

4. On the Virtual Machine page, click the Disks option present under Settings from the left navigation, then click on the swap OS disk option as highlighted below.

5. On the swap OS disk window, select the new managed disk from the Choose disk dropdown. If no other managed disk is available, it will show “no managed disks available.” Then confirm you want to swap the OS disk for this VM by entering the exact name of the VM, as shown in the screenshot below. Finally, click on the OK button, as shown below, and you are done.

Now, you can able to see the disk has been changed successfully. Check out the screenshot below.

Approach – 2: Using Azure PowerShell
You can also use the Azure PowerShell script below to swap the OS disk in your Azure VM using PowerShell.
# Get your Virtual Machine details
$myvm = Get-AzVM -ResourceGroupName newresgroup -Name AzureLessonsVM
# Stop your VM
Stop-AzVM -ResourceGroupName newresgroup -Name $myvm.Name -Force
# Retrieve the new disk details
$newdisk = Get-AzDisk -ResourceGroupName NEWRESGROUP -Name AzurelessonsVM2_disk1_56b6a3d6fa3c46d09882b933432ea6e5
# Configure your VM to point to the new os disk
Set-AzVMOSDisk -VM $myvm -ManagedDiskId $newdisk.Id -Name $newdisk.Name
# Update your virtual machine with the new disk
Update-AzVM -ResourceGroupName newresgroup -VM $myvm After executing the above PowerShell script, I got the expected output as below.

Now, to cross-check, I logged in to the Azure Portal and saw that the new OS disk had been swapped successfully. Check out the screenshot below for your reference.

Video Tutorial
You may also like following the articles below.
- How to delete disk in Azure
- How to increase disk size in Azure VM
- How to find unattached disks in Azure

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
