EC2 Storage and Data Management - EBS and EFS
Operate block and shared file storage for EC2 with EBS volumes, snapshots, encryption, resizing, EFS mount targets, and lifecycle decisions.
What you'll learn
- Choose between EBS and EFS for EC2 workloads
- Create, attach, mount, resize, and snapshot EBS volumes
- Use snapshots for backup, restore, and cross-region copy
- Mount EFS from multiple EC2 instances
Prerequisites
Relevant for certifications
EBS vs EFS
| Service | Storage type | Attached to | Best for |
|---|---|---|---|
| EBS | Block storage | One EC2 instance in one AZ at a time | Boot volumes, databases, low-latency disks |
| EFS | Managed NFS file system | Many instances across AZs | Shared content, Linux home directories, shared app files |
Fast decision
Use EBS when the workload needs a disk. Use EFS when multiple Linux instances need the same files at the same time.
EBS Operations
EBS volumes are AZ-scoped. An instance and its attached EBS volume must be in the same Availability Zone.
Common operations:
- Increase volume size without stopping the instance.
- Change volume type, such as
gp2togp3. - Tune
gp3IOPS and throughput independently. - Snapshot a volume for backup.
- Copy snapshots to another Region.
- Create a new volume from a snapshot.
Snapshot Behavior
EBS snapshots are incremental after the first snapshot. Each snapshot references the blocks needed to restore the volume at that point in time.
For application-consistent backups, flush application writes, briefly freeze or stop the workload, create the snapshot, and then resume writes.
Hands-on: Add and Mount an EBS Volume
Goal: Attach a data disk to Linux and persist it across reboots.
- Open EC2 > Volumes and choose Create volume.
- Select
gp3,8 GiB, encryption enabled, and the same Availability Zone as your EC2 instance. - Select the volume and choose Attach volume.
- Attach it to your instance as
/dev/sdf. - Connect to the instance and identify the device:
lsblk
- Create a filesystem and mount it:
sudo mkfs -t xfs /dev/xvdf
sudo mkdir -p /data
sudo mount /dev/xvdf /data
df -h
- Persist the mount in
/etc/fstabusing the volume UUID:
sudo blkid /dev/xvdf
sudo cp /etc/fstab /etc/fstab.bak
echo "UUID=<uuid> /data xfs defaults,nofail 0 2" | sudo tee -a /etc/fstab
sudo mount -a
- Create a test file in
/data. - Reboot the instance and confirm
/datais mounted.
Hands-on: Resize an EBS Volume
Goal: Increase a Linux data volume from 8 GiB to 16 GiB.
- In EC2 > Volumes, select the volume.
- Choose Modify volume and change size to
16 GiB. - Wait until modification state is
optimizingorcompleted. - On the instance, grow the partition if needed:
lsblk
sudo growpart /dev/xvdf 1
- Grow the filesystem:
# XFS
sudo xfs_growfs /data
# ext4 alternative
sudo resize2fs /dev/xvdf1
- Confirm with
df -h.
Hands-on: Snapshot and Restore an EBS Volume
- Select the EBS volume and choose Create snapshot.
- Add tags such as
Name = cloudops-data-backup. - Wait for snapshot completion.
- Create a new volume from the snapshot in the same AZ as a test instance.
- Attach and mount the restored volume.
- Confirm the test file exists.
- Clean up the restored volume and old snapshots when done.
EFS Operations
EFS is regional and uses mount targets in subnets. Each mount target has an IP in a subnet and a security group.
Security group pattern:
- EC2 security group: outbound NFS TCP 2049 to EFS security group.
- EFS security group: inbound NFS TCP 2049 from EC2 security group.
Hands-on: Mount EFS on Two EC2 Instances
- Create an EFS file system.
- Create mount targets in at least two subnets.
- Configure the EFS security group to allow inbound NFS TCP 2049 from the EC2 security group.
- On each EC2 instance, install the EFS mount helper:
sudo dnf install -y amazon-efs-utils
- Mount the file system:
sudo mkdir -p /shared
sudo mount -t efs -o tls fs-1234567890abcdef0:/ /shared
- On instance A, create a file in
/shared. - On instance B, read the same file.
- Add an
/etc/fstabentry if the mount should survive reboot.
Common SOA-C03 Exam Questions
Q: Can an EBS volume attach to an instance in another AZ? No. EBS volumes are AZ-scoped.
Q: Which service lets multiple EC2 instances share the same Linux file system? Amazon EFS.
Q: How do you copy an EBS backup to another Region? Copy the EBS snapshot to the destination Region, then create a volume from the copied snapshot.
What to Learn Next
- Amazon S3 for CloudOps - object storage, lifecycle, and replication
- AWS Disaster Recovery for CloudOps - backup and recovery patterns
- AWS Security & Compliance - KMS encryption and access controls
