Tutorial - Manage Azure disks with Azure PowerShell

Azure virtual machines use disks to store the VMs operating system, applications, and data. When creating a VM, it's important to choose a disk size and configuration appropriate to the expected workload. This tutorial covers deploying and managing VM disks. You learn about:

  • OS disks and temporary disks
  • Data disks
  • Standard and Premium disks
  • Disk performance
  • Attaching and preparing data disks

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com/powershell. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press enter to run it.

Default Azure disks

When an Azure virtual machine is created, two disks are automatically attached to the virtual machine.

Operating system disk - Operating system disks can be sized up to 4 terabytes, and hosts the VMs operating system. If you create a new virtual machine (VM) from an Azure Marketplace image, the typically 127 GB (but some images have smaller OS disk sizes). The OS disk is assigned a drive letter of C: by default. The disk caching configuration of the OS disk is optimized for OS performance. The OS disk should not host applications or data. For applications and data, use a data disk, which is detailed later in this article.

Temporary disk - Temporary disks use a solid-state drive that is located on the same Azure host as the VM. Temp disks are highly performant and may be used for operations such as temporary data processing. However, if the VM is moved to a new host, any data stored on a temporary disk is removed. The size of the temporary disk is determined by the VM size. Temporary disks are assigned a drive letter of D: by default.

Azure data disks

Additional data disks can be added for installing applications and storing data. Data disks should be used in any situation where durable and responsive data storage is needed. The size of the virtual machine determines how many data disks can be attached to a VM.

VM disk types

Azure provides two types of disks.

Standard disks - backed by HDDs, and delivers cost-effective storage while still being performant. Standard disks are ideal for a cost effective dev and test workload.

Premium disks - backed by SSD-based, high-performance, low-latency disk. Perfect for VMs running production workload. VM sizes with an S in the size name, typically support Premium Storage. For example, DS-series, DSv2-series, GS-series, and FS-series VMs support premium storage. When you select a disk size, the value is rounded up to the next type. For example, if the disk size is more than 64 GB, but less than 128 GB, the disk type is P10.

Premium SSD sizesĀ  P1 P2 P3 P4 P6 P10 P15 P20 P30 P40 P50 P60 P70 P80
Disk size in GiB 4 8 16 32 64 128 256 512 1,024 2,048 4,096 8,192 16,384 32,767
Provisioned IOPS per disk 120 120 120 120 240 500 1,100 2,300 5,000 7,500 7,500 16,000 18,000 20,000
Provisioned Throughput per disk 25 MB/sec 25 MB/sec 25 MB/sec 25 MB/sec 50 MB/sec 100 MB/sec 125 MB/sec 150 MB/sec 200 MB/sec 250 MB/sec 250 MB/sec 500 MB/sec 750 MB/sec 900 MB/sec
Max burst IOPS per disk 3,500 3,500 3,500 3,500 3,500 3,500 3,500 3,500
Max burst throughput per disk 170 MB/sec 170 MB/sec 170 MB/sec 170 MB/sec 170 MB/sec 170 MB/sec 170 MB/sec 170 MB/sec
Max burst duration 30 min 30 min 30 min 30 min 30 min 30 min 30 min 30 min
Eligible for reservation No No No No No No No No Yes, up to one year Yes, up to one year Yes, up to one year Yes, up to one year Yes, up to one year Yes, up to one year

When you provision a premium storage disk, unlike standard storage, you are guaranteed the capacity, IOPS, and throughput of that disk. For example, if you create a P50 disk, Azure provisions 4,095-GB storage capacity, 7,500 IOPS, and 250-MB/s throughput for that disk. Your application can use all or part of the capacity and performance. Premium SSD disks are designed to provide low single-digit millisecond latencies and target IOPS and throughput described in the preceding table 99.9% of the time.

While the above table identifies max IOPS per disk, a higher level of performance can be achieved by striping multiple data disks. For instance, 64 data disks can be attached to Standard_GS5 VM. If each of these disks is sized as a P30, a maximum of 80,000 IOPS can be achieved. For detailed information on max IOPS per VM, see VM types and sizes.

Create and attach disks

To complete the example in this tutorial, you must have an existing virtual machine. If needed, create a virtual machine with the following commands.

Set the username and password needed for the administrator account on the virtual machine with Get-Credential:

Create the virtual machine with New-AzVM. You'll be prompted to enter a username and password for the administrators account for the VM.

New-AzVm `
    -ResourceGroupName "myResourceGroupDisk" `
    -Name "myVM" `
    -Location "East US" `
    -VirtualNetworkName "myVnet" `
    -SubnetName "mySubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "myPublicIpAddress" 

Create the initial configuration with New-AzDiskConfig. The following example configures a disk that is 128 gigabytes in size.

$diskConfig = New-AzDiskConfig `
    -Location "EastUS" `
    -CreateOption Empty `
    -DiskSizeGB 128

Create the data disk with the New-AzDisk command.

$dataDisk = New-AzDisk `
    -ResourceGroupName "myResourceGroupDisk" `
    -DiskName "myDataDisk" `
    -Disk $diskConfig

Get the virtual machine that you want to add the data disk to with the Get-AzVM command.

$vm = Get-AzVM -ResourceGroupName "myResourceGroupDisk" -Name "myVM"

Add the data disk to the virtual machine configuration with the Add-AzVMDataDisk command.

$vm = Add-AzVMDataDisk `
    -VM $vm `
    -Name "myDataDisk" `
    -CreateOption Attach `
    -ManagedDiskId $dataDisk.Id `
    -Lun 1

Update the virtual machine with the Update-AzVM command.

Update-AzVM -ResourceGroupName "myResourceGroupDisk" -VM $vm

Prepare data disks

Once a disk has been attached to the virtual machine, the operating system needs to be configured to use the disk. The following example shows how to manually configure the first disk added to the VM. This process can also be automated using the custom script extension.

Manual configuration

Create an RDP connection with the virtual machine. Open up PowerShell and run this script.

Get-Disk | Where partitionstyle -eq 'raw' |
    Initialize-Disk -PartitionStyle MBR -PassThru |
    New-Partition -AssignDriveLetter -UseMaximumSize |
    Format-Volume -FileSystem NTFS -NewFileSystemLabel "myDataDisk" -Confirm:$false

Verify the data disk

To verify that the data disk is attached, view the StorageProfile for the attached DataDisks.


The output should look something like this example:

Name            : myDataDisk
DiskSizeGB      : 128
Lun             : 1
Caching         : None
CreateOption    : Attach
SourceImage     :
VirtualHardDisk :

Next steps

In this tutorial, you learned about VM disks topics such as:

  • OS disks and temporary disks
  • Data disks
  • Standard and Premium disks
  • Disk performance
  • Attaching and preparing data disks

Advance to the next tutorial to learn about automating VM configuration.