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
Navigate to the AWS EC2 dashboard.
Click on “Elastic Block Store” > “Volumes” > “Create Volume.”
Choose the volume type (e.g., gp3 for general purpose).
Select the Availability Zone matching your EC2 instance.
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
From the Volumes list, select the volume, then choose Actions > Attach Volume.
Select your EC2 instance ID.
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
Create a directory to mount the volume:
sudo mkdir /data
Mount the volume:
sudo mount /dev/xvdf /data
Confirm the mount:
df -h
Step 5: Mount EBS Automatically on Reboot
To ensure the volume remounts on instance reboot:
Add to /etc/fstab:
echo '/dev/xvdf /data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab
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
Post a Comment