blahblahblah
blahblahblah

Reputation: 2447

Unable to mount EBS volume on Ubuntu EC2

I cant seem to figure out how to mount an EBS volume to a Ubuntu EC2 instance using Amazon's instructions. Can someone help me out?

~$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  16G  0 disk 
└─xvda1 202:1    0  16G  0 part /

~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            492M   12K  492M   1% /dev
tmpfs           100M  340K   99M   1% /run
/dev/xvda1       16G  7.2G  7.8G  48% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            497M     0  497M   0% /run/shm
none            100M     0  100M   0% /run/user

~$ sudo file -s /dev/xvda
/dev/xvda: x86 boot sector

~$ sudo file -s /dev/xvda1
/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=da85f42e-5e55-40d1-95da-dea139db0d7f, volume name "cloudimg-rootfs" (needs journal recovery) (extents) (large files) (huge files)

~$ sudo mkfs -t ext4 /dev/xvda
mke2fs 1.42.9 (4-Feb-2014)
/dev/xvda is apparently in use by the system; will not make a filesystem here!

~$ sudo mkdir /data

~$ sudo mount /dev/xvda /data
mount: /dev/xvda already mounted or /data busy

Upvotes: 0

Views: 1756

Answers (2)

Adib
Adib

Reputation: 49

here's a script for Amazon Linux 2 you can recreate for Ubuntu just try while commenting raws with yum:

#!/bin/bash
sudo yum -y update
sudo yum -y upgrade

# Format and mount an attached volume
DEVICE=/dev/$(lsblk -rno NAME | awk 'FNR == 3 {print}')
MOUNT_POINT=/data/
mkdir $MOUNT_POINT
yum -y install xfsprogs
mkfs -t xfs $DEVICE
mount $DEVICE $MOUNT_POINT

# Automatically mount an attached volume after reboot / For the current task it's not obligatory
cp /etc/fstab /etc/fstab.orig
UUID=$(blkid | grep $DEVICE | awk -F '\"' '{print $2}')
echo -e "UUID=$UUID     $MOUNT_POINT      xfs    defaults,nofail   0   2" >> /etc/fstab
umount /data
mount -a

# Change user for data operations / Non mandatory
chown -R ec2-user:ec2-user $MOUNT_POINT

from here

Upvotes: 0

Mark B
Mark B

Reputation: 201008

You appear to have one disk xvda with one partition xvda1. The partition /dev/xvda1 is already mounted at /. Since you only have one disk, with one partition, that is mounted as the root volume, there really isn't anything else you can do at this point. Are you trying to add a second EBS volume to your EC2 instance? If so you need to attach it to the instance first, and then look for it to show up in the lsblk output.

Upvotes: 2

Related Questions