Amazon EBS Block Storage

Amazon EBS Block Storage

Watch the video to deepen your understanding.

Subscribe

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Amazon EBS Block Storage: A Comprehensive Guide

Introduction to Amazon Elastic Block Store (EBS)

When you launch a virtual machine in the cloud—what Amazon Web Services (AWS) calls an Elastic Compute Cloud (EC2) instance—you need a place to store your operating system, your application files, your databases, and your logs. In the world of physical servers, this would be your local hard drive or solid-state drive (SSD). In the cloud, this role is filled by Amazon Elastic Block Store, or EBS.

At its core, EBS provides block-level storage volumes for use with EC2 instances. Think of an EBS volume as a virtual hard drive that you can attach to your instance. Once attached, the instance sees it as a raw, unformatted block device. You can then format it with the file system of your choice (like ext4, XFS, or NTFS) and mount it to your directory structure.

Understanding EBS is critical because it is the primary storage mechanism for most persistent data in AWS. Unlike instance store volumes, which are physically attached to the host server and disappear if you stop your instance, EBS volumes are network-attached. This means they persist independently of the lifecycle of the instance. If your server crashes or you need to shut it down for maintenance, your data stays safely stored on the EBS volume, ready to be attached to a new or restarted instance. Mastering EBS is the difference between a system that loses data on every reboot and a production-grade application that safely stores user records, configurations, and state.


Not read yet

How EBS Works: The Architecture

EBS operates as a network-attached storage service. When you create an EBS volume, you specify its size and the type of performance you need. AWS then provisions that storage in a specific Availability Zone (AZ). Because the volume is tied to an AZ, it is highly available within that zone, as AWS automatically replicates the data across multiple physical hardware nodes to prevent data loss due to component failure.

The Lifecycle of an EBS Volume

  1. Creation: You define the volume size, type, and the AZ where it will live.
  2. Attachment: You link the volume to a running EC2 instance. The operating system detects a new block device (often appearing as /dev/xvdf or /dev/nvme1n1).
  3. Formatting/Mounting: You run commands to create a file system on the device and mount it to a directory.
  4. Usage: Your applications read and write data to the volume as if it were a local disk.
  5. Detachment/Deletion: You can unmount the volume, detach it from the instance, and either delete it or move it to a different instance.

Callout: EBS vs. Instance Store It is vital to distinguish between EBS and Instance Store. Instance Store provides temporary, ephemeral storage that is physically attached to the host computer. It offers very high performance because it is local, but if the instance stops, terminates, or the underlying hardware fails, all data on that drive is permanently lost. EBS, by contrast, is persistent. It is designed for data that must survive beyond the life of the instance, such as databases or persistent file systems.


Not read yet

EBS Volume Types: Choosing the Right Performance

One of the most common mistakes beginners make is choosing the wrong volume type. AWS offers several types of EBS volumes, each optimized for different workloads, performance patterns, and cost structures.

Solid State Drive (SSD) Volumes

These are designed for transactional workloads, such as databases, boot volumes, and high-performance applications where low latency is critical.

  • General Purpose SSD (gp3): This is the current default and recommended choice for most workloads. It provides a consistent baseline of performance and allows you to scale throughput and IOPS (Input/Output Operations Per Second) independently of the volume size.
  • General Purpose SSD (gp2): The older generation of gp3. It ties performance to volume size (the larger the disk, the faster it is), which can be limiting if you need high performance on a small disk.
  • Provisioned IOPS SSD (io1/io2): Designed for mission-critical, high-performance applications that require sustained IOPS or extremely low latency. You pay for the IOPS you provision, making these more expensive but highly predictable.

Hard Disk Drive (HDD) Volumes

These are designed for large, streaming workloads where throughput (the amount of data transferred per second) matters more than the number of individual operations (IOPS).

  • Throughput Optimized HDD (st1): Ideal for big data, log processing, and data warehousing. It is not suitable for boot volumes.
  • Cold HDD (sc1): The lowest-cost storage for infrequent access. It is designed for large volumes of data that you don’t need to access often, such as cold backups or archival data.
Volume Type Workload Type Max IOPS Best For
gp3 General Purpose 16,000 Boot volumes, small/medium DBs
io2 High Performance 64,000 Large, mission-critical databases
st1 Throughput 500 Streaming, logs, big data
sc1 Throughput 250 Infrequent access, archives

Note: Always start with gp3 unless you have a specific requirement for high IOPS (io2) or large-scale streaming (st1/sc1). Over-provisioning storage types is a frequent source of unnecessary costs in cloud billing.


Not read yet

Setting Up an EBS Volume: Step-by-Step

Let's walk through the process of creating and attaching an EBS volume to an EC2 instance. This example assumes you are using a Linux-based instance.

Step 1: Create the Volume

  1. Log into the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. Under Elastic Block Store, select Volumes.
  4. Click Create Volume.
  5. Select the volume type (e.g., gp3) and size.
  6. Crucial: Ensure the Availability Zone matches the AZ of the instance you intend to attach it to. You cannot attach a volume in us-east-1a to an instance in us-east-1b.

Step 2: Attach the Volume

  1. Once created, select the volume in the console.
  2. Click Actions > Attach Volume.
  3. Choose your instance from the list and specify the device name (e.g., /dev/sdf).

Step 3: Format and Mount (Inside the Instance)

Once attached, you must log into your instance via SSH to make the disk usable.

# 1. Check if the device is visible to the OS
lsblk

# 2. Check if the volume has a file system
sudo file -s /dev/nvme1n1

# If the output shows "data", it's empty and needs a file system.
# 3. Create an XFS file system (or ext4)
sudo mkfs -t xfs /dev/nvme1n1

# 4. Create a mount point
sudo mkdir /data

# 5. Mount the volume
sudo mount /dev/nvme1n1 /data

Tip: If you want the volume to mount automatically after a system reboot, you must add an entry to the /etc/fstab file. Always use the UUID of the device rather than the device name (like /dev/nvme1n1), as device names can change between reboots.


Not read yet

Best Practices for EBS Management

Managing storage at scale requires a disciplined approach. Follow these industry standards to ensure your data is safe and your costs remain predictable.

1. Implement Automated Backups (Snapshots)

EBS snapshots are incremental backups. When you take a snapshot, only the blocks that have changed since your last snapshot are saved to Amazon S3. This makes snapshots very efficient and cost-effective. Use Amazon Data Lifecycle Manager (DLM) to automate the creation, retention, and deletion of these snapshots based on a policy.

2. Monitor Performance with CloudWatch

Use Amazon CloudWatch to monitor your EBS metrics. Specifically, watch for VolumeQueueLength (how many requests are waiting) and VolumeIdleTime. If your queue length is consistently high, your volume is likely struggling to keep up with the application's demand, and you should consider upgrading your volume type or increasing provisioned IOPS.

3. Encryption by Default

AWS allows you to enable encryption for all new EBS volumes by default in your account settings. This is a security best practice. Encrypted volumes use AWS Key Management Service (KMS) to protect your data at rest. There is virtually no performance penalty for enabling this, and it is a requirement for most compliance frameworks (like HIPAA or PCI-DSS).

4. Right-Sizing

Don't provision a 1TB volume if your application only uses 50GB. Because EBS allows you to modify volume size and type on the fly—without detaching the volume or stopping the instance—you can start small and scale up as your data grows. This prevents "storage sprawl" and keeps costs down.

Warning: While you can increase the size of an EBS volume at any time, you cannot decrease it. Always start with a conservative estimate and increase the size as necessary.


Not read yet

Common Pitfalls and How to Avoid Them

Even experienced engineers run into issues with EBS. Being aware of these pitfalls can save you hours of troubleshooting.

The "AZ Mismatch" Error

As mentioned earlier, EBS volumes are zonal resources. If you have an instance in us-east-1a, it cannot access a volume in us-east-1b.

  • The Fix: If you created the volume in the wrong zone, you must create a snapshot of that volume, copy the snapshot to the correct zone, and then create a new volume from that snapshot in the correct zone.

File System Corruption

If you detach a volume while an application is still writing to it, or if you don't unmount the file system properly (umount), you risk file system corruption.

  • The Fix: Always stop the service using the disk, then run sudo umount /data before detaching the volume in the AWS console.

IOPS Bottlenecks

Sometimes, even if you pay for a high-performance volume, you won't see the expected results. This usually happens because the EC2 instance type itself has a limit on how much throughput it can handle.

  • The Fix: Check the "EBS-Optimized" throughput limit of your EC2 instance type. If your instance is too small (e.g., a t3.micro), it will throttle your storage performance regardless of the EBS volume type you choose.

Not read yet

Advanced Topic: Modifying Volumes on the Fly

One of the most powerful features of EBS is the ability to change the volume type or size without downtime. Suppose you have a database running on a gp2 volume, and you notice your IOPS are hitting the limit.

How to Upgrade without Downtime:

  1. Go to the AWS Console, find the volume, and select Modify Volume.
  2. Change the volume type to gp3 or increase the IOPS/Throughput.
  3. Once the modification completes, you may need to resize the file system inside the OS to recognize the new capacity.
    # For XFS file systems:
    sudo xfs_growfs -d /data
    
    # For ext4 file systems:
    sudo resize2fs /dev/nvme1n1
    

This capability allows you to respond to traffic spikes in real-time, ensuring your applications remain responsive without needing to perform risky migrations or maintenance windows.


Comparison: EBS vs. Other AWS Storage Services

It is important to understand where EBS fits into the broader AWS storage landscape.

  • EBS (Block Storage): Best for single-instance, high-performance needs like databases or boot drives. It is not designed to be shared by multiple instances simultaneously (with the exception of Multi-Attach for specific provisioned IOPS volumes).
  • Amazon EFS (File Storage): A managed network file system that can be mounted by hundreds of instances at the same time. It is great for shared web servers or content management systems but has higher latency than EBS.
  • Amazon S3 (Object Storage): Designed for storing massive amounts of unstructured data (images, backups, logs). It is not a block device and cannot be mounted as a file system to an OS; you interact with it via APIs or the AWS CLI.
Feature EBS EFS S3
Type Block File Object
Access One Instance Multiple Instances API / HTTP
Performance Very High Medium High (throughput)
Use Case DBs, OS, Apps Shared Files Backups, Data Lake

Not read yet

Troubleshooting Connectivity

Sometimes an instance "loses" a drive. If you run lsblk and the device is missing, follow this checklist:

  1. Check the Attachment State: Go to the AWS Console and confirm the volume is in the "in-use" state and attached to the correct instance ID.
  2. Check for NVMe vs. Xen Drivers: Modern instances (Nitro-based) use NVMe drivers, and devices appear as /dev/nvmeXn1. Older instances use Xen drivers, appearing as /dev/xvdf. If your script expects /dev/sdf but the system mapped it to /dev/nvme1n1, your mount commands will fail.
  3. Check Instance Health: If the instance is in a "degraded" state, it may be unable to communicate with the EBS service.
  4. Permissions: Ensure the IAM role assigned to the instance has the necessary permissions to describe and attach volumes if you are using automated scripts to manage them.

Callout: EBS Multi-Attach Normally, an EBS volume can only be attached to one EC2 instance at a time to prevent data corruption. However, for specific use cases like clustered applications (where the application handles its own data consistency), you can use "EBS Multi-Attach." This allows a single io1 or io2 volume to be attached to multiple instances in the same Availability Zone. This is an advanced feature and should only be used if your application is explicitly designed to handle concurrent writes.


Not read yet

Security Considerations

Securing your EBS volumes is not just about encryption. It involves a holistic approach to data protection.

  • Identity and Access Management (IAM): Restrict who can create, attach, or delete volumes. Use the principle of least privilege. A developer might need to see volumes, but they may not need the permission to delete them.
  • Snapshot Permissions: By default, snapshots are private. Be very careful if you ever modify snapshot permissions to be "public," as this will expose your data to everyone on the internet.
  • Data Lifecycle Management: As mentioned, use DLM to enforce backup policies. A backup strategy is the ultimate security measure against accidental deletion or ransomware.
  • Volume Tagging: Use tags to identify the environment (e.g., Environment: Production, Project: Finance). This helps in automating security audits and cost allocation reports.

Practical Exercise: Simulating a Disaster Recovery Scenario

To truly master EBS, you should practice recovery. Try this exercise in a non-production environment:

  1. Create a volume and attach it to an instance.
  2. Create a file inside the volume (e.g., echo "secret data" > /data/test.txt).
  3. Take a snapshot of the volume.
  4. Delete the original volume (simulating a catastrophic failure).
  5. Create a new volume from the snapshot you just took.
  6. Attach it to a new instance and verify that test.txt is still there.

If you can successfully complete this, you have mastered the fundamental workflow of cloud data persistence.


Not read yet

Summary of Key Takeaways

  1. Persistence is Key: EBS provides block-level storage that survives the lifecycle of an EC2 instance, making it the standard choice for databases and OS boot volumes.
  2. Choose the Right Type: Use gp3 for 90% of your workloads. Reserve io2 for high-performance databases and st1/sc1 for large-scale streaming or cold storage.
  3. Snapshots are Incremental: Utilize snapshots for backups. Because they are incremental, they are fast and storage-efficient. Automate them using Data Lifecycle Manager.
  4. Encryption is Mandatory: Enable encryption at rest by default for all volumes in your account to ensure compliance and baseline security.
  5. Right-Sizing Saves Money: Start small and grow as needed. You can increase size and modify performance on the fly without downtime, so there is no need to over-provision from day one.
  6. Mind the Availability Zone: EBS volumes are local to their Availability Zone. You cannot attach a volume across different zones; if you need to move data, you must use snapshots to transfer it.
  7. Monitor the Queue: Use CloudWatch to track performance. If your application feels slow, check the VolumeQueueLength to see if your EBS volume is becoming a bottleneck.

By applying these principles, you ensure that your cloud infrastructure is not only performant but also resilient and cost-effective. EBS is a foundational service; once you understand how to manage it, you have unlocked the ability to build reliable, scalable applications that can withstand the rigors of production environments.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.