Azure Docs / Azure Storage / Disks

How to Use Azure Managed Disks

Azure Managed Disks are a powerful and flexible way to manage storage for your Azure Virtual Machines. This guide will walk you through common tasks and scenarios.

1. Creating a Managed Disk

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

Using Azure CLI

To create a standard SSD managed disk:

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

Using Azure PowerShell

To create a premium SSD managed disk:

New-AzDisk -ResourceGroupName "MyResourceGroup" -DiskName "MyPremiumManagedDisk" -DiskSku Premium_LRS -CreateOption Empty -DiskSizeGB 256

2. Attaching a Managed Disk to a VM

Once a disk is created, you can attach it to an existing or new Azure Virtual Machine.

Using Azure CLI

Attach an existing managed disk to a VM:

az vm disk attach \ --resource-group MyResourceGroup \ --vm-name MyVM \ --name MyManagedDisk \ --lun 1

Using Azure Portal

  1. Navigate to your Virtual Machine in the Azure portal.
  2. Under "Settings", select "Disks".
  3. Click "Add data disk".
  4. Choose "Choose a disk" and select your managed disk from the dropdown.
  5. Configure the LUN (Logical Unit Number) if necessary.
  6. Click "Save".

3. Detaching a Managed Disk from a VM

You can detach a managed disk from a VM when it's no longer needed. Ensure the VM is stopped (deallocated) before detaching.

Using Azure CLI

az vm disk detach \ --resource-group MyResourceGroup \ --vm-name MyVM \ --name MyManagedDisk

4. Resizing a Managed Disk

You can increase the size of a managed disk. You cannot decrease the size.

Using Azure CLI

Increase disk size to 512 GB:

az disk update \ --resource-group MyResourceGroup \ --name MyManagedDisk \ --size-gb 512

Important Note

After resizing a disk, you might need to extend the partition within the operating system to utilize the new space.

5. Managing Disk Snapshots

Snapshots are point-in-time copies of a disk. They are useful for backups and data recovery.

Creating a Snapshot using Azure CLI

az snapshot create \ --resource-group MyResourceGroup \ --name MyManagedDiskSnapshot \ --source MyManagedDisk

6. Creating a Disk from a Snapshot

You can create a new managed disk using an existing snapshot.

Using Azure CLI

az disk create \ --resource-group MyResourceGroup \ --name MyNewDiskFromSnapshot \ --source MyManagedDiskSnapshot

For more advanced scenarios, such as disk encryption, disk performance tiers, and migrating existing disks, please refer to the official Azure documentation.

View Official Documentation