Automatically mount an EBS volume upon starting an Amazon EC2 Linux instance
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Attaching an EBS volume to an EC2 instance is only half the job. If you want the volume available after every reboot, the instance also needs a stable mount configuration. On Linux, that usually means identifying the filesystem by UUID and adding a carefully chosen entry to /etc/fstab.
Identify the Correct Device and Filesystem
After attaching the volume in AWS, connect to the instance and inspect the block devices:
lsblk shows which device appeared, and blkid shows the filesystem UUID. The UUID is more stable than a raw device path such as /dev/xvdf, which may not always map the same way across boots or Nitro-based naming conventions.
If the volume is new and has no filesystem yet, create one first:
Only do this on a brand-new empty volume, because formatting destroys existing data.
Create a Mount Point and Test a Manual Mount
Before editing /etc/fstab, create the target directory and make sure the mount works manually:
If the manual mount fails, fix that problem first. fstab should automate a known-good mount, not debug a broken one.
Add the Volume to /etc/fstab
Use the UUID from blkid rather than the raw device path:
Example output:
Then add an /etc/fstab entry:
Important parts:
- '
UUID=...identifies the volume' - '
/datais the mount point' - '
ext4is the filesystem type' - '
nofailprevents boot from failing hard if the volume is unavailable'
The nofail option is especially useful on cloud instances where attachment timing or operational mistakes could otherwise block boot.
Validate Before Rebooting
Never edit /etc/fstab and reboot immediately without testing:
mount -a tells Linux to mount everything from fstab that is not already mounted. If that succeeds, your configuration is much safer to trust on the next reboot.
This step is critical because a bad fstab entry can leave a system unbootable or stuck in recovery mode.
On systems that use systemd extensively, you can also inspect boot-time mount failures later with journalctl -b if the volume still does not come up as expected after reboot successfully.
Think About Ownership and Application Access
Mounting the volume is not the whole operational picture. The application also needs correct permissions:
Use the right owner and group for your workload, whether that is ec2-user, nginx, postgres, or another service account.
If the volume stores application data, document the mount in provisioning scripts or infrastructure code so future instances are configured consistently.
Common Pitfalls
- Using a raw device path instead of a UUID in
/etc/fstab. - Forgetting to test the mount manually before automating it.
- Formatting a volume that already contains data.
- Rebooting after editing
/etc/fstabwithout first runningmount -a. - Ignoring ownership and permissions after the mount succeeds.
Summary
- Automatic EBS mounting on EC2 is usually implemented through
/etc/fstab. - Use
lsblkandblkidto identify the device and its filesystem UUID. - Prefer UUID-based mounts over raw device names.
- Include
nofailwhen appropriate so boot is more resilient. - Test with
mount -abefore rebooting the instance.

