Stop 05 · Storage ServicesTopics · 2/9

Block Storage (EBS)

Part of the Cloud Computing Roadmap

In short

Every VM needs a disk to boot from and somewhere fast to keep its database files. That's block storage: it behaves exactly like a hard drive, just one that lives on the network.

Storage that attaches to a single VM like a traditional hard drive, offering low-latency, high-performance access — used for a VM's operating system disk and any application requiring fast, direct storage access.

The blob character puts books into a steel almirah in a hostel room.

Think of it like this

The almirah in your hostel room

Your steel almirah sits in your room. Only you open it, and things are right there when you need them. Move rooms and you can carry it along, but it can't sit in two rooms at once. That's a block volume.

Watch it happen

Adding a data disk to a VM

Create
Attach
Format
Mount
Snapshot

1/5Create a 20 GB gp3 volume in the same availability zone as your VM.

The big ideas

What you need to know

Acts like a local disk

The OS sees a raw device to format and mount. Databases and boot drives need this kind of storage.

One VM, one zone

A volume lives in one availability zone and usually attaches to one instance at a time.

Pick for speed

gp3 is the general default. io2 gives very high, guaranteed IOPS for busy databases. HDD types suit big sequential reads.

Snapshots for safety

Snapshots are incremental backups. Use them to restore, copy to another region or build a volume in a new zone.

See it in code

Walk through the code

bash
1lsblk                                  # find the new disk, e.g. nvme1n12sudo mkfs -t xfs /dev/nvme1n1          # ONLY on a new, empty disk3sudo mkdir /data4sudo mount /dev/nvme1n1 /data5df -h /data                            # check size and mount6 7# Make it survive reboots (use the UUID, not the device name)8sudo blkid /dev/nvme1n19echo 'UUID=<your-uuid> /data xfs defaults,nofail 0 2' | sudo tee -a /etc/fstab

1/3Spot the new disk and format it. mkfs erases everything on the device.

Device names can change between reboots on Nitro instances, so /etc/fstab should use the disk's UUID.

Save yourself the pain

Common mistakes

Oops

Running mkfs on a volume restored from a snapshot.

Do this instead

Restored volumes already have data. Check with sudo file -s /dev/nvme1n1 before formatting anything.

Oops

Creating the volume in a different zone from the VM.

Do this instead

Volumes attach only within their own zone. To move, snapshot it and create a new volume in the target zone.

Your mission

Attach, write, detach, reattach

~35 min

Quick check

You need fast storage for a PostgreSQL server running on one EC2 instance. What fits best?

Go deeper

  1. 1Attach a block storage volume to a VM and format/mount it.
  2. 2Learn the difference between block storage's single-VM attachment and object storage's broad accessibility.
  3. 3Understand why databases typically use block storage rather than object storage directly.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge