# How to Store Data on Amazon EC2 Using EBS Volumes

Listen to this Post

Amazon EBS (Elastic Block Store) is a scalable block storage service designed for Amazon EC2 instances. It provides durable, high-performance storage that can be attached to running instances. Below is a step-by-step guide to setting up and managing EBS volumes.

Steps to Configure EBS for EC2

1. Create an EBS Volume

  • Go to the AWS Management Console β†’ EC2 Dashboard β†’ Volumes β†’ Create Volume.
  • Select the Volume Type (gp3 for general-purpose, io1/io2 for high IOPS).
  • Specify Size (in GiB) and Availability Zone (must match the EC2 instance’s AZ).

AWS CLI Command:

aws ec2 create-volume --availability-zone us-east-1a --size 100 --volume-type gp3

2. Attach the EBS Volume to an EC2 Instance

  • In the EC2 Volumes section, select the volume β†’ Actions β†’ Attach Volume.
  • Choose the EC2 Instance ID and specify a Device Name (e.g., /dev/sdf).

**AWS CLI Command:**

aws ec2 attach-volume --volume-id vol-1234567890abcdef0 --instance-id i-0123456789abcdef0 --device /dev/sdf

### **3. Format and Mount the EBS Volume**

  • SSH into your EC2 instance:
    ssh -i "your-key.pem" ec2-user@your-instance-ip
    
  • Check the attached disk:
    lsblk
    
  • Format the disk (if new):
    sudo mkfs -t xfs /dev/xvdf
    
  • Create a mount directory:
    sudo mkdir /mnt/ebs_volume
    
  • Mount the volume:
    sudo mount /dev/xvdf /mnt/ebs_volume
    
  • Make mount persistent (add to /etc/fstab)
    echo "/dev/xvdf /mnt/ebs_volume xfs defaults,nofail 0 2" | sudo tee -a /etc/fstab
    

### **4. Monitor and Backup EBS Volumes**

  • Use CloudWatch for monitoring:
    aws cloudwatch get-metric-statistics --namespace AWS/EBS --metric-name VolumeReadBytes --dimensions Name=VolumeId,Value=vol-1234567890abcdef0 --start-time 2023-10-01T00:00:00 --end-time 2023-10-02T00:00:00 --period 3600 --statistics Average
    
  • Create EBS Snapshots (Backup):
    aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description "Daily Backup"
    

## **You Should Know:**

βœ” **EBS Volume Types:**

  • gp3: General-purpose SSD (balanced price/performance).
  • io1/io2: High-performance SSD (for databases).
  • st1: Low-cost HDD (throughput-optimized).
  • sc1: Cold HDD (cheapest, rarely accessed data).

βœ” **Detaching EBS Safely:**

sudo umount /mnt/ebs_volume 
aws ec2 detach-volume --volume-id vol-1234567890abcdef0

βœ” **Resizing EBS:**

  • Modify volume in AWS Console β†’ Extend filesystem:
    sudo growpart /dev/xvdf 1 
    sudo xfs_growfs /mnt/ebs_volume
    

## **What Undercode Say:**

Amazon EBS is essential for persistent storage in AWS. Always:
Encrypt volumes for security (aws ec2 enable-ebs-encryption-by-default).
Automate snapshots using AWS Backup or Lambda.
Monitor IOPS/throughput to avoid bottlenecks.
Use Linux commands (df -h, iostat -x 5) for disk health checks.

**Expected Output:**

A fully mounted EBS volume accessible at `/mnt/ebs_volume` with automated backups and performance monitoring.

**Further Reading:**

References:

Reported By: Riyazsayyad Imagine – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass βœ…

Join Our Cyber World:

πŸ’¬ Whatsapp | πŸ’¬ TelegramFeatured Image