GCP Persistent Disk Storage
Persistent Disk is Google Cloud's durable, high-performance block storage service. It serves as the virtual hard drive for your Virtual Machine (VM) instances. Unlike ephemeral storage, Persistent Disks exist independently of the VM; data persists even if the instance is terminated.
1. Key Characteristics
- Network-Attached: Connected via Google’s high-speed network, allowing disks to be easily detached and moved between VMs in the same zone.
- High Availability: Data is automatically replicated multiple times within a zone to protect against hardware failure.
- Incremental Snapshots: Create point-in-time backups that only store data changed since the last snapshot, saving time and costs.
- Hot Resizing: Increase disk capacity on-the-fly without rebooting or detaching the disk.
2. Comparison of Disk Types
| Disk Type | Performance | Ideal Use Case |
|---|---|---|
| Standard (pd-standard) | HHDD-backed | Large data processing, cold storage, backups. |
| Balanced (pd-balanced) | Solid | General-purpose workloads, boot disks, web servers. |
| SSD (pd-ssd) | High | Relational databases (SQL), enterprise applications. |
| Extreme (pd-extreme) | Ultra | SAP HANA, Oracle, massive I/O workloads. |
3. Practical Example: Database Scaling
Imagine your database is outgrowing its server capacity. Because you used a Persistent Disk:
- You can take a Snapshot of the disk for safety.
- You can shut down the current VM, detach the disk, and attach it to a much larger N2 High-Mem machine.
- Your data is exactly where you left it, with zero data migration or manual file transfers required.
4. Steps for Using Persistent Disk in GCP
Phase 1: Create and Attach (Console)
- Go to Compute Engine > Storage > Disks and click Create Disk.
- Select the same Zone as your VM and define the size.
- Go to VM instances, edit your instance, and under Additional disks, click Attach existing disk.
Phase 2: Configuration (OS Level via SSH)
After attaching, you must prepare the disk for use with these commands:
# 1. Format the disk (Warning: deletes existing data)
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,discard /dev/sdb
# 2. Create a mount point directory
sudo mkdir -p /mnt/disks/data-storage
# 3. Mount the disk
sudo mount -o discard,defaults /dev/sdb /mnt/disks/data-storage
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,discard /dev/sdb
# 2. Create a mount point directory
sudo mkdir -p /mnt/disks/data-storage
# 3. Mount the disk
sudo mount -o discard,defaults /dev/sdb /mnt/disks/data-storage