Tag Archives: EC2

Mount EBS Volumes To EC2 Linux Instances

View all available volumes:

$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   10G  0 disk 
├─xvda1 202:1    0    1M  0 part 
└─xvda2 202:2    0   10G  0 part /
xvdf    202:80   0  3.9T  0 disk 
$ file -s /dev/xvdf
/dev/xvdf: data

If returns data it means the volume is empty. We need to format it first:

$ mkfs -t ext4 /dev/xvdf
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144000 inodes, 1048576000 blocks
52428800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3196059648
32000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done       

Create a new directory and mount it to EBS volume:

$ cd / && mkdir ebs-data
$ mount /dev/xvdf /ebs-data/

Check volume mount:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       10G  878M  9.2G   9% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           496M     0  496M   0% /dev/shm
tmpfs           496M   13M  483M   3% /run
tmpfs           496M     0  496M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/1000
tmpfs           100M     0  100M   0% /run/user/0
/dev/xvdf       3.9T   89M  3.7T   1% /ebs-data

In order to make it mount automatically after each reboot, we need to edit /etc/fstab, first make a backup:

$ cp /etc/fstab /etc/fstab.orig

Find the UUID for the volume you need to mount:

$ ls -al /dev/disk/by-uuid/
total 0
drwxr-xr-x. 2 root root 80 Nov 25 05:04 .
drwxr-xr-x. 4 root root 80 Nov 25 04:40 ..
lrwxrwxrwx. 1 root root 11 Nov 25 04:40 de4dfe96-23df-4bb9-ad5e-08472e7d1866 -> ../../xvda2
lrwxrwxrwx. 1 root root 10 Nov 25 05:04 e54af798-14df-419d-aeb7-bd1b4d583886 -> ../../xvdf

Then edit /etc/fstab:

$ vi /etc/fstab

with:

#
# /etc/fstab
# Created by anaconda on Tue Jul 11 15:57:39 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=de4dfe96-23df-4bb9-ad5e-08472e7d1866 /                       xfs     defaults        0 0
UUID=e54af798-14df-419d-aeb7-bd1b4d583886 /ebs-data               ext4    defaults,nofail 0 2

Check if fstab has any error:

$ mount -a