Fundamental EBS Concepts
What is Amazon EBS?
Amazon EBS (Elastic Block Store) is AWS's block storage service. It provides persistent storage volumes for EC2 instances.
┌─────────────────────────────────────────────────────────────┐
│ AMAZON EBS │
├─────────────────────────────────────────────────────────────┤
│ │
│ "Virtual hard drives for your cloud servers" │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ EC2 Instance │ │
│ │ │ │
│ │ ┌────────────────┐ ┌────────────────┐ │ │
│ │ │ EBS Volume │ │ EBS Volume │ │ │
│ │ │ (Root - OS) │ │ (Data) │ │ │
│ │ │ /dev/xvda │ │ /dev/xvdb │ │ │
│ │ │ 8 GB │ │ 100 GB │ │ │
│ │ └────────────────┘ └────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Features: │
│ • Block storage (like a hard drive) │
│ • Persistent (data retained after shutdown) │
│ • Attachable/Detachable │
│ • Replicated within the AZ │
│ • Encryption available │
│ │
└─────────────────────────────────────────────────────────────┘
EBS vs Instance Store
┌─────────────────────────────────────────────────────────────┐
│ EBS vs INSTANCE STORE │
├─────────────────────────────────────────────────────────────┤
│ │
│ EBS (Elastic Block Store) INSTANCE STORE │
│ ───────────────────────── ───────────── │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Network │ │ Local │ │
│ │ Storage │ │ Storage │ │
│ │ │ │ (on the host) │ │
│ │ Separate │ │ Physical disk │ │
│ │ volume │ │ of the server │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
│ ✅ Persistent ❌ Ephemeral │
│ ✅ Snapshots ❌ No backup │
│ ✅ Detachable ❌ Fixed to the instance │
│ ✅ Resizable ❌ Fixed size │
│ │
│ ⚠️ Network latency ✅ Very low latency │
│ 💰 Charged ✅ Included (some types) │
│ │
│ USE CASES: │
│ • Data to retain • Temporary cache │
│ • Databases • Ephemeral data │
│ • Applications • Buffer/Swap │
│ │
└─────────────────────────────────────────────────────────────┘
EBS Volume Types
Overview
┌─────────────────────────────────────────────────────────────┐
│ EBS VOLUME TYPES │
├─────────────────────────────────────────────────────────────┤
│ │
│ SSD (Solid State Drive) │
│ ├── gp3 (General Purpose SSD) ← RECOMMENDED │
│ ├── gp2 (General Purpose SSD - old) │
│ ├── io1 (Provisioned IOPS SSD) │
│ └── io2 (Provisioned IOPS SSD - new gen) │
│ │
│ HDD (Hard Disk Drive) │
│ ├── st1 (Throughput Optimized HDD) │
│ └── sc1 (Cold HDD) │
│ │
│ Quick choice: │
│ • General use, boot → gp3 │
│ • High-performance DB → io2 │
│ • Big Data, sequential → st1 │
│ • Archive, infrequent access → sc1 │
│ │
└─────────────────────────────────────────────────────────────┘
Detailed Comparison
| Type | Max IOPS | Max Throughput | Size | Price/GB | Use Case |
|---|---|---|---|---|---|
| gp3 | 16,000 | 1,000 MB/s | 1GB-16TB | $0.08 | General use |
| gp2 | 16,000 | 250 MB/s | 1GB-16TB | $0.10 | Legacy |
| io2 | 64,000 | 1,000 MB/s | 4GB-16TB | $0.125 + IOPS | Critical DB |
| io1 | 64,000 | 1,000 MB/s | 4GB-16TB | $0.125 + IOPS | Legacy |
| st1 | 500 | 500 MB/s | 500GB-16TB | $0.045 | Big Data |
| sc1 | 250 | 250 MB/s | 500GB-16TB | $0.025 | Archive |
gp3 vs gp2 (The Most Important)
┌─────────────────────────────────────────────────────────────┐
│ gp3 vs gp2 │
├─────────────────────────────────────────────────────────────┤
│ │
│ gp2 (old) gp3 (new, preferred) │
│ ──────────── ───────────────────── │
│ │
│ IOPS tied to size Configurable IOPS │
│ 3 IOPS/GB (min 100) 3,000 IOPS base │
│ Max 16,000 IOPS Up to 16,000 IOPS │
│ │
│ Limited throughput Configurable throughput │
│ 128-250 MB/s 125-1,000 MB/s │
│ │
│ $0.10/GB $0.08/GB (+IOPS if >3000) │
│ │
│ Example 100 GB: Example 100 GB: │
│ • 300 IOPS (3×100) • 3,000 IOPS (base) │
│ • 128 MB/s • 125 MB/s (scalable) │
│ • $10/month • $8/month │
│ │
│ ✅ ALWAYS prefer gp3 for new volumes! │
│ │
└─────────────────────────────────────────────────────────────┘
EBS Volume Lifecycle
┌─────────────────────────────────────────────────────────────┐
│ EBS LIFECYCLE │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ │
│ │ Create │ ← aws ec2 create-volume │
│ └────┬─────┘ │
│ │ │
│ ▼ │
│ ┌──────────┐ │
│ │Available │ ← Volume created, not attached │
│ └────┬─────┘ │
│ │ attach-volume │
│ ▼ │
│ ┌──────────┐ │
│ │ In-use │ ← Attached to an instance │
│ └────┬─────┘ │
│ │ │
│ ┌────┴────┐ │
│ │ │ │
│ ▼ ▼ │
│ Snapshot Detach │
│ │ │ │
│ │ ▼ │
│ │ ┌──────────┐ │
│ │ │Available │ │
│ │ └────┬─────┘ │
│ │ │ delete-volume │
│ │ ▼ │
│ │ ┌──────────┐ │
│ │ │ Deleted │ │
│ │ └──────────┘ │
│ │ │
│ └──► Snapshot (for backup or new AZ) │
│ │
└─────────────────────────────────────────────────────────────┘
Volumes and AZ
┌─────────────────────────────────────────────────────────────┐
│ EBS AND AVAILABILITY ZONES │
├─────────────────────────────────────────────────────────────┤
│ │
│ ⚠️ An EBS volume exists in ONLY ONE AZ! │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Region us-east-1 │ │
│ │ │ │
│ │ ┌───────────────┐ ┌───────────────┐ │ │
│ │ │ us-east-1a │ │ us-east-1b │ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌─────────┐ │ │ ┌─────────┐ │ │ │
│ │ │ │ vol-aaa │ │ ❌ │ │ EC2 │ │ │ │
│ │ │ └─────────┘ │ ───► │ │ │ │ │ │
│ │ │ │ │ └─────────┘ │ │ │
│ │ └───────────────┘ └───────────────┘ │ │
│ │ │ │
│ │ vol-aaa cannot be attached to an instance in │ │
│ │ us-east-1b! │ │
│ │ │ │
│ │ Solution: Create a snapshot, then recreate the │ │
│ │ volume in the other AZ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Common Operations
Attach a Volume
# 1. Create the volume (same AZ as the instance!)
aws ec2 create-volume \
--availability-zone us-east-1a \
--size 100 \
--volume-type gp3
# 2. Attach to the instance
aws ec2 attach-volume \
--volume-id vol-xxx \
--instance-id i-xxx \
--device /dev/sdf
# 3. On the Linux instance, format and mount
# (Connect via SSH)
sudo mkfs -t ext4 /dev/xvdf
sudo mkdir /data
sudo mount /dev/xvdf /data
# 4. For permanent mount, edit /etc/fstab
echo '/dev/xvdf /data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab
Detach a Volume
# 1. On the instance, unmount properly
sudo umount /data
# 2. Detach via AWS
aws ec2 detach-volume --volume-id vol-xxx
Resize a Volume
# 1. Modify the size (no need to detach!)
aws ec2 modify-volume \
--volume-id vol-xxx \
--size 200
# 2. On the instance, extend the filesystem
# For ext4:
sudo growpart /dev/xvdf 1
sudo resize2fs /dev/xvdf1
# For xfs:
sudo xfs_growfs /data
Delete on Termination
┌─────────────────────────────────────────────────────────────┐
│ DELETE ON TERMINATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ Option that determines if the volume is deleted │
│ when the instance is terminated. │
│ │
│ DeleteOnTermination = TRUE (default for root) │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Instance │ ── Terminate ──► │ Volume │ │
│ │ terminated │ │ DELETED │ │
│ └─────────────┘ └─────────────┘ │
│ │
│ DeleteOnTermination = FALSE (recommended for data) │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Instance │ ── Terminate ──► │ Volume │ │
│ │ terminated │ │ RETAINED │ │
│ └─────────────┘ └─────────────┘ │
│ │
│ Recommendation: │
│ • Root volume (OS): TRUE (recreate with the instance) │
│ • Data volumes: FALSE (retain the data) │
│ │
└─────────────────────────────────────────────────────────────┘
EBS Encryption
┌─────────────────────────────────────────────────────────────┐
│ EBS ENCRYPTION │
├─────────────────────────────────────────────────────────────┤
│ │
│ Encryption at rest with AWS KMS │
│ │
│ What is encrypted: │
│ ✅ Data on the volume │
│ ✅ Data in transit (volume ↔ instance) │
│ ✅ Snapshots created from the volume │
│ ✅ Volumes created from snapshots │
│ │
│ Performance impact: MINIMAL (< 5%) │
│ Cost: Free (KMS default key) or custom key │
│ │
│ Best practice: ALWAYS encrypt! │
│ │
│ # Create an encrypted volume │
│ aws ec2 create-volume \ │
│ --encrypted \ │
│ --kms-key-id alias/aws/ebs \ │
│ --availability-zone us-east-1a \ │
│ --size 100 │
│ │
└─────────────────────────────────────────────────────────────┘
Summary
| Concept | Description |
|---|---|
| EBS | Persistent block storage for EC2 |
| gp3 | Recommended type for general use |
| io2 | High performance (DB) |
| st1/sc1 | HDD for large volumes, sequential access |
| Snapshot | Incremental backup to S3 |
| AZ-bound | Volume limited to a single AZ |
| Encryption | Always enable, minimal impact |
Validation Quiz
- What is the difference between EBS and Instance Store?
- Which volume type for a critical database?
- Can you attach a volume from us-east-1a to an instance in us-east-1b?
- What is the difference between gp2 and gp3?
- What is "Delete on Termination"?
Next section: Snapshots