
close
close
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.
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 in the Storage Account Container [Image Credit: Aidan Finn]
advertisment
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
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:
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]
advertisment
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.
More from Aidan Finn
advertisment
Petri Newsletters
Whether it’s Security or Cloud Computing, we have the know-how for you. Sign up for our newsletters here.
advertisment
More in Cloud Computing
Build 2022: Microsoft Introduces New Dev Box Cloud PC Service for Developers
May 24, 2022 | Rabia Noureen
Use Azure ExpressRoute Private Peering & Azure Virtual WAN to Connect Privately to Microsoft 365
Apr 21, 2022 | Flo Fox
Microsoft to Make Changes to Cloud Licensing Restrictions after Customer Complaints
Apr 18, 2022 | Rabia Noureen
Most popular on petri
Log in to save content to your profile.
Article saved!
Access saved content from your profile page. View Saved
Join The Conversation
Create a free account today to participate in forum conversations, comment on posts and more.
Copyright ©2019 BWW Media Group