AWS EBS Volume Setup: From Attachment to Mounting on EC2 Made Simple


Amazon Elastic Block Store (EBS) provides persistent block storage volumes for Amazon EC2. Whether you're a developer deploying scalable applications or a DevOps engineer managing cloud infrastructure, understanding how to attach and mount EBS volumes is essential. This guide simplifies the entire process—from creating and attaching an EBS volume to mounting it on an EC2 instance.


 Step 1: Create an EBS Volume

  1. Navigate to the AWS EC2 dashboard.

  2. Click on “Elastic Block Store” > “Volumes” > “Create Volume.”

  3. Choose the volume type (e.g., gp3 for general purpose).

  4. Select the Availability Zone matching your EC2 instance.

  5. Set the size in GiB, and click Create Volume.

 Tip: Ensure your EC2 instance is in the same availability zone as the EBS volume; otherwise, it won’t be attachable.


 Step 2: Attach the EBS Volume to an EC2 Instance

  1. From the Volumes list, select the volume, then choose Actions > Attach Volume.

  2. Select your EC2 instance ID.

  3. Set the device name (e.g., /dev/xvdf) and click Attach.

Check the attachment with:


lsblk



 Step 3: Format the EBS Volume

Use the following command to format the EBS volume as ext4:


sudo mkfs -t ext4 /dev/xvdf

 Note: If the volume was already formatted or contains data, skip this step.


Step 4: Mount the EBS Volume

  1. Create a directory to mount the volume:


sudo mkdir /data


  1. Mount the volume:


sudo mount /dev/xvdf /data


  1. Confirm the mount:


df -h



 Step 5: Mount EBS Automatically on Reboot

To ensure the volume remounts on instance reboot:

  1. Add to /etc/fstab:


echo '/dev/xvdf /data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab


  1. Test the fstab configuration:


sudo mount -a



 Bonus: Secure and Monitor Your EBS Volume

  • Encrypt your volume for sensitive workloads.

  • Take snapshots for backup.

  • Use CloudWatch to monitor performance and health.


Conclusion

Attaching and mounting EBS volumes on AWS EC2 instances doesn’t have to be intimidating. Following these straightforward steps will ensure reliable, persistent storage for your applications.


Comments

Popular posts from this blog

ECS Deployment Best Practices: Blue/Green with CodePipeline and CodeDeploy

HTTP Basic vs API Key Auth: Best Practices for Secure API Development

Creating BI Solutions: AI/BI Genie Space Authoring Best Practices in Databricks

YouTube Channel