How to Mount and Access an Attached EBS Volume on Amazon EC2 Instance


2 views

After attaching an EBS volume to your running EC2 instance, you won't immediately find it at /dev/sda because:

  • /dev/sda typically refers to your root volume
  • New volumes usually get assigned sequential names like /dev/sdf, /dev/sdg, etc.

To identify your new volume:

lsblk
# or
ls /dev/xvd*

Use these commands to list all available block devices:

sudo fdisk -l
# For newer Linux kernels:
sudo lsblk -o NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT

Once you've identified your volume (e.g., /dev/xvdf), follow these steps:

# Check if the volume has a filesystem
sudo file -s /dev/xvdf

# If no filesystem exists, create one
sudo mkfs -t ext4 /dev/xvdf

# Create a mount point
sudo mkdir /data

# Mount the volume
sudo mount /dev/xvdf /data

To ensure the volume mounts automatically after reboot:

# Get the UUID of your volume
sudo blkid /dev/xvdf

# Edit /etc/fstab
sudo nano /etc/fstab

# Add this line (replace UUID with your actual UUID)
UUID=your-uuid-here /data ext4 defaults,nofail 0 2

Confirm everything worked correctly:

df -h
# Should show your mounted volume
  • If you get "device busy" errors, check for running processes: sudo lsof /data
  • For "wrong fs type" errors, verify your filesystem type matches what's in fstab
  • If the instance won't boot after fstab changes, detach the volume temporarily to fix the file

When you attach an EBS volume to your running EC2 instance, it won't automatically appear in your filesystem. First, you need to identify the device name assigned by AWS. Common device names include:

# List available block devices
lsblk

# Alternative command to show attached storage
ls /dev/xvd*

You might see devices like /dev/xvdf or /dev/nvme1n1 (for NVMe instances) instead of the traditional /dev/sda naming.

Once you've identified your volume, follow these steps:

# Check if the volume has a filesystem
sudo file -s /dev/xvdf

# If no filesystem exists, create one (WARNING: erases all data)
sudo mkfs -t ext4 /dev/xvdf

# Create a mount point
sudo mkdir /data

# Mount the volume
sudo mount /dev/xvdf /data

To ensure the volume mounts automatically on instance restart:

# Get the UUID of your volume
sudo blkid /dev/xvdf

# Add to /etc/fstab
echo "UUID=your-uuid-here /data ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab

Test your configuration with these commands:

# Check mounted filesystems
df -h

# Verify fstab entry
sudo mount -a
ls /data

If you encounter problems:

  • Check AWS console to confirm volume is "in-use"
  • Verify the instance has permission to access the volume (IAM roles)
  • Ensure you're using the correct device name for your instance type

For modern instance types with NVMe volumes:

# Install NVMe utilities (Amazon Linux)
sudo yum install -y nvme-cli

# List NVMe devices
sudo nvme list

# Mount command example
sudo mount /dev/nvme1n1 /data