Overview and What You Will Learn
Amazon EBS is network-attached block storage for EC2 that lives independently of the instance. Choose gp3 for almost everything, io2 when you need very high or guaranteed IOPS, and st1 or sc1 for large sequential workloads. EC2 Instance Store is local disk on the host: the fastest storage you can get, but its contents are lost when the instance stops or fails.
In this lab you will:
- Compare the six EBS volume types and see why gp3 replaced gp2
- Create, attach, format and mount a gp3 volume, then resize it online
- Back up with snapshots and restore them, including the four-step process to encrypt an existing volume
- Protect snapshots with Recycle Bin and speed up restores with Fast Snapshot Restore
- Decide when Instance Store is the correct choice
Why This Matters in Production
Storage decisions feel invisible until they cause an incident. Picture a brokerage database on gp2 during market open: IOPS are tied to volume size, the volume is too small to provide enough IOPS, and transaction latency climbs under load. Moving to gp3 or io2 fixes it, because IOPS can be set independently of size. Or picture an engineer deleting a snapshot you need for restores: with Recycle Bin that is a recoverable mistake, and without it the snapshot is gone.
Core Principles
An EBS volume exists in a single Availability Zone, attaches to one instance at a time (except Multi-Attach), and is provisioned, so you pay for the size you allocate and not what you use. It is not a file system, so you format it yourself, and it is not shared storage, for which you use EFS.
or consistent latency| I([io2]) Q -->|Large sequential reads and writes| S([st1]) Q -->|Rarely accessed, cheapest| C([sc1]) Q -->|Scratch data, replicated data,
maximum local speed| L([Instance Store]) classDef ssd fill:#326CE5,color:#FFFFFF classDef hdd fill:#F97316,color:#FFFFFF classDef local fill:#8B5CF6,color:#FFFFFF classDef ask fill:#DBEAFE,color:#1E293B class G,I ssd class S,C hdd class L local class Q ask
| Type | Max IOPS | Max throughput |
|---|---|---|
| gp3 | 16,000 | 1,000 MiB/s |
| gp2 | 16,000 | 250 MiB/s |
| io2 Block Express | 256,000 | 4,000 MiB/s |
| io1 | 64,000 | 1,000 MiB/s |
| st1 (HDD) | 500 | 500 MiB/s |
| sc1 (HDD) | 250 | 250 MiB/s |
Only SSD types (gp2, gp3, io1, io2) can be boot volumes. HDD types cannot. Limits depend on instance type and Region, so check the current EBS documentation for your case.
gp3 versus gp2 is the most important distinction. On gp2, IOPS equal 3 per GiB of size (minimum 100, up to 16,000), so a small volume gets few IOPS and you buy extra capacity just to get performance. On gp3, every volume includes 3,000 IOPS and 125 MiB/s regardless of size, and you can raise IOPS and throughput independently. gp3 is also about 20 percent cheaper per GB.
Need 6,000 IOPS and 100 GiB of space: gp2: provision 2,000 GiB to reach 6,000 IOPS (1,900 GiB wasted) gp3: provision 100 GiB and set IOPS to 6,000Delete on Termination is on by default for the root volume and off by default for additional volumes. Turn it off for roots that hold data you may need to recover.
io1 and io2 Multi-Attach lets up to 16 Nitro instances in the same AZ attach one volume. It is only safe with cluster-aware software that coordinates writes. Standard file systems such as ext4 and XFS are not cluster-aware, and sharing them between instances corrupts data.
Detailed Step-by-Step Practical Lab
Milestone 1: Create and Attach a gp3 Volume
The volume must be in the same AZ as the instance. IOPS and throughput are set separately from size.
export AWS_REGION=ap-south-1export INSTANCE_ID=i-0abc123def456789export AZ=ap-south-1a VOLUME_ID=$(aws ec2 create-volume \ --volume-type gp3 --size 10 --iops 3000 --throughput 125 \ --availability-zone $AZ \ --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=devops-data}]' \ --query VolumeId --output text) aws ec2 wait volume-available --volume-ids $VOLUME_ID aws ec2 attach-volume \ --volume-id $VOLUME_ID --instance-id $INSTANCE_ID --device /dev/sdfMilestone 2: Format, Mount and Persist
On Nitro instances the device appears as an NVMe name such as /dev/nvme1n1, not /dev/sdf. Check with lsblk instead of assuming.
lsblk# NAME SIZE TYPE MOUNTPOINT# nvme0n1 8G disk# nvme1n1 10G disk <- the new volume sudo mkfs -t xfs /dev/nvme1n1sudo mkdir /datasudo mount /dev/nvme1n1 /data # Mount by UUID at boot, and do not hang the boot if the volume is missingUUID=$(sudo blkid -s UUID -o value /dev/nvme1n1)echo "UUID=$UUID /data xfs defaults,nofail 0 2" | sudo tee -a /etc/fstabsudo mount -a echo "Important production data" | sudo tee /data/critical.txtdf -h /dataMilestone 3: Resize and Retune Online
Elastic Volumes lets you change size, type, IOPS and throughput on a running volume. A volume can only grow, never shrink, and after a modification you must wait before changing it again (about six hours). After increasing size you must grow the file system too.
aws ec2 modify-volume --volume-id $VOLUME_ID --size 20 --iops 6000 aws ec2 describe-volumes-modifications --volume-ids $VOLUME_ID \ --query "VolumesModifications[].[ModificationState,Progress]" --output text# optimizing is usable, completed means finished # On the instance, grow the file system into the new spacesudo xfs_growfs -d /datadf -h /dataTo migrate a gp2 volume to gp3, run modify-volume --volume-type gp3 with explicit IOPS. Check the volume's real IOPS usage first, because a gp2 volume with burst credits may be running above its baseline.
Milestone 4: Take and Restore Snapshots
Snapshots are incremental: the first copies everything and later ones store only changed blocks. You can delete an old snapshot safely, because AWS keeps the data that other snapshots still need.
SNAP_ID=$(aws ec2 create-snapshot \ --volume-id $VOLUME_ID \ --description "devops-data before upgrade" \ --query SnapshotId --output text) aws ec2 wait snapshot-completed --snapshot-ids $SNAP_ID # Restore to a new volume in any AZ of the Regionaws ec2 create-volume \ --snapshot-id $SNAP_ID --volume-type gp3 --availability-zone ap-south-1b # Copy to another Region for disaster recovery (run against the destination Region)aws ec2 copy-snapshot \ --source-region ap-south-1 --source-snapshot-id $SNAP_ID \ --description "DR copy" --region ap-southeast-1 # Share with another accountaws ec2 modify-snapshot-attribute \ --snapshot-id $SNAP_ID --attribute createVolumePermission \ --operation-type add --user-ids 999888777666For rarely used snapshots, the Archive tier costs about 75 percent less. It has a 90 day minimum, and restoring takes 24 to 72 hours.
aws ec2 modify-snapshot-tier --snapshot-id $SNAP_ID --storage-tier archiveDo not rely on running these by hand. Use Amazon Data Lifecycle Manager or AWS Backup to take snapshots on a schedule, copy them across Regions and expire them automatically.
Milestone 5: Encrypt an Existing Volume
You cannot flip encryption on for an existing unencrypted volume. You copy through an encrypted snapshot instead.
# 1. Snapshot the unencrypted volumeSNAP_ID=$(aws ec2 create-snapshot --volume-id $VOLUME_ID --query SnapshotId --output text)aws ec2 wait snapshot-completed --snapshot-ids $SNAP_ID # 2. Copy the snapshot with encryption enabledENC_SNAP=$(aws ec2 copy-snapshot \ --source-region ap-south-1 --source-snapshot-id $SNAP_ID \ --encrypted --kms-key-id alias/devops-prod-key \ --query SnapshotId --output text)aws ec2 wait snapshot-completed --snapshot-ids $ENC_SNAP # 3. Create an encrypted volume from the encrypted snapshotNEW_VOL=$(aws ec2 create-volume \ --snapshot-id $ENC_SNAP --volume-type gp3 --availability-zone ap-south-1a \ --query VolumeId --output text)aws ec2 wait volume-available --volume-ids $NEW_VOL # 4. Stop using the old volume, detach it, and attach the new onesudo umount /data # on the instanceaws ec2 detach-volume --volume-id $VOLUME_IDaws ec2 attach-volume --volume-id $NEW_VOL --instance-id $INSTANCE_ID --device /dev/sdfPrevent the problem next time by turning on encryption by default. It is a per-Region setting, so enable it in every Region you use.
aws ec2 enable-ebs-encryption-by-default --region ap-south-1aws ec2 get-ebs-encryption-by-default --region ap-south-1Milestone 6: Protect Snapshots with Recycle Bin
Without Recycle Bin, a deleted snapshot is permanently gone. A retention rule keeps deleted snapshots recoverable for the period you choose.
aws rbin create-rule \ --retention-period RetentionPeriodValue=14,RetentionPeriodUnit=DAYS \ --resource-type EBS_SNAPSHOT \ --description "14 day snapshot recovery window" # After an accidental deleteaws ec2 list-snapshots-in-recycle-binaws ec2 restore-snapshot-from-recycle-bin --snapshot-id $SNAP_IDMilestone 7: Remove Restore Latency with Fast Snapshot Restore
A volume created from a snapshot loads its data lazily from S3, so the first read of each block is slow. This hurts when you restore a database and expect full speed. Fast Snapshot Restore pre-warms the snapshot in the AZs you choose, so new volumes perform fully at once.
aws ec2 enable-fast-snapshot-restores \ --availability-zones ap-south-1a ap-south-1b \ --source-snapshot-ids $SNAP_ID aws ec2 describe-fast-snapshot-restores \ --filters Name=snapshot-id,Values=$SNAP_ID \ --query "FastSnapshotRestores[].[AvailabilityZone,State]" --output table aws ec2 disable-fast-snapshot-restores \ --availability-zones ap-south-1a ap-south-1b --source-snapshot-ids $SNAP_IDFSR is billed per minute for each snapshot in each AZ while it is enabled, and the number of snapshots with FSR per Region is limited, so enable it only for restore-critical snapshots and disable it afterward. If you skip FSR, read the whole volume once with a tool like fio or dd to initialize it before production use.
Milestone 8: Decide When Instance Store Is Correct
Instance Store is physical disk attached to the host. It has no network hop, so it delivers the highest IOPS and lowest latency EC2 offers, and the size and speed depend on the instance type (storage-optimized families such as i4i). The trade-off is durability.
| Event | Instance Store data |
|---|---|
| Reboot | Kept |
| Stop, terminate, hibernate | Lost |
| Host or disk failure | Lost |
Use it for caches, buffers, scratch space and for data that is already replicated, such as Kafka brokers and Elasticsearch or OpenSearch nodes, where losing one node is acceptable and the cluster rebuilds it. Do not use it for any single copy of data you cannot recreate.
Milestone 9: Clean Up
sudo umount /data # on the instance, and remove the fstab lineaws ec2 detach-volume --volume-id $NEW_VOLaws ec2 delete-volume --volume-id $NEW_VOLaws ec2 delete-volume --volume-id $VOLUME_IDaws ec2 delete-snapshot --snapshot-id $SNAP_IDaws ec2 delete-snapshot --snapshot-id $ENC_SNAPProduction Best Practices & Common Pitfalls
- Use gp3 for new volumes. It is cheaper than gp2 and decouples IOPS from size.
- Enable encryption by default in every Region. New volumes are then encrypted automatically.
- Automate snapshots. Use Data Lifecycle Manager or AWS Backup, and test restores.
- Enable Recycle Bin for snapshots. A 7 to 30 day window costs little and prevents permanent mistakes.
- Turn off Delete on Termination for data volumes and data-bearing roots.
- Match the type to the access pattern. st1 for sequential throughput, io2 for latency-sensitive databases.
- Mount by UUID with
nofail. Device names change and a missing volume should not block boot. - Treat Instance Store as disposable. Replicate or rebuild anything stored there.
Common MistakeUsing Instance Store for data that must survive. A stop, termination or host failure destroys it, with no snapshot and no recovery.
Common MistakeEnabling Multi-Attach with ext4 or XFS. These file systems assume a single writer, and two hosts mounting the same volume will corrupt it.
TipSnapshot before any risky change, such as a resize, type change or upgrade. It takes minutes and gives you a clean rollback.
RememberEBS is locked to one Availability Zone. To move data to another AZ, snapshot it and create a new volume there.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
aws ec2 describe-volumes |
List volumes |
aws ec2 create-volume --volume-type gp3 |
Create a volume |
aws ec2 modify-volume |
Change size, type, IOPS or throughput online |
aws ec2 create-snapshot |
Back up a volume |
aws ec2 copy-snapshot |
Copy or encrypt a snapshot |
aws ec2 restore-snapshot-from-recycle-bin |
Recover a deleted snapshot |
lsblk |
Show block devices on the instance |
| Symptom | Likely cause and fix |
|---|---|
| Volume cannot attach | Different AZ from the instance, snapshot and recreate in the right AZ |
| Disk missing after attach | NVMe naming, check lsblk for the real device |
| Larger size not visible | File system not grown, run growpart and xfs_growfs or resize2fs |
| Slow first reads after restore | Lazy initialization, use Fast Snapshot Restore or pre-read the volume |
| IOPS throttling on gp2 | IOPS tied to small size, move to gp3 and set IOPS |
| Cannot delete snapshot | Referenced by an AMI, deregister the AMI first |