EBS basics (volumes, types, attach to EC2)
Topic: Cloud aws core
Summary
EBS provides block storage for EC2 instances. Create a volume in an AZ, attach it to an instance in the same AZ, and mount it inside the OS. Use this when you need persistent disk for an instance or when sizing or changing the root or data volume.
Intent: How-to
Quick answer
- Create volume in EC2 -> Volumes: choose AZ (must match instance AZ), size, type (gp3 for general, io2 for high IOPS). Attach to instance: select instance and device name (e.g. /dev/sdf).
- Inside Linux: lsblk to see the device; mkfs if new (e.g. mkfs.ext4 /dev/nvme1n1); mount and add to /etc/fstab. Windows: disk management to bring online and format.
- Root volume is created with the instance; resize in console or CLI then extend partition and filesystem inside the OS. EBS is AZ-bound; snapshot to move data across AZs or regions.
Prerequisites
Steps
-
Create and attach
EC2 -> Volumes -> Create volume; select AZ (same as instance), size, type (gp3 recommended). Attach: Actions -> Attach volume; select instance and device name (/dev/sdf or /dev/xvdf).
-
Mount (Linux)
lsblk to see device (e.g. nvme1n1). New volume: mkfs.ext4 /dev/nvme1n1; mkdir /data; mount /dev/nvme1n1 /data. Add to /etc/fstab by UUID so it mounts on reboot.
-
Resize root or volume
Modify volume in console (increase size); wait for optimizing. Linux: growpart and resize2fs (or xfs_growfs). Do not reduce size without backup and re-create.
-
Snapshot and restore
Snapshot for backup or to copy to another AZ/region. Create volume from snapshot in target AZ; attach to instance. Encrypt volumes for sensitive data (encryption at rest).
Summary
Create EBS volume in the same AZ as the instance; attach and mount (format if new). Resize by modifying the volume then growing partition and filesystem. Use snapshots for backup and cross-AZ copy. Use this for persistent EC2 storage.
Prerequisites
Steps
Step 1: Create and attach
Create volume in the same AZ; attach to instance with a device name.
Step 2: Mount (Linux)
Format if new; mount and add to fstab by UUID.
Step 3: Resize root or volume
Increase volume in console; grow partition and filesystem in the OS.
Step 4: Snapshot and restore
Snapshot for backup; create volume from snapshot in another AZ or region; attach and mount.
Verification
Volume is attached and mounted; data persists across instance stop/start; resize and snapshot work as expected.
Troubleshooting
Volume not visible — Check attachment and device name; use lsblk; NVMe devices may have different names. Wrong AZ — Detach; create snapshot; create volume from snapshot in correct AZ; attach.