DEV Community

loading...
Cover image for Attach new EBS to your EC2 instance

Attach new EBS to your EC2 instance

asdflkjh profile image kinaamnay ・2 min read

No long stories straight steps.

  1. Click on volumes under Elastic Block Store in EC2 dashboard

  2. Create new EBS drive

  3. Use already running instance or create new EC2 instance.

  4. 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.

  5. SSH into your EC2 instance

  6. lsblk this will list all devices attached to your instance.

  7. Try to identify new EBS volume name in the results

  8. Check mountpoint column for that row and that should be empty and that's fine

  9. sudo file -s /dev/xvdf replace xvdf with your volume this command will result in /dev/xvdf: data that 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.

  10. sudo mkfs -t ext4 /dev/xvdf this will format that newly created volume in ext4 file system.

  11. Now we will create mount point where we will mount this new volume in our system. sudo mkdir /data and then sudo mount /dev/xvdf/ /data this will mount it to /data directory.

  12. Make sure we have mounted successfully by lsblk

  13. To mount this volume everytime we reboot run sudo cp /etc/fstab /etc/fstab.orig and then sudo nano /etc/fstab . Enter following statement at the end and save this file /dev/xvdf /data ext4 defaults,nofail 0 2

  14. Check if everything is on track by sudo file -s /dev/xvdf and now you should see everything about this new volume.

  15. Check if it is mounting on every reboot by cd / and sudo umount /data will unmount and then sudo mount -a will run the script to mount all volumes on reboot.

  16. Check back by lsblk and 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.

Discussion (0)

pic
Editor guide