az vm disk

Manage the managed data disks attached to a VM.

Just like any other computer, virtual machines in Azure 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. Operating System Disk Every virtual machine has one attached operating system disk. It's registered as a SATA drive and is labeled /dev/sda by default. This disk has a maximum capacity of 1023 gigabytes (GB). Temporary disk The temporary disk is automatically created for you. On Linux virtual machines, the disk is typically /dev/sdb and is formatted and mounted to /mnt/resource by the Azure Linux Agent. The size of the temporary disk varies, based on the size of the virtual machine. Data disk A data disk is a VHD that's attached to a virtual machine to store application data, or other data you need to keep. Data disks are registered as SCSI drives and are labeled by the creator. Each data disk has a maximum capacity of 1023 GB. The size of the virtual machine determines how many data disks can be attached and the type of storage that can be used to host the disks.

Commands

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

az vm disk attach

Attach a managed persistent disk to a VM.

az vm disk attach --disk
--resource-group
--vm-name
[--caching {None, ReadOnly, ReadWrite}]
[--lun]
[--new]
[--size-gb]
[--sku {Premium_LRS, Standard_LRS}]

Examples

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

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

Required Parameters

--disk
Disk name or id.
--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

--caching
Disk caching policy.
accepted values: None, ReadOnly, ReadWrite
--lun
0-based logical unit number (LUN). Max value depends on the Virtual Machine size.
--new
Create a new disk.
--size-gb -z
Size in GB.
--sku
Underlying storage sku.
accepted values: Premium_LRS, Standard_LRS

az vm disk detach

Detatch a managed disk from a VM.

az vm disk detach --name
--resource-group
--vm-name

Examples

Detach a data disk from a VM.

az vm disk detach -g MyResourceGroup --vm-name MyVm -n 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>`.