az vm disk

Manage the managed data disks attached to a VM.

Azure Virtual Machines use disks as a place to store an operating system, applications, and data. All Azure virtual machines have at least two disks: An operating system disk, and a temporary disk. The operating system disk is created from an image, and both the operating system disk and the image are actually virtual hard disks (VHDs) stored in an Azure storage account. Virtual machines also can have one or more data disks, that are also stored as VHDs.

                        Azure Managed and Unmanaged Data Disks have a maximum size of 4095 GB (with the exception of larger disks in preview). Azure Unmanaged Disks also have a maximum capacity of 4095 GB.
                        
                        For more information, see:
                        - Azure Disks - <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds">https://docs.microsoft.com/en-us/azure/virtual-machines/linux/about-disks-and-vhds</a> and <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds">https://docs.microsoft.com/en-us/azure/virtual-machines/windows/about-disks-and-vhds</a>.
                        - Larger Managed Disks in Public Preview - <a href="https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/">https://azure.microsoft.com/en-us/blog/introducing-the-public-preview-of-larger-managed-disks-sizes/</a>
                        - Ultra SSD Managed Disks in Public Preview - <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd">https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-ultra-ssd</a>.

Commands

az vm disk attach Attach a managed persistent disk to a VM.
az vm disk detach Detach a managed disk from a VM.

az vm disk attach

Attach a managed persistent disk to a VM.

az vm disk attach --vm-name
[--caching {None, ReadOnly, ReadWrite}]
[--enable-write-accelerator]
[--ids]
[--lun]
[--name]
[--new]
[--resource-group]
[--size-gb]
[--sku {Premium_LRS, StandardSSD_LRS, Standard_LRS, UltraSSD_LRS}]
[--subscription]

Examples

Attach a new default sized (1023 GB) managed data disk to a VM.

az vm disk attach -g MyResourceGroup --vm-name MyVm --name disk_name --new

Attach a managed persistent disk to a VM. (autogenerated)

az vm disk attach --disk $diskId --new --resource-group MyResourceGroup --size-gb 128 --sku Standard_LRS --vm-name MyVm

Required Parameters

--vm-name

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

Optional Parameters

--caching

Disk caching policy.

accepted values: None, ReadOnly, ReadWrite
--enable-write-accelerator

Enable write accelerator.

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--lun

0-based logical unit number (LUN). Max value depends on the Virtual Machine size.

--name -n

The name or ID of the managed disk.

--new

Create a new disk.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--size-gb -z

Size in GB. Max size: 4095 GB (certain preview disks can be larger).

default value: 1023
--sku

Underlying storage SKU.

accepted values: Premium_LRS, StandardSSD_LRS, Standard_LRS, UltraSSD_LRS
--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm disk detach

Detach a managed disk from a VM.

az vm disk detach --name
--resource-group
--vm-name
[--subscription]

Examples

Detach a data disk from a VM.

az vm disk detach -g MyResourceGroup --vm-name MyVm --name disk_name

Required Parameters

--name -n

The data disk name.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--vm-name

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.