AWS
EBS
Ubuntu
EC2
Cloud Computing

Add EBS to Ubuntu EC2 Instance

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Adding an EBS volume to an Ubuntu EC2 instance is a two-part job: attach the block device in AWS, then prepare and mount it inside Linux. The important detail is to check whether the volume is brand new or already contains data, because a new volume needs formatting while an existing one usually must not be reformatted.

Create and Attach the Volume

In the AWS console, create the EBS volume in the same Availability Zone as the EC2 instance. Then attach it to the instance. You can do the attachment from the console or the CLI, but the Linux-side steps are the same afterward.

Once attached, connect to the instance:

bash
ssh -i /path/to/key.pem ubuntu@your-instance-hostname

Find the Device

On Ubuntu, list block devices:

bash
lsblk

You may see a name such as /dev/nvme1n1 or /dev/xvdf depending on the instance family. Confirm the new device size so you do not accidentally work on the root disk.

For more detail:

bash
sudo fdisk -l

Format Only If Needed

If the volume is new and empty, create a filesystem:

bash
sudo mkfs.ext4 /dev/nvme1n1

If the volume already contains data, stop here and mount it directly instead. Running mkfs on an existing data volume destroys the previous filesystem.

Mount the Volume

Create a mount point and mount the volume:

bash
sudo mkdir -p /mnt/data
sudo mount /dev/nvme1n1 /mnt/data
df -h

At this point the disk is usable, but the mount is temporary. A reboot will remove it unless you add a persistent entry.

Persist the Mount with UUID

Use the filesystem UUID rather than the device name, because Linux device names may vary across reboots:

bash
sudo blkid /dev/nvme1n1

Then add an /etc/fstab entry:

bash
sudo nano /etc/fstab

Example line:

text
UUID=your-uuid-here /mnt/data ext4 defaults,nofail 0 2

Test the file before rebooting:

bash
sudo mount -a

If that command returns cleanly, the mount configuration is probably valid.

Resizing and Existing Filesystems

If you later expand the EBS volume size in AWS, you may need to grow the partition or filesystem inside Ubuntu as well. That is a separate step from the initial attachment. The exact command depends on whether the filesystem is ext4, xfs, or part of LVM.

This is a common source of confusion: increasing the EBS volume in AWS does not automatically enlarge the mounted filesystem in the guest OS.

Snapshot-based workflows add another twist. If the volume was created from a snapshot, it may already contain a filesystem and data, so the right first step is inspection with lsblk, blkid, and mount, not immediate formatting.

That one check prevents one of the easiest accidental data-loss mistakes in EC2 storage work.

It is worth slowing down for.

Especially in production.

Common Pitfalls

  • Creating the volume in a different Availability Zone from the instance.
  • Formatting a volume that already contains data.
  • Using the wrong block device and touching the root disk by mistake.
  • Adding /dev/xvdf to fstab instead of the UUID.
  • Forgetting mount -a testing before rebooting.

Summary

  • Create the EBS volume in the same Availability Zone as the EC2 instance.
  • Attach it, SSH into Ubuntu, and identify the new block device carefully.
  • Format the device only if it is new and empty.
  • Mount it and verify with df -h.
  • Use the filesystem UUID in /etc/fstab for persistent mounting.

Course illustration
Course illustration

All Rights Reserved.