Manage Azure Managed Disks

This document provides comprehensive guidance on managing Azure Managed Disks, a key component for virtual machines and other Azure services requiring persistent storage.

Overview of Managed Disks

Azure Managed Disks simplify storage management by abstracting away the underlying storage accounts. They are highly available, durable, and scalable. Key benefits include:

Disk Types

Azure offers several disk types to meet different performance and cost requirements:

Creating Managed Disks

You can create managed disks using the Azure portal, Azure CLI, PowerShell, or ARM templates.

Using Azure CLI

To create a Standard SSD managed disk:

az disk create --resource-group MyResourceGroup --name MyDisk --sku StandardSSD_LRS --size-gb 128

To create a Premium SSD managed disk with specific IOPS and throughput:

az disk create --resource-group MyResourceGroup --name MyPremiumDisk --sku Premium_LRS --size-gb 256 --set-disk-performance --disk-iops-ps 4000 --disk-throughput-mbps 120

Attaching Managed Disks to VMs

Managed disks can be attached to Azure Virtual Machines as data disks or OS disks. Ensure the VM and the disk are in the same Azure region and availability zone.

Using Azure CLI

To attach a disk to a VM:

az vm disk attach --resource-group MyResourceGroup --vm-name MyVM --name MyDisk --new --sku StandardSSD_LRS

Resizing Managed Disks

You can resize a managed disk without downtime if it's not attached to a running VM. If attached, the VM must be stopped (deallocated).

Using Azure CLI

To resize a disk:

az disk update --resource-group MyResourceGroup --name MyDisk --size-gb 256
Important: Resizing a disk to a smaller size is not supported. You must create a new, smaller disk and copy the data.

Detaching Managed Disks

Detaching a disk from a VM is a straightforward process.

Using Azure CLI

To detach a disk:

az vm disk detach --resource-group MyResourceGroup --vm-name MyVM --name MyDisk

Deleting Managed Disks

Managed disks can be deleted when they are no longer needed. Ensure they are detached from any VMs.

Using Azure CLI

To delete a disk:

az disk delete --resource-group MyResourceGroup --name MyDisk
Note: When a managed disk is deleted, all data on the disk is permanently lost.

Snapshots and Images

Managed disks support creating snapshots for backup and disaster recovery purposes. You can also create custom images from managed disks to deploy identical VMs.

Creating a Snapshot

az snapshot create --resource-group MyResourceGroup --name MyDiskSnapshot --source MyDisk

Creating an Image

az image create --resource-group MyResourceGroup --name MyCustomImage --source MyDisk

Encryption

All managed disks are encrypted at rest by default using Azure Storage Service Encryption (SSE) with platform-managed keys. You can also use customer-managed keys for enhanced control.

Performance Considerations

Choose the appropriate disk type based on your application's IOPS (Input/Output Operations Per Second) and throughput requirements. Monitor disk performance metrics in the Azure portal.

Disk Type Typical Use Cases Performance Characteristics
Ultra Disks High-performance databases, mission-critical applications High IOPS and throughput, lowest latency
Premium SSDs Production applications, I/O-intensive workloads Consistent IOPS and throughput, low latency
Standard SSDs Web servers, dev/test environments Balanced performance and cost
Standard HDDs Backup, archive, infrequent access Lowest cost, higher latency
Tip: For optimal performance and cost efficiency, match your disk type to your workload demands.