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:
- Launch an EC2 instance and look at its root volume
- Create a new 20 GiB EBS volume and attach it to the instance
- Format it, mount it, and make the mount survive reboots
- Write a file to it
- Detach it and attach it to a second instance, then read the same file there
- 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-1bcan't attach to an instance ineu-north-1a. - A volume normally attaches to one instance at a time. (Multi-Attach exists for
io1/io2volumes, 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.
Launch an instance. For this demo I used:
- AMI: Ubuntu 26.04
- Instance type:
t3.micro - Storage: the default 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.
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.
Step 2: Create a new EBS volume
Click Create volume and fill in:
- Volume type: General Purpose SSD (
gp2).gp3is also fine, and it's usually cheaper with better baseline performance. - Size:
20GiB - Availability Zone: the same AZ as your instance (
eu-north-1b) - Tag:
Name = ebsdemo, so it's easy to spot in the list
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.
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.
Pick your instance and a device name. I used /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.
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.
Two disks show up:
-
nvme0n1(8G) is the root volume. Its partitionnvme0n1p1is 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.
⚠️
mkfserases everything on the device. Double-check the device name, because formattingnvme0n1would destroy your OS. Only format a volume that is new or that you deliberately want to wipe.
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 Mount the volume on it:
sudo mount /dev/nvme1n1 /demoebs Run lsblk again. nvme1n1 now shows /demoebs as its mount point.
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.
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.
💡 Copy the UUID from the right line.
blkidlists every partition, including/boot(nvme0n1p13). If you copy the/bootUUID by mistake, fstab will point at the wrong disk. Make sure you take the UUID from the/dev/nvme1n1line.
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 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 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.
ls (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:
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.
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.
This time, choose the new instance:
The volume's Attached resources now shows 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> 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
mkfsagain. The volume already has a filesystem, and formatting it would wipe your data. Always check withfile -sbefore formatting.
Mount it and look inside:
sudo mkdir /demoebs2 sudo mount /dev/nvme1n1 /demoebs2 cd /demoebs2 ls cat tutorialfile.txt The output is:
This is a new file created on demoec2 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.
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."
After the instances terminate, check Volumes:
Both root volumes are gone, but ebsdemo is still there and Available. Each volume has a Delete on termination setting:
- Root volumes:
trueby default, so they're deleted along with the instance. - Volumes you attach yourself:
falseby 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.
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/sdfshows up as/dev/nvme1n1. Uselsblkto find the right disk. - Format a volume only once. Check with
file -sfirst, especially on a volume that already has data. - Use a UUID and
nofailin/etc/fstab. The UUID mounts the right disk, andnofaillets 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.





































