Skip to main content

Lab 005: Expanding and Managing Disk Storage



Requirements

  1. Expand the existing VM datacenter-vm disk from 32Gi to 64Gi.

  2. Also create a new standard HDD data disk named datacenter-disk of 64Gi and mount the disk to VM datacenter-vm at location /mnt/datacenter-disk.


Note

The solution can be implemented using both the Azure Cloud Console and the Azure CLI. This document outlines the CLI-based approach to accomplish these tasks. It is recommended to first explore the Azure Cloud Console for hands-on experience and a practical understanding of the process before utilizing the CLI approach, unless specifically instructed otherwise.

Prerequisites

  • Azure CLI is authenticated.
  • A resource group containing kml exists.
  • SSH access to datacenter-vm is available.

Steps

RESOURCE_GROUP=$(az group list --query "[?contains(name, 'kml')].name | [0]" --output tsv)
VM_NAME="datacenter-vm"
DISK_NEW_SIZE=64
NEW_DISK_NAME="datacenter-disk"
MOUNTPOINT="/mnt/datacenter-disk"

OS_DISK_NAME=$(az vm show \
--resource-group "$RESOURCE_GROUP" \
--name "$VM_NAME" \
--query "storageProfile.osDisk.name" \
--output tsv)

VM_PUBLIC_IP=$(az vm list-ip-addresses --resource-group "$RESOURCE_GROUP" --name "$VM_NAME" --query "[].virtualMachine.network.publicIpAddresses[0].ipAddress" --output tsv)

# Stop VM before resizing OS disk
az vm stop --resource-group "$RESOURCE_GROUP" --name "$VM_NAME"

# Resize OS disk
az disk update \
--resource-group "$RESOURCE_GROUP" \
--name "$OS_DISK_NAME" \
--size-gb "$DISK_NEW_SIZE"

# Start VM after resize
az vm start --resource-group "$RESOURCE_GROUP" --name "$VM_NAME"

# Create and attach new 64GiB data disk
az disk create \
--resource-group "$RESOURCE_GROUP" \
--name "$NEW_DISK_NAME" \
--size-gb 64 \
--sku Standard_LRS

az vm disk attach \
--resource-group "$RESOURCE_GROUP" \
--vm-name "$VM_NAME" \
--name "$NEW_DISK_NAME"

echo "Connect to VM: ssh azureuser@$VM_PUBLIC_IP"

Run the following inside the VM after SSH login:

lsblk
sudo mkfs.ext4 /dev/sdc
sudo mkdir -p /mnt/datacenter-disk
sudo mount /dev/sdc /mnt/datacenter-disk

UUID=$(sudo blkid -s UUID -o value /dev/sdc)
echo "UUID=$UUID /mnt/datacenter-disk ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab

sudo mount -a
df -h

Verification

  • Confirm OS disk size for datacenter-vm is 64 GiB in Azure.
  • Confirm datacenter-disk is attached to the VM.
  • Confirm /mnt/datacenter-disk is mounted and persists after reboot.

Resources

Azure CLI Docs