When deploying compute workloads in Google Cloud, you generally choose between Persistent Disks (PDs) and Local SSDs.
- Persistent Disks: Durable, network-attached, can be resized, backed up with snapshots, and survive VM reboots.
- Local SSDs: Physically attached to the host, extremely fast (high IOPS & throughput), but ephemeral – data does not persist if the VM is deleted (unless explicitly preserved during stop).
In this tutorial, we’ll walk through how to:
- Create a VM with a Local SSD
- Format and mount the SSD
- Configure auto-mount after reboot
- Test persistence across reboots and stops
- Clean up resources
🔹 Step 1: Create VM with Local SSD
👉 From the Console:
- Go to Compute Engine → VM Instances → Create Instance
- Name: demo9-vm-localssd
- Region: us-central1
- Zone: us-central1-a
- Machine family: N2 (not all series support Local SSDs)
- Machine type: n2-standard-2
- Boot Disk: Debian 9 (check OS compatibility for Local SSDs)
- Under Advanced Options → Disks → Add Local SSD
- Click Create
👉 Equivalent CLI command:
gcloud compute instances create demo9-vm-localssd \
--project=gcpdemos \
--zone=us-central1-a \
--machine-type=n2-standard-2 \
--network-interface=subnet=default \
--tags=http-server \
--local-ssd=interface=NVME
🔹 Step 2: Format & Mount the SSD
Connect to the VM:
gcloud compute ssh --zone "us-central1-a" "demo9-vm-localssd" --project "gcpdemos"
Check block devices:
sudo lsblk
Format the Local SSD with ext4:
sudo mkfs.ext4 -F /dev/nvme0n1
Create a mount directory and mount the disk:
sudo mkdir -p /mnt/disks/disk1ssd
sudo mount /dev/nvme0n1 /mnt/disks/disk1ssd
sudo chmod a+w /mnt/disks/disk1ssd
Verify:
sudo df -h
✅ You should see /dev/nvme0n1 mounted at /mnt/disks/disk1ssd.
🔹 Step 3: Auto-Mount SSD on Reboot
Local SSDs won’t automatically mount after reboot unless configured.
Backup fstab:
sudo cp /etc/fstab /etc/fstab_backup_before_localssd
Get the UUID:
sudo blkid -s UUID
Add entry to /etc/fstab:
echo UUID=<YOUR-UUID-HERE> /mnt/disks/disk1ssd ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
Verify:
cat /etc/fstab
🔹 Step 4: Test the SSD
Write a test file:
sudo echo "Welcome to GCP Local SSD - Host: $(hostname)" | sudo tee /mnt/disks/disk1ssd/localssd.html
cat /mnt/disks/disk1ssd/localssd.html
Reboot the VM:
sudo reboot
Reconnect and verify:
df -h
ls -lrt /mnt/disks/disk1ssd/
cat /mnt/disks/disk1ssd/localssd.html
✅ The SSD remounts automatically, and your file persists across reboots.
🔹 Step 5: Important Notes on Local SSDs
- If you stop the VM, you must decide whether to preserve or discard SSD data.
- Flags to remember:
- --discard-local-ssd=True → discard data
- --discard-local-ssd=False → preserve data (at cost)
Example:
# Stop VM & preserve SSD
gcloud compute instances stop demo9-vm-localssd --zone=us-central1-a --discard-local-ssd=False
🔹 Step 6: Cleanup
# Stop VM
gcloud compute instances stop demo9-vm-localssd --zone=us-central1-a
# Delete VM
gcloud compute instances delete demo9-vm-localssd --zone=us-central1-a
✅ Wrap Up
- Persistent Disks are durable and snapshot-friendly.
- Local SSDs give blazing-fast performance but require careful handling since they are ephemeral by default.
- Best suited for high-performance workloads like caching, databases with replication, or temporary storage needs.
🚀 Now you can confidently create and manage VMs with Local SSDs in GCP.
Top comments (0)