Create and Configure Azure Virtual Machines: Sizes, Images, Disks, Networking, Extensions and Connecting Securely
VM Building Blocks
| Part | Notes |
|---|---|
| Image | OS template from Marketplace or your own |
| Size | vCPU, memory, disk and network limits |
| OS disk and data disks | Managed disks |
| Network interface (NIC) | Connects to a subnet, may have a public IP |
| Network security group | Firewall rules |
| Availability option | None, zone, availability set or scale set |
Choosing a Size
| Series | Use |
|---|---|
| B | Burstable, low average CPU, dev/test |
| D | General purpose |
| E | Memory optimized, databases |
| F | Compute optimized |
| N | GPU |
| L | Storage optimized |
Size names change by generation. Use az vm list-sizes -l centralindia -o table for the current list.
Create a Linux VM
bash
az group create -n rg-vm -l centralindia
az vm create -g rg-vm -n web01 --image Ubuntu2204 --size Standard_B2s \
--admin-username azureuser --generate-ssh-keys --public-ip-sku Standard \
--vnet-name vnet-vm --subnet default --nsg-rule SSH --zone 1
az vm list -d -g rg-vm -o table
Create a Windows VM
powershell
$cred = Get-Credential
New-AzVM -ResourceGroupName rg-vm -Name win01 -Location centralindia -Image Win2022Datacenter -Size Standard_B2s `
-Credential $cred -VirtualNetworkName vnet-vm -SubnetName default -PublicIpAddressName pip-win01 -OpenPorts 3389
Open ports Do not leave RDP (3389) or SSH (22) open to the whole internet. Use Azure Bastion, just-in-time access or a VPN.
Disks
| Disk | Use |
|---|---|
| Standard HDD | Backup and rarely used data |
| Standard SSD | Light production and dev/test |
| Premium SSD / SSD v2 | Production databases and apps |
| Ultra Disk | Very high IOPS and low latency |
bash
az vm disk attach -g rg-vm --vm-name web01 --name data01 --new --size-gb 128 --sku Premium_LRS
# inside the VM: partition, format and mount the new disk (lsblk, fdisk, mkfs, mount) or use Disk Management on Windows
- Host caching: ReadOnly for data disks that are mostly read, None for write-heavy log disks
- You can expand a disk (VM must be deallocated for some cases) but not shrink it
Extensions
bash
az vm extension set -g rg-vm --vm-name web01 --publisher Microsoft.Azure.Extensions --name CustomScript \
--settings '{"commandToExecute":"sudo apt-get update && sudo apt-get install -y nginx"}'
- Extensions install agents or run scripts after deployment (Custom Script, Azure Monitor Agent, Desired State, Disk Encryption)
- cloud-init (Linux) and custom data run at first boot
Power States and Billing
| State | Compute billed? |
|---|---|
| Running | Yes |
| Stopped (inside OS) | Yes, resources still allocated |
| Stopped (deallocated) | No. Disks and static IPs still billed |
bash
az vm deallocate -g rg-vm -n web01
az vm start -g rg-vm -n web01
az vm resize -g rg-vm -n web01 --size Standard_D2s_v5
- Resizing may restart the VM. If the size is not available on the host, deallocate first
- Dynamic public IPs change after deallocation. Use static if needed
Connecting
- Bastion: browser-based RDP/SSH over TLS, no public IP needed
- JIT access opens ports for a short time (Defender for Cloud)
- Serial console and Run command for troubleshooting
- Redeploy moves a VM to a new host if connection fails
Practice
- Create a Linux VM and install nginx with the Custom Script extension
- Add and mount a data disk
- Deallocate and resize the VM
- Connect through Bastion instead of a public IP
Conclusion
A VM has an image, size, disks, NIC and NSG. Create it with portal, CLI or PowerShell, use extensions for setup, deallocate to stop compute billing and connect with Bastion or JIT for safety.
Quick Summary: building blocks; sizes; Linux and Windows; disks; extensions; billing; connecting.

