DevOps Peach

GCP Basics · Compute Engine – Machine Types, VMs, Disks and Managed Instance Groups · Lesson 3 of 5

Persistent Disk, Hyperdisk, Snapshots and Images

Choose a disk type for performance and cost, grow disks online, protect them with scheduled incremental snapshots, and build custom images and image families for repeatable VMs.

Practice interactively →

VM storage is network block storage: the disk lives apart from the VM, so you can detach it, resize it and snapshot it.

flowchart LR
  VM["VM db-1"] --> PD["Persistent Disk data-1<br/>pd-balanced 200 GB"]
  PD -- "schedule daily 02:00" --> SN["Snapshots<br/>incremental, multi-regional"]
  SN --> NEW["New disk in another zone"]
  BOOT["Boot disk of web-1"] --> IMG["Custom image web-v3<br/>family web"]
  IMG --> TPL["Instance template"]
  %% step VM: db-1 keeps its data on a separate Persistent Disk, not on the boot disk.
  %% step PD: pd-balanced gives SSD-backed performance at a moderate price; performance grows with size.
  %% step SN: A snapshot schedule takes incremental snapshots and deletes old ones after the retention period.
  %% step NEW: Any snapshot can become a new disk in any zone or region, for restore or migration.
  %% step BOOT: A configured boot disk becomes a custom image, grouped in the image family web.
  %% step TPL: Instance templates reference the family, so new VMs start from the latest image.

Disk types

Type Backed by Use
pd-standard HDD Cheap, sequential, backups
pd-balanced SSD Default for most VMs
pd-ssd SSD Databases needing more IOPS
pd-extreme SSD Very high IOPS (older option)
Hyperdisk (Balanced, Throughput, Extreme, ML) Next-generation Provision IOPS and throughput independently of size; required by newer machine series such as C4 and N4
Local SSD Physically attached Fastest, but data is lost when the VM stops or is deleted

Snapshots

Images and machine images

Use
Custom image One boot disk you configured; share across projects; group in an image family; deprecate old ones
Machine image A whole VM: all disks, metadata, machine type; good for cloning or backup of a VM
gcloud compute resource-policies create snapshot-schedule daily-2am --region=asia-southeast1   --daily-schedule --start-time=19:00 --max-retention-days=14
gcloud compute disks add-resource-policies data-1 --resource-policies=daily-2am --zone=asia-southeast1-a
gcloud compute images create web-v3 --source-disk=web-1 --source-disk-zone=asia-southeast1-a --family=web

(--start-time is UTC: 19:00 UTC is 02:00 in Vietnam.)

Command Meaning
gcloud compute disks resize data-1 --size=400GB --zone=… Grow a disk
gcloud compute disks snapshot data-1 --snapshot-names=data-1-manual --zone=… One-off snapshot
gcloud compute images deprecate web-v2 --state=DEPRECATED --replacement=web-v3 Retire an old image

Traps: Local SSD is not durable; resizing the disk does not resize the file system; creating an image from a running boot disk needs --force and may be inconsistent.

Practice interactively →