OnCallReadyStart learning

Azure Lesson 33.9 · Azure V: Compute, App Hosting & the AZ-104 exam · 26 min read

VM disks, encryption at host, and moving a VM

In plain words

A VM's disks are separate things you can buy, swap and move. The OS disk holds the system; data disks hold your data; the temp disk is scratch space that can disappear. Bigger premium disks are also faster - you buy speed by buying size.

Everything on managed disks is already encrypted when it is stored. Encryption at host also covers the temp disk and the cache on the physical server. Moving a VM to another resource group means moving its disks and network card with it.

VM disks, encryption at host, and moving a VM

A VM is mostly its disks: the OS disk it boots from, the data disks that hold what you care about, and a temporary disk that holds nothing you should care about. Most VM incidents that are not networking are disk incidents - a disk that is full, too slow for the workload, attached in the wrong zone, or "encrypted" in a way that does not satisfy the auditor. And sooner or later someone asks you to move a VM into the platform team's resource group, which turns out to mean moving four resources, not one.

Need to know: Azure disks are managed disks, resources of their own (Microsoft.Compute/disks), with a type - Standard HDD, Standard SSD, Premium SSD, Premium SSD v2, Ultra - whose size decides its performance tier (a 64 GiB Premium SSD is a P6: 240 IOPS). A disk can only grow. A zonal VM can only use disks in its own zone. Every managed disk is encrypted at rest by default (server-side encryption with platform-managed keys); encryption at host adds the temporary disk and the caches on the host, needs the EncryptionAtHost feature registered on the subscription and the VM deallocated to turn on. az resource move moves a VM between resource groups or subscriptions in the same region, together with its NICs and disks; a region move is a redeployment.

Disk types, and what size really buys

typesku nameusenotes
Standard HDDStandard_LRSbackups, dev/testcheapest, slow, no SLA for single-instance VMs
Standard SSDStandardSSD_LRS / _ZRSweb servers, light workloadsconsistent latency, tiers E1-E80
Premium SSDPremium_LRS / _ZRSproduction, databasestiers P1-P80: IOPS grow with size
Premium SSD v2PremiumV2_LRSdatabases needing tuned IOPSsize, IOPS and throughput set separately; data disks only, zonal
Ultra DiskUltraSSD_LRStop-end databases (SAP HANA, SQL)sub-ms latency, IOPS/throughput adjustable live; data disks only

The trap with Premium SSD: you do not buy IOPS, you buy a tier, and the tier follows the size. A team that needs 1,000 IOPS and creates a 64 GiB disk gets 240. The fix is a bigger disk (P15, 256 GiB: 1,100 IOPS), Premium SSD v2, or a performance tier set above the size. _ZRS variants replicate synchronously across three zones of the region and can be attached to a VM in any zone.

$ az vm show -g rg-az5-disk -n vm-data --query "{os: storageProfile.osDisk.name, data: storageProfile.dataDisks[].name, size: hardwareProfile.vmSize}" -o json
{
  "data": [],
  "os": "vm-data_OsDisk_1_9fc118c69bc44c75b1d741d9822bb3b2",
  "size": "Standard_D2s_v5"
}
$ az disk list -g rg-az5-disk --query "[].{name:name, sku:sku.name, gb:diskSizeGb, tier:tier, iops:diskIOPSReadWrite, mbps:diskMBpsReadWrite, state:diskState}" -o table
Name                                               Sku          Gb  Tier  Iops  Mbps  State
-------------------------------------------------  -----------  --  ----  ----  ----  --------
vm-data_OsDisk_1_9fc118c69bc44c75b1d741d9822bb3b2  Premium_LRS  30  P4    120   25    Attached

Attaching a data disk

$ az vm disk attach -g rg-az5-disk --vm-name vm-data -n disk-data01 --new --size-gb 64 --sku Premium_LRS -o none
$ az vm show -g rg-az5-disk -n vm-data --query "storageProfile.dataDisks[].{name:name, lun:lun, sizeGb:diskSizeGb, caching:caching}" -o table
Name         Lun  SizeGb  Caching
-----------  ---  ------  -------
disk-data01  0    64      None
$ az disk show -g rg-az5-disk -n disk-data01 --query "{tier:tier, iops:diskIOPSReadWrite, mbps:diskMBpsReadWrite, managedBy:managedBy}" -o json
{
  "iops": 240,
  "managedBy": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Compute/virtualMachines/vm-data",
  "mbps": 50,
  "tier": "P6"
}

--new creates the disk and attaches it in one step; without it -n names an existing disk. The disk lands on the next free LUN (logical unit number, 0 here), which is how the guest tells disks apart. Each size has a maximum number of data disks (maxDataDiskCount in list-sizes: 4 for a D2s_v5). Host caching - None, ReadOnly, ReadWrite - is set per disk: ReadOnly for read-heavy data files, None for write-heavy logs (database transaction logs), ReadWrite only on the OS disk.

Azure attached a raw block device. The guest still has to use it:

$ az vm run-command invoke -g rg-az5-disk -n vm-data --command-id RunShellScript --scripts "lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS" --query "value[0].message" -o tsv
Enable succeeded:
[stdout]
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda     8:0      0   30G  0 disk
├─sda1  8:1      0   29G  0 part /
├─sda14 8:14     0    4M  0 part
├─sda15 8:15     0  106M  0 part /boot/efi
└─sda16 8:16     0  913M  0 part /boot
sdc     8:32     0   64G  0 disk

[stderr]

sda is the OS disk, sdb would be the temporary disk on a size that has one (this one has none: no d in its name), and the new disk is sdc, empty. On Linux: partition it, mkfs, mount it, and add it to /etc/fstab by UUID with nofail - device names can change between boots, and without nofail a missing disk stops the VM at boot (Azure then shows it as running while SSH never answers: the serial console shows the emergency shell).

Growing and changing a disk

$ az disk update -g rg-az5-disk -n disk-data01 --size-gb 32
ERROR: (BadRequest) Disk resizing is allowed only to a larger size. The current size of disk disk-data01 is 64 GB and the requested size is 32 GB.
Code: BadRequest
Message: Disk resizing is allowed only to a larger size. The current size of disk disk-data01 is 64 GB and the requested size is 32 GB.
$ az disk update -g rg-az5-disk -n disk-data01 --size-gb 128 --query "{gb:diskSizeGb, tier:tier, iops:diskIOPSReadWrite}" -o json
{
  "gb": 128,
  "iops": 500,
  "tier": "P10"
}
$ az disk update -g rg-az5-disk -n disk-data01 --sku StandardSSD_LRS
ERROR: (OperationNotAllowed) Cannot change the SKU of disk disk-data01 while it is attached to running VM vm-data. Deallocate the VM first, or detach the disk.
Code: OperationNotAllowed
Message: Cannot change the SKU of disk disk-data01 while it is attached to running VM vm-data. Deallocate the VM first, or detach the disk.
  • Shrinking is impossible - copy the data to a new, smaller disk.
  • Growing a data disk works while the VM runs on current sizes (older VMs and OS disks need the VM deallocated). The tier follows: 128 GiB is a P10, 500 IOPS. Then grow the partition and the file system inside the guest (growpart, resize2fs / xfs_growfs) - Azure only grew the device.
  • Changing the type (Premium <-> Standard SSD) needs the disk detached or the VM deallocated.

Encryption: what is already on, and what encryption at host adds

$ az disk show -g rg-az5-disk -n disk-data01 --query "encryption" -o json
{
  "type": "EncryptionAtRestWithPlatformKey"
}

Every managed disk is encrypted at rest by Azure Storage server-side encryption (SSE), AES-256, always on, with:

  • platform-managed keys (EncryptionAtRestWithPlatformKey, the default), or
  • customer-managed keys in Key Vault, through a disk encryption set (EncryptionAtRestWithCustomerKey) - for auditors who require you to control and rotate the key, or
  • both (double encryption, EncryptionAtRestWithPlatformAndCustomerKeys).

What SSE does not cover: the VM's temporary disk and the disk caches on the host server - data that never reaches Azure Storage. Encryption at host closes that gap: the host encrypts the temp disk and the caches, and data flows encrypted from the host to Storage (end to end). It uses the same keys as the disks, costs nothing extra and does not touch the guest OS.

Turning it on, in order:

$ az feature show --namespace Microsoft.Compute --name EncryptionAtHost --query properties.state -o tsv
NotRegistered
$ az feature register --namespace Microsoft.Compute --name EncryptionAtHost --query properties.state -o tsv
Once the feature 'EncryptionAtHost' is registered, invoking 'az provider register -n Microsoft.Compute' is required to get the change propagated
Registering

The feature is per subscription and takes a few minutes to go from Registering to Registered; after that, az provider register -n Microsoft.Compute propagates it. Until then a VM with --encryption-at-host fails with "the 'Microsoft.Compute/EncryptionAtHost' feature is not enabled for this subscription". On an existing VM the property can only change while it is deallocated:

$ az vm update -g rg-az5-disk -n vm-data --set securityProfile.encryptionAtHost=true
ERROR: (OperationNotAllowed) Changing property 'securityProfile.encryptionAtHost' is not allowed because the VM is not deallocated. Deallocate the VM vm-data and try again.
Code: OperationNotAllowed
Message: Changing property 'securityProfile.encryptionAtHost' is not allowed because the VM is not deallocated. Deallocate the VM vm-data and try again.
$ sleep 240
$ az feature show --namespace Microsoft.Compute --name EncryptionAtHost --query properties.state -o tsv
Registered
$ az provider register -n Microsoft.Compute
$ az vm deallocate -g rg-az5-disk -n vm-data
$ az vm update -g rg-az5-disk -n vm-data --set securityProfile.encryptionAtHost=true --query securityProfile.encryptionAtHost
true
$ az vm start -g rg-az5-disk -n vm-data

New VMs take az vm create ... --encryption-at-host. A policy (built-in "Virtual machines and virtual machine scale sets should have encryption at host enabled") can audit or deny the rest.

Azure Disk Encryption (ADE) is the older, guest-side option: BitLocker or dm-crypt inside the VM, keys in Key Vault. Microsoft has announced its retirement (September 2028) and recommends encryption at host instead; exam questions still name it, usually as the answer for "encrypt inside the guest OS with BitLocker".

On the exam (AZ-104 3.2.2, 3.2.5): "encrypt the temporary disk and the cache" = encryption at host; "customer-managed key for managed disks" = a disk encryption set; "enable it on an existing VM" = deallocate first. "The disk needs more IOPS" = a larger Premium SSD, Premium SSD v2 or Ultra. "Make the disk smaller" = not possible.

Moving a VM to another resource group or subscription

The platform team now owns this VM and wants it in rg-az5-platform:

$ az resource move --destination-group rg-az5-platform --ids $(az vm show -g rg-az5-disk -n vm-data --query id -o tsv)
ERROR: (MissingMoveDependentResources) The move resources request does not contain all the dependent resources. Please check error details for missing resource ids.
Details: '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Network/networkInterfaces/vm-dataVMNic', '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Compute/disks/vm-data_OsDisk_1_9fc118c69bc44c75b1d741d9822bb3b2', '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Compute/disks/disk-data01'
Code: MissingMoveDependentResources
Message: The move resources request does not contain all the dependent resources. Please check error details for missing resource ids.
Details: '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Network/networkInterfaces/vm-dataVMNic', '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Compute/disks/vm-data_OsDisk_1_9fc118c69bc44c75b1d741d9822bb3b2', '/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-disk/providers/Microsoft.Compute/disks/disk-data01'

A VM cannot move alone. ARM refuses with MissingMoveDependentResources and lists what must come with it: the NIC and the disks (OS and data). Move them in one request:

$ VM=$(az vm show -g rg-az5-disk -n vm-data --query id -o tsv); NIC=$(az vm show --ids $VM --query "networkProfile.networkInterfaces[0].id" -o tsv); OS=$(az vm show --ids $VM --query storageProfile.osDisk.managedDisk.id -o tsv); DATA=$(az vm show --ids $VM --query "storageProfile.dataDisks[].managedDisk.id" -o tsv)
$ az resource move --destination-group rg-az5-platform --ids $VM $NIC $OS $DATA
$ az resource list -g rg-az5-platform --query "[].name" -o tsv
vm-data
vm-dataVMNic
vm-data_OsDisk_1_9fc118c69bc44c75b1d741d9822bb3b2
disk-data01
$ az resource list -g rg-az5-disk --query "[].name" -o tsv
vm-dataVNET
vm-dataNSG
vm-dataPublicIP

What a move does and does not do:

  • the resources get new resource IDs (the group is part of the id): scripts, alerts, dashboards and Terraform state that use the old ids break - update them, or terraform state mv/import;
  • the VM keeps running during a move inside a subscription; both groups are locked for writes while it runs (up to hours for big moves);
  • the VNet, NSG and public IP may stay behind in the same subscription (the NIC references them across groups); a cross-subscription move needs the whole network to come along, and both subscriptions must be in the same Microsoft Entra tenant with the resource providers registered;
  • role assignments on the moved resources are not moved - re-create them; tags and locks: a ReadOnly lock on either group stops the move;
  • the region never changes. To move a VM to another region: Azure Resource Mover, Azure Site Recovery (replicate, then fail over), or redeploy from an image/snapshot and a template.

On the exam (AZ-104 3.2.3): a VM moves with its NICs and disks; "to another region" is never az resource move / Move-AzResource - it is Azure Resource Mover (or Site Recovery); the resource ID changes and RBAC on the resource does not follow; a lock or a running write on either group blocks the move.

In an interview: "How do you move a VM to another region?" - "Not with a resource move - that only changes the resource group or subscription. I'd use Azure Resource Mover, or replicate it with Site Recovery and fail over, or rebuild it from a snapshot or image with the same template. Then update DNS, monitoring and anything that used the old resource ID."

Why it helps

"Add a data disk", "make the disk faster", "encrypt the temp disk and cache" and "move this VM to another resource group" are all AZ-104 tasks, and the mistakes are predictable: a disk attached but never partitioned in the OS, a performance tier that resets, encryption at host refused because the feature is not registered, a move that fails because the disks were left out.

After the move, the resource IDs change - scripts and alerts that used them break.

Commands in this lesson

az sleep

FAQ

Which disk types are there?

Standard HDD (cheap, slow), Standard SSD, Premium SSD (performance by size tier: P10, P20, P30...), Premium SSD v2 (IOPS and throughput set separately from size) and Ultra Disk (highest performance, set separately too). Premium needs a VM size with an s in its name.

I attached a data disk but cannot see the space. Why?

Attaching only gives the VM a new block device. Inside the OS you still partition it, create a file system and mount it (and add it to /etc/fstab with the UUID and nofail so a missing disk does not stop the boot). lsblk shows the new device.

Can I make a disk bigger or faster without downtime?

Growing a disk can be done online for most disks, then you grow the partition and file system inside the OS. A Premium SSD can get a higher performance tier than its size gives without resizing. A disk can never be made smaller.

What does encryption at host need?

The EncryptionAtHost feature registered on the subscription (az feature register --namespace Microsoft.Compute --name EncryptionAtHost, then re-register the provider), a VM size that supports it, and the VM deallocated to turn it on for an existing VM. It covers the temp disk and disk caches.

Does a move keep the VM running?

Inside a subscription the VM keeps running while it moves, but both resource groups are locked for writes until the move finishes. The resources get new IDs, role assignments on them do not move, and a ReadOnly lock on either group blocks the move.

In an interview Mid

How do you move a VM to another region?

Not with a resource move - az resource move only changes the resource group or subscription, never the region. I would use Azure Resource Mover, or replicate it with Site Recovery and fail over, or rebuild it from a snapshot or image with the same template. Then update DNS, monitoring and anything that used the old resource ID.

Also asked: What is the difference between encryption at host and server-side encryption? · Why would you choose Premium SSD v2 over Premium SSD? · What has to move together with a VM in a resource move?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.