Introduction

When you launch an EC2 instance, it feels like the server and its disk are one thing. They aren't. The disk is a separate resource called an Amazon EBS volume (Elastic Block Store), and it can live on after the server is gone. You can also unplug it from one server and plug it into another, and your data comes along.

In this walkthrough, you'll:

  1. Launch an EC2 instance and look at its root volume
  2. Create a new 20 GiB EBS volume and attach it to the instance
  3. Format it, mount it, and make the mount survive reboots
  4. Write a file to it
  5. Detach it and attach it to a second instance, then read the same file there
  6. Terminate both instances and see which volumes survive, then clean up

By the end, you'll understand what EBS is and how it behaves.

What is Amazon EBS?

EBS is block storage for EC2. To the operating system, an EBS volume looks like a physical hard drive: you partition it, format it with a filesystem, and mount it. Under the hood, it's storage that AWS provides over its network.

A few things to know before you start:

  • A volume lives in one Availability Zone (AZ). You can only attach a volume to an instance in the same AZ. A volume in eu-north-1b can't attach to an instance in eu-north-1a.
  • A volume normally attaches to one instance at a time. (Multi-Attach exists for io1/io2 volumes, but that's a special case.)
  • Volumes exist independently of instances. Stopping an instance doesn't delete its volumes. By default, terminating one deletes only the root volume. Extra volumes you attach yourself are kept.
  • Every instance has a root volume. That's where the OS is installed. Any other volume you add is a data volume.

Step 1: Launch an EC2 instance

Open the AWS console and search for EC2.

Searching for EC2 in the AWS console

Launch an instance. For this demo I used:

  • AMI: Ubuntu 26.04
  • Instance type: t3.micro
  • Storage: the default 8 GiB gp3 root volume

Configure storage: the 8 GiB gp3 root volume

The Configure storage section is your first look at EBS. That 8 GiB volume is the instance's root volume, where Ubuntu gets installed.

Once it launches, note the Availability Zone. Mine is eu-north-1b, and every volume you attach to this instance has to be created in that AZ.

The demoec2 instance running in eu-north-1b

Now go to Elastic Block Store → Volumes. There's already one volume there, even though you didn't create one. It's the root volume that came with the instance.

The Volumes list showing only the 8 GiB root volume

Step 2: Create a new EBS volume

Click Create volume and fill in:

  • Volume type: General Purpose SSD (gp2). gp3 is also fine, and it's usually cheaper with better baseline performance.
  • Size: 20 GiB
  • Availability Zone: the same AZ as your instance (eu-north-1b)
  • Tag: Name = ebsdemo, so it's easy to spot in the list

Creating a 20 GiB gp2 volume in eu-north-1b

The IOPS line under the size is worth a look: 100 / 3000. A gp2 volume gets 3 IOPS per GiB, with a minimum of 100, and can burst up to 3,000. A gp3 volume gets 3,000 IOPS whatever its size.

Click Create volume. It shows as Creating for a few seconds, then becomes Available.

The new ebsdemo volume being created

Two volumes now: the root volume and ebsdemo

Step 3: Attach the volume to the instance

Open the ebsdemo volume. Its state is Available, which means it exists but isn't attached to anything. Choose Actions → Attach volume.

Volume details, with Actions → Attach volume

Pick your instance and a device name. I used /dev/sdf.

Attaching ebsdemo to demoec2 as /dev/sdf

The instance dropdown says "Only instances in the same Availability Zone as the selected volume are displayed." This is the AZ rule in action.

Also note the blue banner: newer Linux kernels may rename the device. You'll see what that means in a moment.

The volume attached successfully

Step 4: Find the volume inside the instance

SSH into the instance and list the block devices:

lsblk 

lsblk lists every disk and partition the OS can see, plus where each is mounted.

lsblk showing nvme0n1 (root) and nvme1n1 (the new volume)

Two disks show up:

  • nvme0n1 (8G) is the root volume. Its partition nvme0n1p1 is mounted at /.
  • nvme1n1 (20G) is the new volume. It has no partitions and no mount point yet.

Where's /dev/sdf? On modern (Nitro-based) instance types, EBS volumes appear to Linux as NVMe devices. The name you picked in the console (/dev/sdf) is a label on the AWS side. Linux numbers the disks itself, so /dev/sdf becomes /dev/nvme1n1. If you're ever unsure which disk is which, this command shows each disk's EBS volume ID in the SERIAL column:

lsblk -o NAME,SIZE,SERIAL 

Next, check whether the volume has a filesystem:

sudo file -s /dev/nvme1n1 

file -s reads the start of the device and reports what's on it. Here the output is data, which means the volume is raw and unformatted.

Step 5: Format the volume

Create an ext4 filesystem on it:

sudo mkfs -t ext4 /dev/nvme1n1 

mkfs ("make filesystem") formats the device, and -t ext4 picks the filesystem type.

⚠️ mkfs erases everything on the device. Double-check the device name, because formatting nvme0n1 would destroy your OS. Only format a volume that is new or that you deliberately want to wipe.

Formatting the volume with mkfs -t ext4

Run file -s again. The output now reports an ext4 filesystem with a UUID, a unique ID for this filesystem. You'll need that UUID shortly.

Step 6: Mount the volume

A filesystem has to be mounted on a folder (the "mount point") before you can use it. Create one:

sudo mkdir /demoebs 

Creating the /demoebs mount point

Mount the volume on it:

sudo mount /dev/nvme1n1 /demoebs 

Run lsblk again. nvme1n1 now shows /demoebs as its mount point.

nvme1n1 now mounted at /demoebs

Check the space available:

df -h 

df -h shows disk usage for each mounted filesystem in human-readable sizes. The last line shows /dev/nvme1n1: 20G, mounted on /demoebs.

df -h showing the 20G volume on /demoebs

Step 7: Make the mount permanent with /etc/fstab

A mount made with the mount command disappears when the instance reboots. To mount the volume automatically at boot, add it to /etc/fstab.

First, get the volume's UUID:

sudo blkid 

blkid lists every filesystem with its UUID and type.

blkid output; the last line is /dev/nvme1n1

💡 Copy the UUID from the right line. blkid lists every partition, including /boot (nvme0n1p13). If you copy the /boot UUID by mistake, fstab will point at the wrong disk. Make sure you take the UUID from the /dev/nvme1n1 line.

Edit the file:

sudo vi /etc/fstab 

Add this line at the bottom, using your own UUID:

UUID=a22d8831-2a0e-474f-acd3-3bdb7f5e5d92 /demoebs ext4 defaults,nofail 0 2 

The finished /etc/fstab with the new entry

Here's what each field means:

Field Meaning
UUID=... Which filesystem to mount. A UUID is safer than /dev/nvme1n1 because device names can change between boots.
/demoebs Where to mount it
ext4 The filesystem type
defaults,nofail Standard mount options. nofail lets the instance still boot if the volume is missing, which matters here because you're about to detach this volume.
0 Don't back it up with dump
2 Check the filesystem at boot, after the root disk

Without nofail, an instance whose fstab lists a missing volume can hang at boot. nofail is a small option, but it prevents that.

Confirm the UUID in fstab matches the volume:

sudo blkid /dev/nvme1n1 

Confirming the UUID with blkid

Step 8: Write some data

Create a file on the volume:

cd /demoebs sudo vi tutorialfile.txt 

Press i to start typing and add a line of text. Then press Esc and type :wq to save and quit.

The contents of tutorialfile.txt

ls 

tutorialfile.txt on the volume, next to lost+found

(lost+found is created automatically by ext4. It's where the filesystem puts recovered fragments after a disk check.)

This file is the proof for the next part: we'll move the disk to a different server and check whether the file is still there.

Step 9: Detach the volume from the first instance

Before detaching a volume, make sure nothing is writing to it, so no data is lost. You can either unmount it (sudo umount /demoebs) or stop the instance. I stopped the instance:

Instance state → Stop instance

demoec2 stopped

When the instance stopped, its public IPv4 address disappeared. A stopped instance gives up its public IP and gets a new one when it starts. If you need an address that never changes, use an Elastic IP.

Back in Volumes, select ebsdemo and choose Actions → Detach volume. Use the normal Detach. Force detach is a last resort for a stuck volume, because it can corrupt data.

Actions → Detach volume

Volume detached successfully

The volume goes back to Available. It's no longer attached to any server, but the data is still on it.

Step 10: Attach it to a second instance

Launch a second instance, demoec2-2, in the same AZ (eu-north-1b). Then select ebsdemo and choose Actions → Attach volume again.

The volume is Available again; Actions → Attach volume

This time, choose the new instance:

Attaching ebsdemo to demoec2-2

The volume's Attached resources now shows demoec2-2:

ebsdemo in-use and attached to demoec2-2

SSH into the second instance. If it uses a different key pair, point ssh -i at that key. The first attempt in the screenshot fails with Permission denied (publickey) because the .pem file wasn't in the folder the command pointed to. Once the key was moved there, the login worked.

ssh -i $HOME\.ssh\demo2.pem ubuntu@<public-ip> 

Connecting to demoec2-2 over SSH

Step 11: Read the data on the new instance

List the disks:

lsblk 

nvme1n1 (20G) is there, unmounted. Before doing anything else, check what's on it:

sudo file -s /dev/nvme1n1 

It reports an ext4 filesystem with the same UUID as before (a22d8831-...). The filesystem moved with the volume.

⚠️ Do not run mkfs again. The volume already has a filesystem, and formatting it would wipe your data. Always check with file -s before formatting.

Mount it and look inside:

sudo mkdir /demoebs2 sudo mount /dev/nvme1n1 /demoebs2 cd /demoebs2 ls cat tutorialfile.txt 

The file created on demoec2, read on demoec2-2

The output is:

This is a new file created on demoec2 

output showing the file created earlier

The file you wrote on the first server can be read on the second. The data belongs to the volume, not to the instance. That's the main idea of EBS: storage and compute are separate, so you can replace a server and keep its data.

Step 12: Terminate the instances and see what survives

Select both instances and choose Instance state → Terminate (delete) instance.

Terminating both instances

Read the warning in the dialog:

"On an EBS-backed instance, the default action is for the root EBS volume to be deleted when the instance is terminated."

The terminate dialog's warning about root volumes

After the instances terminate, check Volumes:

Only ebsdemo remains; both root volumes are gone

Both root volumes are gone, but ebsdemo is still there and Available. Each volume has a Delete on termination setting:

  • Root volumes: true by default, so they're deleted along with the instance.
  • Volumes you attach yourself: false by default, so they're kept.

This protects your data, but it also means leftover volumes keep costing money. AWS charges for a volume whether or not it's attached to anything.

Step 13: Clean up

Delete the volume: select it, choose Actions → Delete volume, then type delete to confirm.

Confirming the deletion

No volumes left in the region

Deleting a volume is permanent. If you might need the data later, choose Actions → Create snapshot first. A snapshot is a backup of the volume stored in S3, and you can create a new volume from it at any time.

Command cheat sheet

Command What it does
lsblk List disks, partitions and mount points
lsblk -o NAME,SIZE,SERIAL Match Linux device names to EBS volume IDs
sudo file -s /dev/nvme1n1 Check whether a device has a filesystem
sudo mkfs -t ext4 /dev/nvme1n1 Format a device as ext4 (erases it)
sudo mkdir /demoebs Create a mount point
sudo mount /dev/nvme1n1 /demoebs Mount the volume
df -h Show disk space for mounted filesystems
sudo blkid Show filesystem UUIDs
sudo vi /etc/fstab Edit the auto-mount configuration
sudo umount /demoebs Unmount before detaching

Summary

  • EBS volumes are separate from instances. You can create, attach, detach and reattach them on their own.
  • A volume and its instance must be in the same AZ.
  • On Nitro instances, /dev/sdf shows up as /dev/nvme1n1. Use lsblk to find the right disk.
  • Format a volume only once. Check with file -s first, especially on a volume that already has data.
  • Use a UUID and nofail in /etc/fstab. The UUID mounts the right disk, and nofail lets the instance boot without the volume.
  • Terminating an instance deletes the root volume but not extra volumes (by default). Clean up leftover volumes, or snapshot them first if you want to keep the data.

Once you understand that storage and compute are separate, the rest of EBS is easier to learn: snapshots, backups, resizing volumes, and recovering a broken server by moving its disk to a healthy one.