Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

An EBS volume is attached to EC2 but you cannot mount it

Error/dev/xvdf: data

Short answer

Attaching only exposes a block device. Find the real device name with lsblk (Nitro instances show NVMe names), check with file -s whether it has a file system, format only an empty volume, then mount it. A volume made from a snapshot already has data, so never run mkfs on it.

  • Applies to Amazon Linux 2023, Ubuntu 24.04, Nitro-based EC2 instances
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the disks and their file systems. The output shows the real device name, whether it has a file system, and whether it is already mounted.

    lsblk
    sudo lsblk -f
  2. 2Match what you see, then jump to its fix

    1. 1mount says the device does not exist, although the console shows it attached as /dev/sdfYou used the device name from the attach dialog, not the real oneFix
    2. 2sudo file -s <device> prints only: data, and the FSTYPE column of lsblk -f is emptyThe volume is new and has no file system yetFix
    3. 3file -s shows a file system type (for example XFS), but the volume was empty after mkfsThe volume already holds data, and you formatted it or tried toFix
    4. 4The volume mounts by hand but is missing after a rebootThe fstab line is wrong, so the mount is lost after reboot or the instance will not bootFix

What does the error look like?

  • /dev/xvdf: data
  • mkfs.xfs: command not found

Cause 1 of 4

You used the device name from the attach dialog, not the real one

1Check

The device can have a different name than the one in the block device mapping. On Nitro instances EBS volumes appear as NVMe devices, for example /dev/nvme1n1.

lsblk -o +SERIAL

2Fix

Use the name lsblk prints. The NVMe name can change between boots, and NVMe EBS volumes carry the volume ID as their serial number, so list it with lsblk -o +SERIAL to be sure which disk is which.

sudo mount /dev/nvme1n1 /data

3Verify

The mount point appears in the lsblk output.

lsblk

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 4

The volume is new and has no file system yet

1Check

A new volume is a raw block device. It needs a file system before it can be mounted.

sudo file -s /dev/nvme1n1

2Fix

Create a file system on the empty volume, make a mount point, and mount it. If mkfs.xfs is not found, install the XFS tools first.

sudo mkfs -t xfs /dev/nvme1n1
sudo mkdir /data
sudo mount /dev/nvme1n1 /data
# only if mkfs.xfs is missing on a yum-based system:
# sudo yum install xfsprogs

3Verify

Check the mount and write a test file.

df -h /data
sudo touch /data/test && sudo rm /data/test

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 3 of 4

The volume already holds data, and you formatted it or tried to

1Check

A volume created from a snapshot likely has a file system on it. Creating a new file system on top of it overwrites the data.

sudo lsblk -f

2Fix

Skip mkfs. Mount the existing file system as it is. If you already formatted it, restore it from the snapshot onto a new volume.

sudo mkdir -p /data
sudo mount /dev/nvme1n1 /data

3Verify

Your files are listed under the mount point.

ls /data

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 4 of 4

The fstab line is wrong, so the mount is lost after reboot or the instance will not boot

1Check

Mount entries are not kept across reboots unless they are in /etc/fstab. AWS recommends the UUID, because device names can change.

sudo blkid

2Fix

Back up fstab, add a UUID line with the nofail option, then test it with umount and mount -a before you reboot.

sudo cp /etc/fstab /etc/fstab.orig
# /etc/fstab line (use your own UUID):
# UUID=aebf131c-6957-451e-8d34-ec978d9581ae  /data  xfs  defaults,nofail  0  2
sudo umount /data
sudo mount -a

3Verify

mount -a prints no error and /data is mounted.

findmnt /data

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Always run lsblk -f first, and format only when the FSTYPE column is empty.
  • Use UUIDs and nofail in fstab, and test with mount -a before any reboot.
  • Take a snapshot before you change anything on a volume that holds data.
  • Check the file permissions on the mount point so your application user can write.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.