No long stories straight steps.
Click on volumes under Elastic Block Store in EC2 dashboard
Create new EBS drive
Use already running instance or create new EC2 instance.
Again from EC2 dashboard navigate to volumes under Elastic Block Store. Select your volume that you want to attach and from action click attach and select your ec2 instance.
SSH into your EC2 instance
lsblkthis will list all devices attached to your instance.
Try to identify new EBS volume name in the results
Check mountpoint column for that row and that should be empty and that's fine
sudo file -s /dev/xvdfreplace xvdf with your volume this command will result in
/dev/xvdf: datathat means there is no file system associated with that drive. We have to format this newly created volume with some file system which is supported.
sudo mkfs -t ext4 /dev/xvdfthis will format that newly created volume in ext4 file system.
Now we will create mount point where we will mount this new volume in our system.
sudo mkdir /dataand then
sudo mount /dev/xvdf/ /datathis will mount it to /data directory.
Make sure we have mounted successfully by
To mount this volume everytime we reboot run
sudo cp /etc/fstab /etc/fstab.origand then
sudo nano /etc/fstab. Enter following statement at the end and save this file
/dev/xvdf /data ext4 defaults,nofail 0 2
Check if everything is on track by
sudo file -s /dev/xvdfand now you should see everything about this new volume.
Check if it is mounting on every reboot by
sudo umount /datawill unmount and then
sudo mount -awill run the script to mount all volumes on reboot.
Check back by
lsblkand everything should be mounted as expected.
This post is written based on AWS documentation and please make sure you read all types of services and charges associated with them. You will be charged if you use any service out of their free tier. I am not responsible for your any types of issues and charges. Please use this post on your own understanding.