Convert Unmanaged Disk to Managed Disk
Blogs 1 CommentHi!
As I promissed in my last post about creating Managed disks in Azure you also have the option to convert your existing VM’s (Unmanaged disks) to Managed Disks!
The requirments for converting a unmanged disk (UMD) to managed disk (MD):
- The Unmanged Disk(s) is not in a Encrypted storage accout (SSE)
- The VM is created in ARM (Azure Resource manager)
- The conversion cannot be performed in the Azure Portal; Use Powershell
- All disks attached to your VM will be converted (That is: OSDisk and Datadisk(s))
Note1: You could also convert a Classic VM (ASM) to have Managed Disks. In this case you have to mgirate the Classic VM to ARM. This may also include a migration of your VNET and/or Public IP’s to ARM etc.
Note2: If you want to convert UMD’s in a Encrypted storage account (SSE) you have to move the disks (VHD’s) to a Unencrypted Storage Account before converting to MD. After conversion to MD you can encrypt your MD’s with Azure Disk Encryption
Convert a single VM from Unmanaged disk (UMD) to Managed disk (MD)
Ok! lets check which type of OS disk your VM has:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#Add your Resource group and VM details: $ResourceGroup = "RG-W2k16-2" $VM = "WindowsVM02" #Check if your VM has UMD ('MangedDisk' should be empty): (Get-AzureRmVM -ResourceGroupName $ResourceGroup -Name $VM).StorageProfile.OsDisk OsType : Windows EncryptionSettings : Name : WindowsVM02 Vhd : Microsoft.Azure.Management.Compute.Models.VirtualHardDisk Image : Caching : ReadWrite CreateOption : FromImage DiskSizeGB : ManagedDisk : #Just to be sure. check your VHD uri: (Get-AzureRmVM -ResourceGroupName $ResourceGroup -Name $VM).StorageProfile.OsDisk.Vhd.Uri https://<YourSA>.blob.core.windows.net/vhds/<YourVHD-Name>.vhd |
note: you could also check for StorageProfile.DataDisk if your VM has Data disk(s) attached to it
Now we know your VM has a UMD, lets convert it to a MD:
1 2 3 4 5 |
#Stop Azure VM: Stop-AzureRmVM -Name $VM -ResourceGroupName $ResourceGroup #Convert VM with UMD to MD: ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $ResourceGroup -VMName $VM |
Check again if your VM has a Managed disk:
1 2 3 4 5 6 7 8 9 10 11 12 |
#Check if your VM has a Managed Disk: (Get-AzureRmVM -ResourceGroupName $ResourceGroup -Name $VM).StorageProfile.OsDisk OsType : Windows EncryptionSettings : Name : WindowsVM02_WindowsVM02 Vhd : Image : Caching : ReadWrite CreateOption : FromImage DiskSizeGB : 128 ManagedDisk : Microsoft.Azure.Management.Compute.Models.ManagedDiskParameters |
note about Data Disk(s): In the above example I have only showed you the conversion of a Single VM with one OSDisk. Please be aware that your Data Disk(s), if you have them attached to your VM, will also be converted to Managed Disks.
Convert VM’s in an availability set to managed disks (MD) in a managed availability set
For VM’s running in a availability set the conversion is slightly different. in short the steps:
- Convert your Availability set to a ‘Managed Availability set’
- Convert each VM in the Managed Availability set to MD’s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#Add your Resource group name and Availability set: $rgName = 'myResourceGroup' $avSetName = 'myAvailabilitySet' $avSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rgName -Name $avSetName #converts your availability set to managed: Update-AzureRmAvailabilitySet -AvailabilitySet $avSet -Managed #Stop VM's in AV and convert each VM to managed MD's: foreach($vmInfo in $avSet.VirtualMachinesReferences) { $vm = Get-AzureRmVM -ResourceGroupName $rgName | Where-Object {$_.Id -eq $vmInfo.id} Stop-AzureRmVM -ResourceGroupName $rgName -Name $vm.Name -Force ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $rgName -VMName $vm.Name } |
Thats it for now! happy converting!
Next posts i will be convering the details about re-sizing MD’s and upgrade MD’s to premium storage.
gr,
Pieterbas
Resources:
Convert a VM from unmanaged disks to managed disks
Pingback: Creating a VM with Azure Managed Disk – Azure IT is!