Azure- Why is my OS disk bigger than I asked for?

When spinning up a VM from a marketplace image using the Azure Portal you don’t get a choice of OS disk size, and if you specify a size in an API call it’s ignored. For example when deploying Ubuntu images a 32GB default OS disk is always created.

This is because the size is defined in that marketplace template. We can use the Azure CLI to pull out this information.

az vm image list
returns a list of Marketplace Images. Then:

az vm image show --urn "Canonical:UbuntuServer:18.04-LTS:latest"
Returns
{
 "automaticOsUpgradeProperties": {
    "automaticOsUpgradeSupported": true
 },
 "dataDiskImages": [],
 "hyperVgeneration": "V1",
 "id": "/Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/Providers/Microsoft.Compute/Locations/westus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/18.04-LTS/Versions/18.04.201911130",
 "location": "westus",
 "name": "18.04.201911130",
 "osDiskImage": {
     "operatingSystem": "Linux",
     "sizeInBytes": 32213303808,
     "sizeInGb": 31
  },
 "plan": null,
 "tags": null
}

The “sizeInGb” entry shows us that a 31 GB OS disk is part of the template provided by Canonical. Other templates are similar, CentOS is 1GB smaller at 30GB and RHEL is 64GB.

If a smaller OS disk is required then a custom template can be used in place of the Marketplace one, but there’s a certain level of maintenance required to keep that up to date.