🎯 Objective
Attach an EBS (Elastic Block Store) volume to an EC2 instance and make it usable (mount + persist).
🧠 What is an EBS Volume?
An EBS volume is a network-attached disk for EC2.
Key Features:
🏗️ Architecture
EC2 Instance ←→ EBS Volume👉 After attaching, you must format + mount it manually.
# 🛠️ Method 1: Attach via AWS Console
📍 Step 1: Create Volume
1. Go to EC2 Dashboard
1. Click Volumes
1. Click Create Volume
1. Configure:
1. Click Create
🔗 Step 2: Attach Volume
1. Select volume
1. Click Actions → Attach Volume
1. Choose:
1. Click Attach
# ⚙️ Method 2: Using AWS CLI
📌 Create Volume
aws ec2 create-volume \
--availability-zone ap-southeast-1a \
--size10 \
--volume-type gp3📌 Attach Volume
aws ec2 attach-volume \
--volume-id vol-123456 \
--instance-id i-1234567890abcdef0 \
--device /dev/xvdf# 🔍 Step 3: Verify in EC2 Instance
SSH into instance:
ssh ec2-user@<public-ip>List disks:
lsblk👉 You should see:
xvda → root disk
xvdf → new volume# 🧱 Step 4: Format the Volume
👉 Only if it’s a new volume
sudo mkfs-t ext4 /dev/xvdf# 📂 Step 5: Mount the Volume
Create mount point:
sudomkdir /dataMount:
sudo mount /dev/xvdf /data🔍 Verify Mount
df-h# 💾 Step 6: Make It Persistent (IMPORTANT)
Edit fstab:
sudovi /etc/fstabAdd:
/dev/xvdf /data ext4 defaults,nofail 0 2✅ Test fstab
sudo mount -a👉 If no error → correct
# ⚠️ Important Notes
# 🚀 Real Use Cases
# 🧪 Example Scenario
👉 Attach volume for logs:
sudomkdir /var/log/app
sudo mount /dev/xvdf /var/log/app# ⚠️ Common Mistakes
# 🧠 DevOps Insight
👉 Real production flow:
Attach → Format → Mount → Persist (fstab)