Day 7 | Today, I learned about EBS Volume Mounting on EC2 β and itβs a key skill for managing persistent storage in AWS! π₯
I learned how to attach, mount, unmount, and re-attach an EBS Volume to an EC2 instance to ensure data remains safe β even if the instance is stopped or restarted. πΎ
This is extremely useful in real DevOps environments where applications need reliable and durable storage.
π Key things I learned today:
| Concept | Explanation |
|---|---|
| EBS Volume Importance | Provides persistent and durable storage for EC2 instances |
| Block-Level Storage | Works like a virtual hard disk and supports file systems & databases |
| Data Persistence | Data remains safe even after unmounting or EC2 stop/start |
| File System Support | Can format volume using EXT4 or XFS before mounting |
| Disk Verification |
lsblk command helps check available disks and mount points |
| Safe Unmounting | Always unmount before detaching to prevent data corruption |
| Attach to Another EC2 | Volume can be detached and reattached to another instance easily |
| Best Use Cases | Ideal for databases, logs, backups, and application storage |
π AWS EBS Volume Mounting β Step-by-Step Guide
Date: 01/08/2024
Topic: How to create, attach, mount, unmount, and reuse an EBS Volume in AWS
π What You Will Learn
- Create and attach an EBS Volume
- Mount volume inside Linux EC2 instance
- Store data and verify persistence
- Unmount and reattach the same volume to another instance
π Step 1: Create an EC2 Instance
Launch a Linux EC2 instance (Amazon Linux / Ubuntu)
π½ Step 2: Create an EBS Volume
Go to:
EC2 β Volumes β Create Volume
yaml
Copy code
Select:
- Volume Type: gp2 / gp3
- Size: 5β20 GB (example)
- Availability Zone: MUST match EC2 instance AZ
If AZ is different β β Volume cannot be attached
Click Create Volume β Attach Volume
π Step 3: Attach Volume to Instance
EC2 β Volumes β Select Volume β Actions β Attach Volume
java
Copy code
Note the device name (Example):
/dev/xvdf
yaml
Copy code
Step 4: Mounting The Volume in Linux (Terminal)
π Check available disks
lsblk
π Check if volume contains data
sudo file -s /dev/xvdf
π Format the volume (Fresh Volume Only)
sudo mkfs -t xfs /dev/xvdf
OR
sudo mkfs.ext4 /dev/xvdf
π Create a mount directory
sudo mkdir /home/ec2-user/test
π Mount the volume
sudo mount /dev/xvdf /home/ec2-user/test
π Confirm mount
lsblk
π Step 5: Create Files & Folders (Data stored inside EBS volume)
cd /home/ec2-user/test
mkdir one two three four five
touch india pune mumbai
π Step 6: Unmount Volume
Move back to home directory:
cd ~
Unmount:
sudo umount /dev/xvdf
π The folder looks empty but the data remains stored inside the EBS volume.
π Step 7: Re-Mount to Verify Data
sudo mount /dev/xvdf /home/ec2-user/test
ls /home/ec2-user/test
β Your files will appear again!
π Step 8: Attach to Another Instance
Unmount first:
sudo umount /dev/xvdf
β‘οΈ Detach Volume β Attach to another EC2 instance
Mount again:
sudo mkdir /home/ec2-user/test
sudo mount /dev/xvdf /home/ec2-user/test
π Connect With Me
| π Platform | π Link |
|---|---|
| π GitHub | https://lnkd.in/d2F3JPa3 |
| βοΈ Dev.to Blog | https://lnkd.in/dNtgqAME |
| πΌ LinkedIn | https://lnkd.in/d3NctxFT |
| π Resume (Google Drive) | https://lnkd.in/dHDNsd_D |

Top comments (0)