DEV Community

Latchu@DevOps
Latchu@DevOps

Posted on

Part-33: ⚡Configuring VM with Local SSD in Google Cloud Platform (GCP)

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:

  1. Create a VM with a Local SSD
  2. Format and mount the SSD
  3. Configure auto-mount after reboot
  4. Test persistence across reboots and stops
  5. 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 
Enter fullscreen mode Exit fullscreen mode

🔹 Step 2: Format & Mount the SSD

Connect to the VM:

gcloud compute ssh --zone "us-central1-a" "demo9-vm-localssd" --project "gcpdemos" 
Enter fullscreen mode Exit fullscreen mode

Check block devices:

sudo lsblk 
Enter fullscreen mode Exit fullscreen mode

Format the Local SSD with ext4:

sudo mkfs.ext4 -F /dev/nvme0n1 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

Verify:

sudo df -h 
Enter fullscreen mode Exit fullscreen mode

✅ 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 
Enter fullscreen mode Exit fullscreen mode

Get the UUID:

sudo blkid -s UUID 
Enter fullscreen mode Exit fullscreen mode

Add entry to /etc/fstab:

echo UUID=<YOUR-UUID-HERE> /mnt/disks/disk1ssd ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab 
Enter fullscreen mode Exit fullscreen mode

Verify:

cat /etc/fstab 
Enter fullscreen mode Exit fullscreen mode

🔹 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 
Enter fullscreen mode Exit fullscreen mode

Reboot the VM:

sudo reboot 
Enter fullscreen mode Exit fullscreen mode

Reconnect and verify:

df -h ls -lrt /mnt/disks/disk1ssd/ cat /mnt/disks/disk1ssd/localssd.html 
Enter fullscreen mode Exit fullscreen mode

✅ The SSD remounts automatically, and your file persists across reboots.


🔹 Step 5: Important Notes on Local SSDs

  1. If you stop the VM, you must decide whether to preserve or discard SSD data.
  2. 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 
Enter fullscreen mode Exit fullscreen mode

🔹 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 
Enter fullscreen mode Exit fullscreen mode

✅ 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)