Attach And Mount EBS Volume To EC2 Linux Instance

AWS allows to create / attach / mount new EBS volumes to instances for extra storage. Use lsblk command to view available disk devices and other mount points.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.6G 6.5G 20% /

– Go to EC2 Console –> Volumes to create new volume of required size and type.

– Select the last created volume and select the “attach volume” to attach to the ec2 instance.

– Now, SSH login to ec2 instance and find list of available disks or mounts.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 16G 0 disk

Check the volume has data or empty
# file -s /dev/xvdf

Format the volume to ext4 file system type
# mkfs -t ext4 /dev/xvdf

Mount the volume to “/mnt/dir/” directory
# mkdir /mnt/dir/
# mount /dev/xvdf /mnt/dir/ -t ext4

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.6G 6.5G 20% /
/dev/xvdf 16G 45M 15G 1% /mnt/dir

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 16G 0 disk /mnt/dir

EBS Automount On Reboot using fstab
# cp /etc/fstab /etc/fstab.bak

Write FSTAB file
# vi /etc/fstab
/dev/xvdf /mnt/dir ext4 defaults,nofail

Check errors
# mount -a

How to unmount volume??
# umount /dev/xvdf

Help: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch