Attaching Amazon EBS Volumes to EC2 Instances: A Step-by-Step Guide

saumya singhsaumya singh
3 min read

When working with Amazon EC2 instances, storage requirements often grow with time. While your instance comes with root storage by default, you can easily add more storage by attaching Amazon Elastic Block Store (EBS) volumes. EBS provides persistent, block-level storage that can be attached to EC2 instances and is ideal for applications requiring fast and consistent storage.

In this article, we’ll walk through:

  • What Amazon EBS is

  • Why you need additional EBS volumes

  • Step-by-step guide to attaching an EBS volume to an EC2 instance


🔹 What is Amazon EBS?

Amazon Elastic Block Store (EBS) is a scalable block storage service that works with Amazon EC2. Unlike instance store volumes, EBS is persistent—your data remains intact even if you stop or terminate the instance (as long as you keep the volume).

EBS is commonly used for:

  • Hosting databases

  • Storing application files

  • Backups and snapshots

  • Extending root volume storage


🔹 Why Attach an EBS Volume to EC2?

Sometimes the root storage that comes with your instance isn’t enough. By attaching a separate EBS volume, you can:

  • Add additional space for logs, databases, or applications

  • Isolate workloads into different storage devices

  • Scale storage independently from compute power


🔹 Step-by-Step: Attaching an EBS Volume to EC2

1. Create an EBS Volume

  1. Go to the AWS Management ConsoleEC2Volumes.

  2. Click Create Volume.

  3. Choose:

    • Volume Type (gp3 is common for general-purpose workloads).

    • Size (e.g., 10 GiB).

    • Availability Zone (AZ) → must match the AZ of your EC2 instance.

  4. Click Create Volume.


2. Attach the Volume to an EC2 Instance

  1. Select the newly created volume.

  2. Click Actions → Attach Volume.

  3. Choose the Instance ID of your EC2 instance.

  4. Assign a device name (e.g., /dev/sdf).

  5. Click Attach.


3. Connect to the Instance and Format the Volume

  1. SSH into your EC2 instance:

     ssh -i your-key.pem ec2-user@<public-ip>
    
  2. List available disks:

     lsblk
    

    You should see your new volume (e.g., /dev/xvdf).

  3. Format the volume with a filesystem:

     sudo mkfs -t xfs /dev/xvdf
    

4. Mount the Volume

  1. Create a directory to mount it:

     sudo mkdir /data
    
  2. Mount the volume:

     sudo mount /dev/xvdf /data
    
  3. Verify the mount:

     df -h
    

5. Make the Mount Persistent

If you want the volume to be mounted automatically after reboot:

  1. Get the UUID of the volume:

     sudo blkid /dev/xvdf
    
  2. Edit the /etc/fstab file and add an entry like this:

     UUID=<your-uuid>   /data   xfs   defaults,nofail   0   2
    

📊 Diagram: EBS Volume Attachment

+-------------------+           +------------------+
|   EC2 Instance    |           |    EBS Volume    |
| (Compute & OS)    | <-------> | (Persistent Disk) |
+-------------------+           +------------------+

✅ Conclusion

Attaching an EBS volume to an EC2 instance is one of the most practical ways to scale your storage without disrupting your compute resources. With just a few clicks and commands, you can create, attach, format, and persist additional storage for your workloads.

By mastering this process, you’ll be well-prepared to handle real-world AWS storage needs such as database hosting, log storage, and scalable application environments.


10
Subscribe to my newsletter

Read articles from saumya singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

saumya singh
saumya singh

Welcome to my corner of the cloud, where ideas scale faster than servers and downtime is not an option! Here, I write about everything from spinning up VPCs to tearing down myths about the cloud. Whether you’re an engineer, a curious learner, or someone who just likes seeing words like 'serverless' and 'auto-scaling,' you’re in the right place. Consider this blog your high-availability zone for tips, tutorials, and tech thoughts—delivered with 99.99% uptime .