Sub topic 1
What Amazon EBS is and how it works
Amazon Elastic Block Store (EBS) provides block storage volumes that you attach to EC2 instances. To the operating system, an EBS volume looks like a raw disk. You partition it, format it with a file system, and mount it. Unlike the disk inside a physical server, the volume lives on a separate storage service and connects to the instance over the network. This chapter covers the working model: what a volume is, where it lives, how it connects to an instance, and what that implies for availability, durability and billing.
Prerequisites
This chapter assumes you already know the following:
- Basic EC2 concepts: instances, AMIs and Availability Zones.
- The Linux command line.
- The AWS CLI or the AWS Management Console at a basic level.
- What a file system and a disk partition are.
You need no earlier chapter. Later chapters cover volume types, snapshots and encryption in detail. Here they appear only as far as needed to explain the model.
Block storage in one paragraph
A block device exposes storage as fixed-size blocks that are read and written by address. It has no concept of files or folders. The operating system adds that layer with a file system such as XFS or ext4. Databases, boot disks and any workload that needs low-latency random reads and writes use block storage. This differs from object storage (S3), which you reach through an HTTP API, and from file storage (EFS), which you mount as a shared network file system.
The core model
An EBS volume has these properties:
- Network-attached. The volume is not in the physical host that runs your instance. Reads and writes travel over the AWS network. On current Nitro-based instance types, a dedicated hardware card presents the volume to the guest as an NVMe device, so it appears as a name like
/dev/nvme1n1. - Scoped to one Availability Zone. A volume is created in a single AZ and can attach only to instances in that same AZ. To move data across AZs, you take a snapshot and create a new volume from it.
- Replicated within its AZ. EBS stores each volume's data redundantly across multiple servers in the AZ. A single hardware failure does not lose data. It does not protect you from the loss of the whole AZ, and it does not protect you from your own mistakes, such as deleting files.
- Independent of the instance. Stopping an instance keeps its volumes. A non-root volume also survives instance termination by default, and you can detach it and attach it to a different instance. (The root volume behaves differently by default, as a later chapter covers.)
- Provisioned, not elastic by usage. You choose a size and, depending on the type, performance settings when you create the volume. You pay for what you provision, whether or not you fill it.
- Attached to one instance at a time. The exception is Multi-Attach, which is available only on certain volume types and is covered in its own chapter. An instance can have many volumes attached.
What "network-attached" means for you
Because I/O crosses the network, three things follow.
- Latency is higher than local disks. EBS latency is typically in the single-digit millisecond range for general-purpose volumes, and sub-millisecond for the highest-performance types. A disk physically inside the host is faster, but it loses its data when the instance stops or fails (see the next chapter).
- Performance has two ceilings. The volume has its own limits on IOPS (I/O operations per second) and throughput (data moved per second). The instance also has limits on total EBS traffic. You reach whichever ceiling is lower. The performance chapters cover how to size both.
- You can detach and reattach while the data stays intact. This makes recovery simple. If an instance becomes unusable, you can move the data volume to a healthy instance in the same AZ.
Durability and availability, stated precisely
Durability is the chance that your data survives. Availability is the chance that you can reach it. EBS publishes an annual failure rate for each volume type: roughly 0.1% to 0.2% for most types, and 0.001% for io2 Block Express. These numbers describe loss of a volume from infrastructure failure, not loss from deletion or corruption caused by software. The practical conclusions are:
- A volume is a single-AZ resource. If the AZ has an outage, the volume is unavailable until the zone recovers.
- Snapshots are your protection against deletion, corruption and AZ loss. A snapshot is stored in Amazon S3, in storage that AWS manages. It does not appear in your S3 buckets.
- Treat a volume as durable disk, not as a backup.
Working with a volume from the CLI
The following command creates an encrypted 100 GiB gp3 volume with the baseline performance written out explicitly.
aws ec2 create-volume \
--availability-zone us-east-1a \
--volume-type gp3 \
--size 100 \
--iops 3000 \
--throughput 125 \
--encrypted \
--tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=data-vol}]'The command returns JSON that includes a VolumeId and a State of creating. To see the state, size and zone of your volumes in a table, query them:
aws ec2 describe-volumes \
--filters Name=tag:Name,Values=data-vol \
--query 'Volumes[].{Id:VolumeId,State:State,AZ:AvailabilityZone,GiB:Size,Attached:Attachments[0].InstanceId}' \
--output tableA volume moves through these states:
| State | Meaning |
|---|---|
| `creating` | EBS is provisioning the volume. |
| `available` | The volume exists and is not attached to any instance. |
| `in-use` | The volume is attached to at least one instance. |
| `deleting` | EBS is removing the volume. |
| `error` | The volume failed to create or is in a failed state. |
An available volume is still billed. A volume left behind after you terminate an instance is a common source of unnecessary cost.
What you pay for
EBS billing has these parts. The cost chapter treats them in depth.
- Provisioned storage in GiB-months, charged from creation to deletion, whether attached or not.
- Provisioned performance above the included baseline, such as extra IOPS or throughput on gp3, or all provisioned IOPS on io2.
- Snapshot storage, charged on the data the snapshots hold.
Data transfer between an instance and a volume in the same AZ is not billed separately.
Common errors
These problems appear most often when people first use EBS.
- Zone mismatch. Attaching fails with an error saying the volume and instance are in different Availability Zones. Check both with
describe-volumesanddescribe-instances. Create a snapshot and restore it in the right zone if the volume is in the wrong one. - Attached but unusable. A new volume is empty.
attach-volumesucceeds, but the operating system sees an unformatted disk until you create a file system and mount it. - Wrong device name. The
--device /dev/sdfvalue you give at attach time is a request. On Nitro instances the OS shows an NVMe name instead, and the number may change after reboot. Identify disks by UUID or volume ID, not by/dev/nvme1n1. - Assuming the volume is a backup. Replication within an AZ does not protect against deleting the wrong directory. Use snapshots.
- Forgotten volumes. Volumes in the
availablestate continue to cost money. List them regularly.
Summary of the model
An EBS volume is a provisioned, network-attached block device that is replicated inside one Availability Zone, billed from creation to deletion, and independent of the lifecycle of the instance it is attached to. Everything else in this tutorial builds on that: the volume type decides its performance and price, the attach and mount steps make it usable, and snapshots and encryption protect it.
Exercise
You have an EBS volume in us-east-1a with important data. An engineer deletes a directory by mistake, and separately the instance in us-east-1a must be replaced by one in us-east-1b. Does EBS replication help with the deletion? How do you get the data to the new instance in us-east-1b?
Show answer
Replication does not help with the deletion, because it copies every change, including the delete, and only guards against hardware failure. Recovery from the deletion needs an earlier snapshot. For the move, a volume cannot attach across Availability Zones. Create a snapshot of the volume, create a new volume from that snapshot with --availability-zone us-east-1b, and attach the new volume to the instance in us-east-1b.
Exercise
You terminate an instance and later see a charge for a 500 GiB volume you thought was gone. Which volume state would you expect to find with describe-volumes, and what should you do?
Show answer
The volume is most likely in the available state, meaning it exists but is attached to nothing. If you no longer need the data, take a snapshot if you might want it later, then delete the volume with aws ec2 delete-volume --volume-id <id> to stop the charge.