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:

Commands

Name Description Type Status
az vm disk attach

Attach a managed persistent disk to a VM.

Core GA
az vm disk detach

Detach a managed disk from a VM.

Core GA

az vm disk attach

Attach a managed persistent disk to a VM.

This allows for the preservation of data, even if the VM is reprovisioned due to maintenance or resizing.

az vm disk attach --vm-name
                  [--caching {None, ReadOnly, ReadWrite}]
                  [--disks]
                  [--enable-write-accelerator]
                  [--ids]
                  [--lun]
                  [--name]
                  [--new]
                  [--resource-group]
                  [--size-gb]
                  [--sku {PremiumV2_LRS, Premium_LRS, Premium_ZRS, StandardSSD_LRS, StandardSSD_ZRS, 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 --name $diskId --new --resource-group MyResourceGroup --size-gb 128 --sku Standard_LRS --vm-name MyVm

Attach multiple managed disks to a VM.

az vm disk attach --vm-name MyVm --resource-group MyResourceGroup --sku Standard_LRS --disks diskId1 diskId2 diskId3

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
--disks

One or more names or IDs of the managed disk (space-delimited).

--enable-write-accelerator

Enable write accelerator.

Default value: False
--ids
Deprecated

Option '--ids' has been deprecated and will be removed in a future release. Use '--disks' instead.

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--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.

Default value: False
--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: PremiumV2_LRS, Premium_LRS, Premium_ZRS, StandardSSD_LRS, StandardSSD_ZRS, Standard_LRS, UltraSSD_LRS
--subscription

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

Global Parameters
--debug

Increase logging verbosity to show all debug logs.

--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

--output -o

Output format.

Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
Default value: json
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

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

--verbose

Increase logging verbosity. Use --debug for full debug logs.

az vm disk detach

Detach a managed disk from a VM.

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

Examples

Detach a data disk from a VM.

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

Force detach a data disk from a VM.

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

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

--force-detach

Force detach managed data disks from a VM.

Global Parameters
--debug

Increase logging verbosity to show all debug logs.

--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

--output -o

Output format.

Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
Default value: json
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

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

--verbose

Increase logging verbosity. Use --debug for full debug logs.