Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!
Cloud Computing

What Are Azure Managed Disks?

In today’s Ask the Admin, I’ll look at how Microsoft is making it easier to provision disks in Azure.

Azure Storage provides scalable, durable, and highly available storage, and to facilitate this, there are two types of storage account that can be used to provision blob, table, queue, file storage, and virtual machine (VM) hard disks. Until recently, creating a virtual disk in the Azure cloud required working directly with a storage account, but Managed Disks can be created while leaving Azure to create and manage the necessary storage account.

 

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

 

In more complex scenarios, such as using Virtual Machine Scale Sets (VMSS) to create thousands of identical VMs, Managed Disks automate storage account scale management. Managed Disks now allow VMSS to scale up to one thousand VMs in a single set, 10 times more than was possible with unmanaged disks.

Managed Disks are Azure Resource Manager (ARM) resources, and as such can be managed using JSON templates. As part of this release, Snapshots and Images are also now ARM resources. For more information on working with ARM templates, see What are Microsoft Azure Resource Groups? and Export Azure Resource Group as a JSON Template on the Petri IT Knowledgebase. But probably the best news is that existing ARM VMs can be converted to Managed Disks with just a reboot.

For more information on creating VMs in Azure, see Create a Virtual Machine in the Azure Cloud on Petri.

Unmanaged vs. Managed Disks

Let’s have a look at how the process of using a Managed Disk for a VM differs in PowerShell. When using unmanaged disks, you first need to create a storage account, using the New-AzureRmStorageAccount cmdlet, and a URI for the OS disk:

New-AzureRmStorageAccount -Name $storaccName -ResourceGroupName $rgName –Type 'Standard_LRS' -Location $location

$storacct = Get-AzureRmStorageAccount -ResourceGroupName $rgName –StorageAccountName $storaccName 
$disknameOS = $vmname + 'diskOS' 
$vhduri = $storacct.PrimaryEndpoints.Blob.ToString() + "vhds/${disknameOS}.vhd"

And finally, set the OS disk for the new VM using Set-AzureRmVMOSDisk:
Set-AzureRmVMOSDisk -VM $newVM -Name $disknameOS -VhdUri $vhduri -Caching ReadWrite -CreateOption fromImage

Managed Disks

But using Managed Disks, we can skip the process of creating a storage account and defining a URI for the disk. All we need to do is specify the disk name, storage account type, and a few other parameters:

$myVM = Set-AzureRmVMOSDisk -VM $myVM -Name 'myOsDisk1' -StorageAccountType PremiumLRS -DiskSizeInGB 128 -CreateOption FromImage -Caching ReadWrite

The VM can then be provisioned using the New-AzureRmVM cmdlet. For a complete guide to deploying ARM VMs using PowerShell, see Deploy VMs Using Azure Resource Manager and PowerShell on Petri.

Convert a VM to Managed Disks

Existing ARM VMs in your Azure subscription can be converted to Managed Disks using the ConvertTo-AzureRmVMManagedDisk cmdlet. First, stop the VM you want to convert using the code below, replacing myResourceGroup and myVM with a resource group and VM name as appropriate:

$rgName = 'myResourceGroup' $vmName = 'myVM' Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName -Force

Once the status of the VM has changed to Stopped (Deallocated), use ConvertTo-AzureRmVMManagedDisk to convert all disks associated with the VM to Managed Disks:
ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $rgName -VMName $vmName

In this article, I explained how Azure Managed Disks differ from unmanaged disks and how to convert existing ARM VMs to Managed Disks.

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

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.

RSVP Now

Sponsored By