Cloud Computing

Converting Azure VM Disks to Managed Disks

In this post, I will show you how to convert a virtual machine, not in an availability set, but with virtual hard disks in a storage account (without encryption) to a virtual machine using Managed Disks.

 

 

Sponsored Content

Maximize Value from Microsoft Defender

In this ebook, you’ll learn why Red Canary’s platform and expertise bring you the highest possible value from your Microsoft Defender for Endpoint investment, deployment, or migration.

The Virtual Machine

There is nothing unusual about the Azure Resource Manager virtual machine that I will convert. It has an OS disk, a temp drive, and some data disks. Keep in mind that the Managed Disk is ARM only.

The unmanaged disks of the Azure virtual machine [Image Credit: Aidan Finn]
The Unmanaged Disks of the Azure Virtual Machine [Image Credit: Aidan Finn]
 

The OS disk and the data disks are stored in a storage account. These are the disks that will be converted. The temp drive is stored on the Hyper-V host in Azure, not in a storage account, and is not subject to conversion.

The unmanaged disks in the storage account container [Image Credit: Aidan Finn]
The Unmanaged Disks in the Storage Account Container [Image Credit: Aidan Finn]

Preparing to Convert

We will be using PowerShell to do the conversion. Keep in mind, the necessary cmdlet is only available in the latest version of the PowerShell modules. Make sure you update the Azure PowerShell modules on your PC before you proceed. You will need to reboot if this is the first time you have installed the modules.

We will be using a cmdlet called ConvertTo-AzureRmVMManagedDisk to do the conversion. If this cmdlet is not available on your PC, then try updating your ARM Compute module with the below command in an elevated PowerShell window. Note that I wrote this article on February 18th.  Therefore, you probably will not need to run the below command after the next update to the ARM PowerShell modules installer but here it is just in case.

Install-Module AzureRM.Compute -RequiredVersion 2.6.0 -AllowClobber

Converting the Disks

You can use the following small PowerShell script to convert the disks of a virtual machine from unmanaged disks to Managed Disks.

$ResourceGroupName = "rg-petri3"
$VMName = "vm-petri3"
$SubscriptionID = "1a2b3c45-aa12-1a23-12a3-a1bcdefg345h"

Login-AzureRmAccount

Select-AzureRmSubscription -SubscriptionId $SubscriptionID

Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName -Force

ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $ResourceGroupName -VMName $VMName

 

The first section of the script prepares three variables to store information about your environment:

  • ResourceGroupName: The name of the resource group that contains the virtual machine you wish to convert to use Managed Disks
  • VMName: The name of the virtual machine in question
  • SubscriptionID: The GUID of the subscription that contains the resource group and the virtual machine

The first command will request your login credentials so that the current PowerShell session can sign you into your account.

The second line selects the subscription that contains the machine/disks that you wish to convert. I included this line because many people have access to more than one subscription when they sign in. We need to select the correct active subscription.

You cannot convert a virtual machine’s disks to Managed Disks without shutting it down first. I use the resource group name and the virtual machine name with Stop-AzureRMVM to shut the desired machine down.

The final step, ConvertTo-AzureRmVMManagedDisk, uses the resource group name and the virtual machine name to start the conversion of the machine’s disks.

The virtual machine is automatically started up again. At this time, the locks on the original virtual hard disk blobs in the storage account are released. Once you are happy with the conversion, you can delete the original blobs. If the storage account is not being used for anything else (such as other virtual machines or virtual machine diagnostics), then you can delete the storage account.

The Azure virtual machine after conversion to Managed Disks [Image Credit: Aidan Finn]
The Azure Virtual Machine After Conversion to Managed Disks [Image Credit: Aidan Finn]
 

From the time I started the script to completion, it took approximately 5 minutes to convert my demo lab machine. Please note, the virtual machine was in a running state.

What About Availability Sets?

This post showed you a very simple example with a virtual machine that is not in an availability set. I’ll show you how to convert virtual machines in an availability set in a later post.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by:

 
Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: