Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Last active September 26, 2023 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupeshtiwari/ca53553495d228f415b70e1e508fdfb5 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/ca53553495d228f415b70e1e508fdfb5 to your computer and use it in GitHub Desktop.
attach extra volume to EC2, AWS, Linux, Storage, Mounting Amazon EBS to EC2 Instance, extra volume, attach ebs, aws

Mounting Amazon EFS to EC2 Instance, extra volume, attach ebs, aws

  1. Create new extra EBS volume from AWS console named /dev/xvdf
  2. Attach the new volume to EC2 from AWS Console
  3. Connect to EC2, create a new directory and mount the new extra EBS volume
  • Check all devices attached sudo lsblk -f

  • Determine if file system exist for the new volume sudo file -s /dev/xvdf

  • Create a new file system on EC2 to mount volume mkfs -t xfs /dev/xvdf

    image

    image

  • Create new mount point directory to mount the new volume on EC2 sudo mkdir /data

  • Mount the volume to this new directory sudo mount /dev/xvdf /data

  • Grant full access permission sudo chmod -R 777 /data

  • Confirm its mounted sudo lsblk -f

    image

  • Confirm disk free df -h image

Summary

When you check df -h you won't see the new volume xvdf as a mounted to EC2 local directory. You have to manually connect to E2 and create file system, mount directory and mount EBS volume.

image

All scripts

df -h

# Lists all the block devices in the Linux Machine:
lsblk 

# Check if there is any file system on new EBS Volume:
file -s /dev/xvdf
(If you see "Data", meaning you need to setup file system for this block device.)

# Create a file system on volume to mount it to EC2:
mkfs -t xfs /dev/xvdf

# Create new directory:
mkdir -p /apps/my-data/apps/volume/new-volume
cd /apps/my-data/

# Mount volume to EC2 Instance:
mount /dev/xvdf /apps/my-data/apps/volume/new-volume 

Reference

https://www.youtube.com/watch?v=XqOoNMLlKus&t=432s https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment