OnCallReadyStart learning

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

Virtual machines: images, sizes, quotas and the first boot

In plain words

A virtual machine is a computer you rent by the minute in someone else's datacenter. You choose what is installed on it (the image, like Ubuntu 24.04), how big it is (the size, like Standard_B2s: 2 CPUs, 4 GB of memory), where it lives (the region and maybe a zone) and how you log in (an SSH key).

Azure checks two things before it gives you one: is that size available there, and do you still have enough CPU allowance (quota) left?

Virtual machines: images, sizes, quotas and the first boot

Most of what this course runs on Azure is managed: AKS nodes, App Service, Container Apps. Under all of them are virtual machines, and every platform team still owns a few directly - a jump host, a build agent, a legacy service nobody has containerised, a database vendor that only supports VMs. An administrator is expected to create one correctly the first time: the right image, a size that exists in the region and fits the quota, keys instead of passwords, and no SSH port open to the whole internet by accident.

Need to know: a VM needs an image (publisher:offer:sku:version, or an alias like Ubuntu2404), a size (Standard_D2s_v5: family D, 2 vCPUs, s = premium storage capable, version 5), a region and optionally an availability zone. A size can be unavailable in a region or zone (az vm list-skus shows the restrictions), and every subscription has vCPU quotas per region and per family (az vm list-usage). az vm create is a deployment that also makes a VNet, an NSG, a public IP, a NIC and an OS disk if you do not give it existing ones. Stopped VMs still cost compute; deallocated ones do not. Resizing to a size the current hardware cluster does not offer needs the VM deallocated first.

Images

$ az vm image list --query "[].{alias:urnAlias, urn:urn}" -o table
Alias                    Urn
-----------------------  ------------------------------------------------------------------------------
CentOS85Gen2             OpenLogic:CentOS:8_5-gen2:latest
Debian11                 Debian:debian-11:11-backports-gen2:latest
Debian12                 Debian:debian-12:12-gen2:latest
FlatcarLinuxFreeGen2     kinvolk:flatcar-container-linux-free:stable-gen2:latest
OpenSuseLeap154Gen2      SUSE:openSUSE-leap-15-4:gen2:latest
RHELRaw8LVMGen2          RedHat:RHEL:8-lvm-gen2:latest
SuseSles15SP5            SUSE:sles-15-sp5:gen2:latest
Ubuntu2204               Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest
Ubuntu2404               Canonical:ubuntu-24_04-lts:server:latest
Ubuntu2404Pro            Canonical:ubuntu-24_04-lts:ubuntu-pro:latest
Win2022Datacenter        MicrosoftWindowsServer:WindowsServer:2022-datacenter-g2:latest
Win2022AzureEditionCore  MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition-core:latest
Win2019Datacenter        MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest
Win2016Datacenter        MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest
Win2012R2Datacenter      MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest

az vm image list shows the popular images with their URN - publisher:offer:sku:version - and the short alias the CLI accepts instead (--image Ubuntu2404). latest as the version means "the newest published"; pin a version for builds that must be reproducible. Two details the exam likes:

  • Generation 2 images (-gen2, Hyper-V Gen2, UEFI boot) are the default for new sizes; some older sizes only run Gen1 images, and Trusted Launch (secure boot, vTPM) needs Gen2.
  • Marketplace images from third parties can carry a plan that must be accepted once per subscription (az vm image terms accept) before the first deployment, or it fails with MarketplacePurchaseEligibilityFailed.

Sizes: what the name says

partexamplemeaning
familyDgeneral purpose (D), burstable (B), memory (E), compute (F), storage (L), GPU (N), very large memory (M)
vCPUsD2number of vCPUs
featuresD2ss premium SSD capable, d local temp disk, a AMD, p Arm (Ampere), m more memory
versionv5hardware generation

B sizes are burstable: they bank CPU credits when idle and spend them when busy. Perfect for a jump host, a disaster for a build agent that runs flat out (it drops to its baseline, 20-40% of a vCPU, once the credits are gone). For anything that matters you choose by memory per vCPU and whether it needs premium disks:

$ az vm list-sizes -l westeurope --query "[?starts_with(name,'Standard_D2') || starts_with(name,'Standard_E2') || starts_with(name,'Standard_B2')].{size:name, vcpu:numberOfCores, memMB:memoryInMB, disks:maxDataDiskCount}" -o table
Size              Vcpu  MemMB  Disks
----------------  ----  -----  -----
Standard_B2s      2     4096   4
Standard_B2ms     2     8192   4
Standard_D2s_v5   2     8192   4
Standard_D2ds_v5  2     8192   4
Standard_D2as_v5  2     8192   4
Standard_E2s_v5   2     16384  4

Is it available, and may I have it?

A size can exist in a region and still be refused, for two different reasons.

SKU restrictions - capacity or policy keeps a size out of a region or zone for your subscription:

$ az vm list-skus -l westeurope --size Standard_D -o table
ResourceType     Locations   Name              Zones  Restrictions
---------------  ----------  ----------------  -----  ------------------------------------------------------------------------------
virtualMachines  westeurope  Standard_DS1_v2   1,2,3  None
virtualMachines  westeurope  Standard_DS2_v2   1,2,3  None
virtualMachines  westeurope  Standard_D2s_v5   1,2    ['NotAvailableForSubscription, type: Zone, locations: westeurope, zones: 3']
virtualMachines  westeurope  Standard_D4s_v5   1,2,3  None
virtualMachines  westeurope  Standard_D8s_v5   1      ['NotAvailableForSubscription, type: Zone, locations: westeurope, zones: 2,3']
virtualMachines  westeurope  Standard_D2ds_v5  1,2,3  None
virtualMachines  westeurope  Standard_D4ds_v5  1,2,3  None
virtualMachines  westeurope  Standard_D2as_v5  1,2,3  None
virtualMachines  westeurope  Standard_D4as_v5  1,2,3  None

Standard_D8s_v5 is offered in zone 1 only here; Standard_D2s_v5 not in zone 3. Ask for it there and the deployment fails with SkuNotAvailable. The fix is another zone, another size of the same family, or another region - not a support ticket, unless the business really needs that exact size there.

Quotas - each subscription has a limit of vCPUs per region, and per VM family in the region:

$ az vm list-usage -l westeurope -o table
Name                             CurrentValue  Limit
-------------------------------  ------------  -----
Availability Sets                0             2500
Total Regional vCPUs             3             20
Virtual Machines                 2             25000
Virtual Machine Scale Sets       0             2500
Standard BS Family vCPUs         3             10
Standard DSv2 Family vCPUs       0             4
Standard DSv5 Family vCPUs       0             10
Standard DDSv5 Family vCPUs      0             10
Standard DASv5 Family vCPUs      0             10
Standard ESv5 Family vCPUs       0             0
Standard FSv2 Family vCPUs       0             4
Standard NCASv3_T4 Family vCPUs  0             0

Two limits apply at once: Total Regional vCPUs and the family's. Here the E family (memory optimised) has a limit of 0 - nobody asked for it yet. A VM that would exceed either limit fails with OperationNotAllowed ... exceeding approved standardESv5Family Cores quota, and the error contains the exact numbers and a link to request more. Quota requests for most families are approved automatically within minutes; GPU families usually need a business case.

Creating a VM

$ az vm create -g rg-az5-vm -n vm-tools --image Ubuntu2404 --size Standard_D2s_v5 --zone 1 --admin-username azureuser --generate-ssh-keys
{
  "fqdns": "",
  "id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-vm/providers/Microsoft.Compute/virtualMachines/vm-tools",
  "location": "westeurope",
  "macAddress": "00-0D-3A-F0-A4-2B",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "20.117.5.113",
  "resourceGroup": "rg-az5-vm",
  "zones": "1"
}

One command, and look at what it actually made:

$ az resource list -g rg-az5-vm --query "[].{kind:type, name:name}" -o table
Kind                                     Name
---------------------------------------  --------------------------------------------------
Microsoft.Network/virtualNetworks        vm-toolsVNET
Microsoft.Network/networkSecurityGroups  vm-toolsNSG
Microsoft.Network/publicIPAddresses      vm-toolsPublicIP
Microsoft.Network/networkInterfaces      vm-toolsVMNic
Microsoft.Compute/virtualMachines        vm-tools
Microsoft.Compute/disks                  vm-tools_OsDisk_1_367a73756ec243108116b7c2c982de47

A VNet with a subnet, an NSG, a public IP, a NIC, the VM and its OS disk - six resources, all named after the VM. That is convenient in a lab and wrong for production, where the VM goes into an existing subnet (--vnet-name/--subnet, or --subnet <id> in another group), with no public IP (--public-ip-address "") and no per-NIC NSG (--nsg "") because the subnet already has one. The NSG az vm create makes for a Linux image allows SSH from any source - the default every security scanner flags.

Authentication: --generate-ssh-keys uses ~/.ssh/id_rsa.pub (creating the pair if it does not exist), --ssh-key-values takes a public key you have, and --admin-password turns on password login (Windows always needs one). The admin user cannot be root, admin or administrator.

$ az vm show -g rg-az5-vm -n vm-tools --query "{size:hardwareProfile.vmSize, zone:zones[0], osDisk:storageProfile.osDisk.managedDisk.storageAccountType, sizeGb:storageProfile.osDisk.diskSizeGb, user:osProfile.adminUsername}" -o json
{
  "osDisk": "Premium_LRS",
  "size": "Standard_D2s_v5",
  "sizeGb": 30,
  "user": "azureuser",
  "zone": "1"
}
$ ssh -o StrictHostKeyChecking=accept-new azureuser@$(az vm show -d -g rg-az5-vm -n vm-tools --query publicIps -o tsv) 'hostname; nproc; free -h | head -2'
Warning: Permanently added '20.117.5.113' (ED25519) to the list of known hosts.
vm-tools
2
              total       used       free     shared buff/cache  available
Mem:          7.4Gi      373Mi      6.5Gi      4.1Mi      598Mi      7.0Gi

az vm show -d adds the details that live outside the VM resource: power state, public and private IPs, FQDN.

Power states and what you pay

$ az vm stop -g rg-az5-vm -n vm-tools
Virtual machine is being stopped (powered off). You continue to be charged for the compute resources it reserves: use `az vm deallocate` to stop paying for them.
$ az vm list -d -g rg-az5-vm --query "[].{name:name, power:powerState}" -o table
Name      Power
--------  ----------
vm-tools  VM stopped
$ az vm deallocate -g rg-az5-vm -n vm-tools
$ az vm list -d -g rg-az5-vm --query "[].{name:name, power:powerState}" -o table
Name      Power
--------  --------------
vm-tools  VM deallocated

az vm stop powers the OS off but keeps the hardware reserved: you keep paying for compute, and the CLI says so. az vm deallocate releases the hardware: compute billing stops, disks and a static public IP are still billed, the temporary disk is wiped, and a dynamic public IP would be given back. Shutting a VM down from inside the OS (sudo poweroff) leaves it stopped, not deallocated

  • the classic surprise on the bill. Auto-shutdown schedules deallocate.

Resizing

Sizes run on hardware clusters, and a running VM can only move to a size its current cluster offers:

$ az vm start -g rg-az5-vm -n vm-tools
$ az vm list-vm-resize-options -g rg-az5-vm -n vm-tools --query "[].name" -o tsv
Standard_D2s_v5
Standard_D4s_v5
Standard_D8s_v5
$ az vm resize -g rg-az5-vm -n vm-tools --size Standard_D4s_v5 --query hardwareProfile.vmSize -o tsv
Standard_D4s_v5

A resize reboots the VM, even when it stays on the same cluster - plan it in a maintenance window. A size the cluster does not offer is refused while the VM runs (... is not available in the current hardware cluster); deallocate first and every size in the region becomes possible, then start it. Quotas apply to resizes too:

$ az vm resize -g rg-az5-vm -n vm-tools --size Standard_E4s_v5
ERROR: (OperationNotAllowed) Unable to resize the VM 'vm-tools' because the requested size Standard_E4s_v5 is not available in the current hardware cluster. The available sizes in this cluster are: Standard_D2s_v5,Standard_D4s_v5,Standard_D8s_v5. Read more on VM resizing strategy at https://aka.ms/azure-resizevm.
Code: OperationNotAllowed
Message: Unable to resize the VM 'vm-tools' because the requested size Standard_E4s_v5 is not available in the current hardware cluster. The available sizes in this cluster are: Standard_D2s_v5,Standard_D4s_v5,Standard_D8s_v5. Read more on VM resizing strategy at https://aka.ms/azure-resizevm.

Things a resize cannot do: move between a size with a local temp disk and one without (D2ds <-> D2s) on older generations, move a Gen1 image to a Gen2-only size, or keep the temporary disk's data. Anything on /mnt (Linux) or D: (Windows) is gone after a deallocation or a resize.

Getting in when SSH does not work

$ az vm run-command invoke -g rg-az5-vm -n vm-tools --command-id RunShellScript --scripts "id -un; uptime" --query "value[0].message" -o tsv
Enable succeeded:
[stdout]
root
 20:00:32 up 0 min,  1 user,  load average: 0.08, 0.08, 0.04

[stderr]

Run Command sends a script through the VM agent, runs it as root and returns its output. It needs no open port and no SSH key - which makes it the way in when the NSG, the SSH daemon or the key is broken, and also why Microsoft.Compute/virtualMachines/runCommand/action is a permission to hand out carefully (it is in Virtual Machine Contributor). It takes up to 90 minutes per script and one script at a time per VM. The other ways in: Bastion (the networking part of this chapter), the serial console (needs boot diagnostics; a login prompt even without a network), and the VM access extension to reset a key or a password.

On the exam (AZ-104 3.2.1, 3.2.4): create a VM with the CLI or PowerShell (New-AzVM), pick a size from requirements (memory per vCPU, premium disks, GPU), and know that resizing outside the current cluster requires deallocation, that a resize restarts the VM, and that SkuNotAvailable and quota errors are fixed by another size/zone/region or a quota increase.

In an interview: "A VM deployment fails with SkuNotAvailable. What do you do?" - "Check az vm list-skus for that size in the region and zone: it shows the restriction. Pick another zone, a similar size, or another region. If it is a quota error instead, az vm list-usage shows the family and regional limits and I request an increase."

Why it helps

VMs are still where most legacy and many platform workloads run, and the failures are always the same few: a size not offered in that region or zone, a vCPU quota used up, a resize that needs the VM stopped, a stopped VM that still bills because it was not deallocated.

Reading a size name, checking list-skus and list-usage, and knowing which power state costs money are exam questions and everyday questions.

Commands in this lesson

az ssh

FAQ

How do I read a VM size name like Standard_D4ads_v5?

Family D (general purpose), 4 vCPUs, then the letters: a = AMD processor, d = local temp disk, s = premium storage capable, then the version v5. B is burstable (credits), E memory-optimised, F compute-optimised, L storage-optimised, N GPU. The lesson's table lists the common ones.

Stopped vs deallocated?

Stopping from inside the OS (or az vm stop) leaves the VM "Stopped" - the host keeps the hardware for it and you keep paying for compute. az vm deallocate releases the hardware: compute billing stops, disks still bill, and a dynamic public IP may change. Always deallocate a VM you are not using.

Why does a resize sometimes need the VM deallocated?

A running VM can only be resized to sizes available on its current hardware cluster. az vm list-vm-resize-options shows those. If the size you want is not in that list, deallocate first; Azure can then place the VM on a cluster that has it. The VM restarts either way.

What is the difference between SkuNotAvailable and a quota error?

SkuNotAvailable: the size is not offered or is restricted for your subscription in that region or zone - az vm list-skus shows the restriction. Quota (OperationNotAllowed with a quota message): the size exists, but your vCPU limit for the family or region is used up - az vm list-usage shows it, and you request an increase.

How do I get in when SSH does not work?

The serial console (needs boot diagnostics) shows the boot messages and gives a login without the network. az vm run-command invoke runs a script through the VM agent. az vm user update resets an SSH key or password, and az vm repair builds a repair VM for a disk that will not boot.

In an interview Mid

A VM deployment fails with SkuNotAvailable. What do you do?

Check az vm list-skus for that size in the region and zone: the Restrictions column shows whether it is restricted per zone or for the whole region. Pick another zone, a similar size, or another region. If it is a quota error instead, az vm list-usage shows the family and regional vCPU limits, and I request an increase or free cores elsewhere.

Also asked: What does the s in a VM size name such as D2s_v5 mean? · Why do you still pay for a stopped VM? · How would you resize a VM to a size that is not in its resize options?

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