To make an extra Amazon EBS volume mount automatically after an EC2 Linux instance reboots, add an entry for it to /etc/fstab. Refer to the volume by its filesystem UUID and include the nofail option. The steps above show the basic idea. This guide adds the missing steps (attaching, formatting, finding the UUID), corrects the device-name example, and explains how to test the entry so a mistake can't stop the instance from booting.
By default on every reboot, the EBS volumes other than root volume will get unmounted. To enable automount, you need to make an entry in the /etc/fstab file.
Follow the steps given below to automount the EBS volume to ec2 instance.
Step 1: Back up the /etc/fstab file.
sudo cp /etc/fstab /etc/fstab.bak
Step 2: Open /etc/fstab file and make an entry in the following format.
device_name mount_point file_system_type fs_mntops fs_freq fs_passno
For example,
/dev/xvdf /newvolume ext4 defaults,nofail 0 0
Step 3: Execute the following command to check id the fstab file has any error.
sudo mount -a
If the above command shows no error, it means your fstab entry is good.
Now, on every reboot, the extra EBS volumes will get mounted automatically.
Why the volume is not mounted after a reboot
EBS volumes do not unmount themselves. A volume mounted by hand with the mount command exists only in the running kernel, so the mount is gone after a restart. The volume is still attached and its data is untouched. At boot, systemd reads /etc/fstab and mounts every filesystem listed there. A volume that isn't in that file stays attached but unmounted.
Each line in /etc/fstab has six fields:
| Field | Example | Meaning |
|---|---|---|
| Device | UUID=1b2c... | Which filesystem to mount. A UUID is safer than a /dev name. |
| Mount point | /data | An existing, empty directory |
| Type | xfs or ext4 | Filesystem type created with mkfs |
| Options | defaults,nofail | Mount options. nofail lets the boot continue if the volume is missing. |
| Dump | 0 | Used by the old dump backup tool. Almost always 0. |
| Pass | 2 | fsck order at boot: 0 = never check, 1 = root, 2 = other filesystems |
Prerequisites
- A running EC2 Linux instance (Amazon Linux 2023, Amazon Linux 2, Ubuntu, RHEL and similar) and SSH access to it. On Windows, see How to Login to Linux Server using Putty?.
- An EBS volume in the same Availability Zone as the instance, attached through the console or with
aws ec2 attach-volume --volume-id vol-0123456789abcdef0 --instance-id i-0123456789abcdef0 --device /dev/sdf. - sudo privileges on the instance.
Note: The device name you choose in the console (for example /dev/sdf) is often not the name Linux uses. On Nitro-based instances, EBS volumes appear as NVMe devices such as /dev/nvme1n1. On older Xen instances they usually appear as /dev/xvdf. Always check with lsblk.
Complete procedure
First, find the new volume. It's the disk that has no mount point:
lsblk -f
# Example output on a Nitro instance
NAME FSTYPE LABEL UUID MOUNTPOINTS
nvme0n1
โโnvme0n1p1 xfs / 2a1f... /
โโnvme0n1p128 vfat 7B77-95E7 /boot/efi
nvme1n1Code language: PHP (php)
Check whether the volume already contains a filesystem. If the output is just data, the volume is empty. If it shows a filesystem (for example a volume restored from a snapshot), skip the mkfs step, because formatting erases everything on the volume.
sudo file -s /dev/nvme1n1
# /dev/nvme1n1: data <- empty, safe to format
# Create a filesystem (xfs is the default on Amazon Linux and RHEL)
sudo mkfs -t xfs /dev/nvme1n1
# or: sudo mkfs -t ext4 /dev/nvme1n1Code language: PHP (php)
Create the mount point, mount the volume once, and read its UUID:
sudo mkdir -p /data
sudo mount /dev/nvme1n1 /data
sudo blkid /dev/nvme1n1
# /dev/nvme1n1: UUID="1b2c3d4e-5f60-4a7b-8c9d-0e1f2a3b4c5d" BLOCK_SIZE="512" TYPE="xfs"Code language: PHP (php)
Back up /etc/fstab as shown above, then add the entry. Using tee -a appends the line and avoids the common mistake of overwriting the file with >:
sudo cp /etc/fstab /etc/fstab.bak
echo 'UUID=1b2c3d4e-5f60-4a7b-8c9d-0e1f2a3b4c5d /data xfs defaults,nofail 0 2' | sudo tee -a /etc/fstabCode language: PHP (php)
Test the fstab entry properly before rebooting
sudo mount -a on its own doesn't prove anything if the volume is already mounted, because it skips filesystems that are already mounted. Unmount the volume first so that mount -a actually tests the new line:
- Unmount the volume:
sudo umount /data - Tell systemd to reread fstab:
sudo systemctl daemon-reload. Without this, newermountversions warn that systemd still uses the old version of the file. - Check the syntax and the devices:
sudo findmnt --verify. It reports unknown UUIDs, missing mount points and bad filesystem types. - Mount everything from fstab:
sudo mount -a. No output means success. - Confirm the mount:
df -hT /data - Reboot (
sudo reboot), reconnect and rundf -hT /dataagain.
df -hT /data
# Filesystem Type Size Used Avail Use% Mounted on
# /dev/nvme1n1 xfs 20G 175M 20G 1% /dataCode language: PHP (php)
Corrections to the original steps
The example above uses /dev/xvdf as the device. That name only exists on older Xen-based instance types. On Nitro instances the volume is /dev/nvme1n1 or similar, and NVMe names are assigned in the order devices are detected, so they can change between boots or when volumes are added. An fstab line that points at the wrong name will either fail or mount the wrong disk. Use the UUID instead:
# Original (fragile)
/dev/xvdf /newvolume ext4 defaults,nofail 0 0
# Corrected (stable across reboots and instance types)
UUID=1b2c3d4e-5f60-4a7b-8c9d-0e1f2a3b4c5d /newvolume ext4 defaults,nofail 0 2Code language: PHP (php)
Setting the last field to 2 lets ext4 volumes get a filesystem check at boot, after the root filesystem. For xfs the check does nothing, so 0 and 2 behave the same. The original also leaves out the steps that make the entry work: formatting the volume, creating the mount point directory and finding the UUID. These are covered in the procedure section.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Instance doesn't come back after reboot, or the console log shows emergency mode | Bad fstab line without nofail, or a typo in the UUID | Use the EC2 Serial Console to fix /etc/fstab. Alternatively, stop the instance, attach its root volume to a rescue instance, edit the file and reattach it. |
mount: wrong fs type, bad option, bad superblock | Volume was never formatted, or the type field doesn't match | Run sudo file -s /dev/nvme1n1 and set the type field to match |
mount point /data does not exist | Directory not created | sudo mkdir -p /data |
| xfs volume from a snapshot won't mount: duplicate UUID | Snapshot of a disk that is already mounted on the same instance | Mount once with -o nouuid, or give it a new UUID with sudo xfs_admin -U generate /dev/nvme2n1 while it is unmounted |
| Volume is empty after a reboot | Data was written to /data before it was mounted, so it landed on the root disk | Check with findmnt /data before writing data, and keep the mount point directory empty |
Note: When you mount the root volume of an instance on a rescue instance built from the same AMI, xfs may refuse because of a duplicate UUID. Use sudo mount -o nouuid /dev/nvme1n1p1 /mnt there.
Best practices
- Always reference the volume by
UUID=(orLABEL=), never by/dev/xvdfor/dev/nvme1n1. - Always include
nofailfor non-root EBS volumes so that a detached or failed volume doesn't block boot. - Run
findmnt --verifyafter every edit to fstab, and keep the backup copy until the reboot test passes. - Set ownership after mounting, for example
sudo chown ec2-user:ec2-user /data. Permissions belong to the mounted filesystem, not to the empty directory underneath it. - After increasing the volume size in AWS, grow the filesystem online with
sudo xfs_growfs /dataorsudo resize2fs /dev/nvme1n1. The fstab entry doesn't need to change because the UUID stays the same. - Turn on EBS encryption when you create the volume. It is transparent to the OS and needs no fstab changes.
- For fleets or Auto Scaling groups, script these steps in user data or an AMI instead of editing each instance by hand.
Frequently asked questions
Does the fstab entry still work after stopping and starting the instance?
Yes. Stop/start is just a reboot as far as fstab is concerned, as long as the volume stays attached. Because the entry uses the UUID, it works even if the instance moves to a Nitro type and the device name changes.
What does the nofail option do in /etc/fstab?
It tells systemd to continue booting if the device is missing or fails to mount. Without it, a detached EBS volume or a wrong UUID can drop the instance into emergency mode and leave it unreachable over SSH.
Will the UUID change if I take a snapshot or resize the volume?
Resizing doesn't change the filesystem UUID. A volume created from a snapshot has the same UUID as the original, which can conflict if both are attached to the same instance. Only running mkfs again, or changing the UUID on purpose, generates a new one.
How do I find which NVMe device matches my EBS volume ID?
Run ls -l /dev/disk/by-id/. EBS NVMe devices appear as nvme-Amazon_Elastic_Block_Store_vol... links that include the volume ID. On Amazon Linux, sudo ebsnvme-id /dev/nvme1n1 also prints the volume ID and the requested device name.
Should I use xfs or ext4 for an EBS data volume?
Both work well. xfs is the default on Amazon Linux and RHEL and can be grown online but not shrunk. ext4 is the Ubuntu default and supports offline shrinking. Pick the one your team already knows how to manage.
Related tutorials
- More AWS tutorials
- More Linux tutorials
- How to Login to Linux Server using Putty?
- AWS Tutorials: Auto Scaling Group
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals