Lab 02 – Virtual Machines

Objectives

Prerequisites

Estimated time

50 minutes

---

Part 1 – Resource group and networking

  1. Search for Resource groups > Create. Name: rg-az104-lab08,

region: East US. Review + create > Create.

  1. Search for Virtual networks > Create. Resource group:

rg-az104-lab08, Name: vnet-lab08, Address space: 10.30.0.0/16.

Subnets tab: create subnet subnet-vms with address range 10.30.1.0/24.

Review + create > Create.

Part 2 – Deploy a Linux VM

important

Save your private SSH key in a secure location — you cannot download it again after VM creation. Without it, you'll lose access to the VM.

  1. Search for Virtual machines > Create > Azure virtual machine.
  2. Basics tab:

- Resource group: rg-az104-lab08

- VM name: vm-linux01

- Region: East US

- Image: search Ubuntu > select Ubuntu Server 22.04 LTS

- VM architecture: x64

- Size: StandardB1s

- Authentication type: SSH public key

- Username: azureuser

- SSH public key source: Generate new key pair (save the private key

when prompted)

  1. Networking tab: Virtual network: vnet-lab08, Subnet:

subnet-vms, Public IP: create new (e.g., pip-vm-linux01),

Public inbound ports: allow SSH (22).

  1. Disks tab: leave defaults (OS disk type Standard).
  2. Management tab: review Monitoring options (optional).
  3. Review + create > Create. When finished, Download private key

and create resource (or just Create if you want to generate the key

pair separately).

Connect via SSH

  1. Go to vm-linux01 > Overview > copy its Public IP address.
  2. Open a terminal/SSH client and run:

``

ssh -i azureuser@

`

Part 3 – Deploy a Windows VM

  1. Virtual machines > Create > Azure virtual machine.
  2. Basics tab:

- Resource group: rg-az104-lab08

- VM name: vm-win01

- Region: East US

- Image: search Windows Server > select Windows Server 2022 Datacenter

- VM architecture: x64

- Size: StandardB2s (more resources for Windows desktop experience)

- Authentication type: Password

- Username: azureuser

- Password: set a strong password (meet Azure requirements)

- Confirm password

  1. Networking tab: Virtual network: vnet-lab08, Subnet:

subnet-vms, Public IP: create new, Public inbound ports:

allow RDP (3389).

  1. Disks and Management tabs: leave defaults.
  2. Review + create > Create.

Connect via RDP

  1. Go to vm-win01 > Overview > click Connect (top menu) > RDP.
  2. Select Download RDP file > open the .rdp file > enter username

(azureuser) and the password you set > Connect.

Part 4 – Add a data disk

  1. Go to vm-linux01 > Disks > Create and attach a new disk (top

toolbar).

  1. Disk name: disk-data01. Size: 32 GiB. Storage type: Standard

HDD. Attach (or Create > then Attach).

  1. On the Linux VM (via SSH), partition and mount the new disk:
⚠️

warning

These commands will erase the disk. Verify /dev/sdc is the new data disk, not the OS disk. Running these commands on the wrong disk will destroy your VM.

`bash

# List disks (the new one is likely /dev/sdc)

sudo lsblk

# Partition, format, and mount (example):

sudo parted /dev/sdc --script mklabel gpt mkpart xfspart xfs 0% 100%

sudo mkfs.xfs /dev/sdc1

sudo mkdir /data

sudo mount /dev/sdc1 /data

`

Part 5 – VM Extensions (Custom Script)

ℹ️

tip

Extensions run post-deployment and can fail silently. Always check the Activity log and extension status to confirm success.

  1. Go to vm-linux01 > Extensions + applications (under Settings) >

+ Add.

  1. Search for Custom Script Extension > Create.
  2. Script file tab: in the inline script box, enter:

`bash

apt-get update

apt-get install -y nginx

`

  1. Review + create > Create (installation runs asynchronously; check

Activity log for progress).

  1. Open Networking > Inbound port rules > + Add inbound port rule

> port 80 (HTTP) > Add, so nginx is reachable.

  1. In a browser, open http:// to confirm nginx serves the default

page.

Part 6 – Azure Bastion (secure RDP/SSH without public IP)

  1. Virtual networks > select vnet-lab08 > Subnets > + Subnet.

Create AzureBastionSubnet with address range 10.30.2.0/27.

  1. Virtual networks > select vnet-lab08 > Bastion (left-hand menu) >

+ Add.

  1. Bastion host name: bastion-lab08. Public IP: create new

(e.g., pip-bastion). SKU: Basic (cheapest).

  1. Create (takes ~10 minutes). Once deployed:
  2. Go to vm-win01 (or any VM without a public IP) > Connect > Bastion >

enter Username/Password > Connect (opens an RDP/SSH session in

the browser).

Cost note: Bastion is billed hourly — delete it when done (step 5 under

Cleanup) if cost is a concern.

Part 7 – Resize and power states

important

Resizing requires deallocation. If the new size isn't available in the current hardware cluster, the resize will fail. Plan for potential downtime.

  1. Go to vm-linux01 > Size (under Settings).
  2. Select a new size (e.g., Standard_B2s) > Resize.

- The VM must be deallocated to resize — the Portal handles this

automatically.

  1. Once resized, the VM starts automatically (or select Start manually

if it's still stopped).

  1. To manage power states without resizing, go to vm-linux01 >

Overview > Stop (deallocates, stops compute billing) or Start.

Understanding VM states

    1. Running: billable for compute, network, disk.
    2. Stopped (deallocated): no compute billing, but storage/IP charges remain.
    3. Deallocated is the only state that avoids hourly compute costs.

Validation

Cleanup

  1. If Bastion is deployed: Virtual networks > vnet-lab08 > Bastion >

select the Bastion host > Delete.

  1. Resource groups > select rg-az104-lab08` > Delete resource group

(type the name to confirm). This deletes all VMs, disks, VNet, and public IPs.

Exam Tips