Enable shared disks for Azure managed disks

Applies to: ✔️ Linux VMs ✔️ Windows VMs ✔️ Flexible scale sets ✔️ Uniform scale sets

This article explains how to enable the shared disks feature for Azure managed disks. With Azure shared disks, you can attach a managed disk to multiple virtual machines (VMs) simultaneously, enabling the deployment or migration of clustered applications to Azure.

If you're looking for conceptual information on managed disks that have shared disks enabled, see Azure shared disks.

Prerequisites

The scripts and commands in this article require either:

  • Version 6.0.0 or newer of the Azure PowerShell module.

Or

  • The latest version of the Azure CLI.

Limitations

General limitations

Shared disks have general limitations that apply to all shared disks, regardless of disk type. They also have more limitations that only apply to specific types of shared disks. The following list is the list of general limitations:

  • Currently, only Ultra Disks, Premium SSD v2, Premium SSD, and Standard SSDs can be used as a shared disk
  • Shared disks can be attached to individual Virtual Machine Scale Sets but can't be defined in the Virtual Machine Scale Set models or automatically deployed
  • Write accelerator isn't supported for shared disks
  • Host caching isn't supported for shared disks

Each managed disk that has shared disks enabled are also subject to the following limitations, organized by disk type:

Ultra Disks

Ultra Disks have their own separate list of limitations, unrelated to shared disks. For Ultra Disk limitations, refer to Using Azure Ultra Disks.

When sharing Ultra Disks, they have the following additional limitations:

Premium SSD v2

Premium SSD v2 managed disks have their own separate list of limitations, unrelated to shared disks. For these limitations, see Premium SSD v2 limitations.

When sharing Premium SSD v2 disks, they have the following additional limitation:

Premium SSD

Standard SSDs

Supported operating systems

Shared disks support several operating systems. For the supported operating systems, see the Windows and Linux sections of the conceptual article.

Disk sizes

For now, only Ultra Disks, Premium SSD v2, Premium SSD, and Standard SSDs can enable shared disks. Different disk sizes may have a different maxShares limit, which you can't exceed when setting the maxShares value.

For each disk, you can define a maxShares value that represents the maximum number of nodes that can simultaneously share the disk. For example, if you plan to set up a 2-node failover cluster, you would set maxShares=2. The maximum value is an upper bound. Nodes can join or leave the cluster (mount or unmount the disk) as long as the number of nodes is lower than the specified maxShares value.

Note

The maxShares value can only be set or edited when the disk is detached from all nodes.

Premium SSD ranges

The following table illustrates the allowed maximum values for maxShares by Premium SSD sizes:

Disk sizes maxShares limit
P1,P2,P3,P4,P6,P10,P15,P20 3
P30, P40, P50 5
P60, P70, P80 10

The IOPS and bandwidth limits for a disk aren't affected by the maxShares value. For example, the max IOPS of a P15 disk is 1100 whether maxShares = 1 or maxShares > 1.

Standard SSD ranges

The following table illustrates the allowed maximum values for maxShares by Standard SSD sizes:

Disk sizes maxShares limit
E1,E2,E3,E4,E6,E10,E15,E20 3
E30, E40, E50 5
E60, E70, E80 10

The IOPS and bandwidth limits for a disk aren't affected by the maxShares value. For example, the max IOPS of a E15 disk is 500 whether maxShares = 1 or maxShares > 1.

Ultra Disk ranges

The minimum maxShares value is 1, while the maximum maxShares value is 15. There are no size restrictions on Ultra Disks, any size Ultra Disk can use any value for maxShares, up to and including the maximum value.

Premium SSD v2 ranges

The minimum maxShares value is 1, while the maximum maxShares value is 15. There are no size restrictions on Premium SSD v2, any size Premium SSD v2 can use any value for maxShares, up to and including the maximum value.

Deploy a Premium SSD as a shared disk

To deploy a managed disk with the shared disk feature enabled, set the maxShares property to a value greater than 1. This setting makes the disk shareable across multiple VMs.

Important

Host caching isn't supported for shared disks.

The value of maxShares can only be set or changed when a disk is unmounted from all VMs. See the Disk sizes for the allowed values for maxShares.

  1. Sign in to the Azure portal.

  2. Search for and select Disks.

  3. Select + Create to create a new managed disk.

  4. On the Basics pane, select a Region, and then select Change size.

    Screenshot of the Create a managed disk Basics pane with Region set to China North, Availability zone set to None, and Change size highlighted.

  5. Select the Premium SSD size and SKU that you want and select OK.

    Screenshot of the Disk SKU list with Premium SSD under locally redundant storage and zone-redundant storage highlighted.

  6. Proceed through the deployment until you get to the Advanced pane.

  7. For Enable shared disk, select Yes, and then select a value for Max shares.

    Screenshot of the shared disk settings with Enable shared disk set to Yes and Max shares set to 2.

  8. Select Review + create.

Deploy a Standard SSD as a shared disk

To deploy a managed disk with the shared disk feature enabled, set the maxShares property to a value greater than 1. This setting makes the disk shareable across multiple VMs.

Important

Host caching isn't supported for shared disks.

The value of maxShares can only be set or changed when a disk is unmounted from all VMs. See the Disk sizes for the allowed values for maxShares.

  1. Sign in to the Azure portal.

  2. Search for and select Disks.

  3. Select + Create to create a new managed disk.

  4. On the Basics pane, select a Region, and then select Change size.

    Screenshot of the Create a managed disk Basics pane with Region set to China North, Availability zone set to None, and Change size highlighted.

  5. Select the Standard SSD size and SKU that you want and select OK.

    Screenshot of the Disk SKU list with Standard SSD under locally redundant storage and zone-redundant storage highlighted.

  6. Proceed through the deployment until you get to the Advanced pane.

  7. For Enable shared disk, select Yes, and then select a value for Max shares.

    Screenshot of the shared disk settings with Enable shared disk set to Yes and Max shares set to 2.

  8. Select Review + create.

Deploy an Ultra Disk as a shared disk

To deploy a managed disk with the shared disk feature enabled, change the maxShares parameter to a value greater than 1. This makes the disk shareable across multiple VMs.

Important

The value of maxShares can only be set or changed when a disk is unmounted from all VMs. See the Disk sizes for the allowed values for maxShares.

  1. Sign in to the Azure portal.

  2. Search for and select Disks.

  3. Select + Create to create a new managed disk.

  4. On the Basics pane, select Change size.

  5. Select Ultra Disk for the Disk SKU.

    Screenshot of the Disk SKU list with Ultra Disk under locally redundant storage selected.

  6. Select the disk size that you want and select OK.

  7. Proceed through the deployment until you get to the Advanced pane.

  8. For Enable shared disk, select Yes, and then select a value for Max shares.

  9. Select Review + create.

    Screenshot of the Advanced pane with Enable shared disk set to Yes, Max shares set to 2, Ultra Disk performance values, and logical sector size set to 4096 bytes.

Share an existing disk

To share an existing disk or update how many VMs can mount it, set the maxShares parameter by using either Azure PowerShell or Azure CLI. To disable sharing, set maxShares to 1.

Important

Host caching isn't supported for shared disks.

The value of maxShares can only be set or changed when a disk is unmounted from all VMs. See the Disk sizes for the allowed values for maxShares. Before detaching a disk, record the LUN ID for when you reattach it.

Azure PowerShell

The following Azure PowerShell commands update the sharing configuration of an existing disk.

$datadiskconfig = Get-AzDisk -DiskName "mySharedDisk"
$datadiskconfig.maxShares = 3

Update-AzDisk -ResourceGroupName 'myResourceGroup' -DiskName 'mySharedDisk' -Disk $datadiskconfig

Azure CLI

The following Azure CLI command updates the sharing configuration of an existing disk.

#Modifying a disk to enable or modify sharing configuration

az disk update --name mySharedDisk --max-shares 5 --resource-group myResourceGroup

Use Azure shared disks with your VMs

After you deploy a shared disk with maxShares > 1, you can mount the disk to one or more of your VMs.

Note

Host caching isn't supported for shared disks.

If you're deploying an Ultra Disk, make sure it matches the necessary requirements. See Using Azure Ultra Disks for details.

The following Azure PowerShell commands create a VM and attach the shared disk as a data disk.


$resourceGroup = "myResourceGroup"
$location = "chinanorth2"

$vm = New-AzVm -ResourceGroupName $resourceGroup -Name "myVM" -Location $location -VirtualNetworkName "myVnet" -SubnetName "mySubnet" -SecurityGroupName "myNetworkSecurityGroup" -PublicIpAddressName "myPublicIpAddress"

$dataDisk = Get-AzDisk -ResourceGroupName $resourceGroup -DiskName "mySharedDisk"

$vm = Add-AzVMDataDisk -VM $vm -Name "mySharedDisk" -CreateOption Attach -ManagedDiskId $dataDisk.Id -Lun 0

update-AzVm -VM $vm -ResourceGroupName $resourceGroup

Supported SCSI persistent reservation commands

After you mount the shared disk to your VMs in your cluster, you can establish quorum and read/write to the disk by using Small Computer System Interface (SCSI) persistent reservation (PR) commands.

The following SCSI persistent reservation commands are available when using Azure shared disks:

  • PR_REGISTER_KEY
  • PR_REGISTER_AND_IGNORE
  • PR_GET_CONFIGURATION
  • PR_RESERVE
  • PR_PREEMPT_RESERVATION
  • PR_CLEAR_RESERVATION
  • PR_RELEASE_RESERVATION

When you use PR_RESERVE, PR_PREEMPT_RESERVATION, or PR_RELEASE_RESERVATION, provide one of the following persistent reservation types:

  • PR_NONE
  • PR_WRITE_EXCLUSIVE
  • PR_EXCLUSIVE_ACCESS
  • PR_WRITE_EXCLUSIVE_REGISTRANTS_ONLY
  • PR_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY
  • PR_WRITE_EXCLUSIVE_ALL_REGISTRANTS
  • PR_EXCLUSIVE_ACCESS_ALL_REGISTRANTS

You also need to provide a persistent reservation key when you use PR_RESERVE, PR_REGISTER_AND_IGNORE, PR_REGISTER_KEY, PR_PREEMPT_RESERVATION, PR_CLEAR_RESERVATION, or PR_RELEASE_RESERVATION.

Next steps

If you have more questions, see the shared disks section of the FAQ.