- 01 Introduction to Linux Volumes and AWS EBS
- 02 Physical vs Logical Volumes vs Volume Groups in Linux
- 03 Mounting Volumes in Linux (LVM)
- 04 Managing AWS EBS on EC2 Instances (Without LVM)
- 05 Using LVM with EBS for Dynamic Storage Management
Imagine you're launching an EC2 instance on AWS — basically, your personal cloud server. Now, when you want to store files or run applications, you’ll need storage space, right?
In Linux (and AWS), that storage is called a volume. Think of it as a virtual hard disk.
When you create an EC2 instance, AWS gives you default storage (usually 8 GB) — this is called the root volume. But as your application grows (logs, user data, backups), you’ll need more space.
💡 That’s where extra volumes come in — we create additional disks and attach them to the instance.
AWS EBS is a service that lets you create extra storage volumes and attach them to your EC2 instance.
Think of EC2 as a computer and EBS volumes as external pen drives or hard disks you plug into it.
- Go to AWS EC2 console
- Choose Ubuntu as the OS
- Select instance type: t2.micro
- Create or use an existing key pair (used for SSH login)
- Allow SSH (port 22) in the security group (very important!)
- In storage section: default 8 GB is pre-set (root volume)
- Launch the instance ✅
- Download the .pem key file
- Open terminal and run:
chmod 400 your-key.pem
ssh -i your-key.pem ubuntu@<your-ec2-ip>- 🎉 You’re now inside your cloud server!
🔍 Check Existing Volumes (Root Disk) Run:
lsblkThis shows all attached volumes:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
```xvda` → Your main/root volume (disk)
`xvda1` → Partition of the root volume
`/` → Means it’s mounted to root of the file system
</section>
<section id="view_disk_usage">
#### 📊 View Disk Usage
Run:
```bash
df -hThis shows used/free space:
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.8G 1.6G 6.0G 22% /“Mounting” means connecting a volume to a directory path in Linux.
So when your volume is mounted to /, it means that Linux is reading/writing to it via that location.
Click “Create Volume”
- Type: General Purpose (gp2)
- Size: 10 GB (similarly repeat for 12 GB & 14 GB)
- Availability Zone: must match your EC2’s zone (e.g., ap-south-1a)
- Click Create Volume
🔁 Repeat for 12 GB and 14 GB volumes.
For each volume:
- Click → Actions → Attach Volume
- Select your EC2 Instance
- Set Device Name as /dev/sdf (first one), then /dev/sdg, /dev/sdh
💡 Don't use /dev/sdb, /dev/sdc, etc. — those are usually reserved for system use.
Run:
lsblkYou’ll now see:
NAME 8G ← root disk
xvdf 10G ← attached EBS
xvdg 12G
xvdh 14G
👉 But notice: their MOUNTPOINT is empty — this means they’re attached but not mounted yet.
In the previous steps, you added 3 extra volumes (10 GB, 12 GB, and 14 GB) to your EC2 instance. But right now, they’re just raw blocks of storage — like unformatted pen drives.
To use them properly, Linux uses a smart system called LVM — Logical Volume Manager.
| LVM Layer | Real-World Analogy |
|---|---|
| Physical Volume (PV) | Raw bricks (your disk space) |
| Volume Group (VG) | A big room made by combining bricks |
| Logical Volume (LV) | Separate cabins (partitions) built in room |
You’ll need root permissions to use LVM. You can either run sudo before each command or switch to root:
sudo su
lvm # optional: drops into LVM shellRight now your new disks (/dev/xvdf, /dev/xvdg, /dev/xvdh) are not usable by LVM — we need to convert them to Physical Volumes (PV).
pvcreate /dev/xvdf /dev/xvdg /dev/xvdh
# ✅ This tells Linux: “These disks are ready to be managed by LVM.”You can verify:
pvsNow combine some physical volumes into a Volume Group (VG). For example:
vgcreate my_vg /dev/xvdf /dev/xvdg
# This creates a Volume Group named my_vg with 10 GB + 12 GB = 22 GB.Check with:
vgs
# It will show:
# - Volume Group name
# - Size
# - Number of PVs and LVs inside itNow let’s cut out a slice from that VG and create a Logical Volume (LV) — say, a 10 GB slice:
lvcreate -L 10G -n my_lv my_vg
# -L = size of logical volume
# -n = name of logical volume
# my_vg = the group from which this slice is carved outVerify:
lvsShow physical volume info:
pvdisplayShow volume group details:
vgdisplayShow logical volume details:
lvdisplay1. pvcreate → Make raw disks usable by LVM
2. vgcreate → Combine PVs into a volume group
3. lvcreate → Create partitions (LVs) from the VG
At this point, your logical volume (like /dev/my_vg/my_lv) is ready — but you can’t use it yet. You still need to:
- Format it
- Mount it to a folder
You’ve already created:
- ✅ Physical Volumes (pvcreate)
- ✅ Volume Group (vgcreate)
- ✅ Logical Volume (lvcreate)
Now it’s time to make the Logical Volume usable — and that’s where mounting comes in.
If you run:
lsblk
# You’ll see your disks and LVM layout like /dev/xvdf, /dev/my_vg/my_lv.But if you run:
df -h
👉 You won’t see your new volume here yet — because it’s not mounted.lvs
# Make sure your LV (e.g., my_lv) exists inside your VG (e.g., my_vg).Think of this as a folder where your volume will be plugged in:
mkdir /mnt/my_mountBefore mounting, you need to create a filesystem (e.g., EXT4) on the volume:
mkfs.ext4 /dev/my_vg/my_lv
#⚠️ This will erase everything on the volume, just like formatting a pen drive.Now bind (mount) the LV to your mount folder:
mount /dev/my_vg/my_lv /mnt/my_mount
# ✅ Now your storage is usable from that folder!df -h
# You’ll see a new line like:
/dev/mapper/my_vg-my_lv 10G 50M 9.9G 1% /mnt/my_mount
# 🎉 Success! The volume is now mounted and ready to store files.Go inside the mount directory:
cd /mnt/my_mount
echo "Hello from LVM!" > test.txt
cat test.txt
# 💡 If you see the content, it means your mounted volume is working perfectly.| Concept | Meaning |
|---|---|
| Attached | Disk is plugged into the system (via AWS EBS, etc.) |
| Mounted | Disk is connected to a directory and can be used |
👉 Attached is like plugging in a USB drive
👉 Mounted is like opening it and starting to use it
🛑 Unmount:
umount /mnt/my_mountIf you now try:
cat /mnt/my_mount/test.txt❌ You won’t be able to access it (because it’s unmounted). But don’t worry — your data is safe.
🔁 Remount:
mount /dev/my_vg/my_lv /mnt/my_mount
# Now the file is back!- lsblk shows block devices
- df -h shows mounted filesystems
- mkfs.ext4 formats the LV
- mount makes it usable
- You can store files, read them, unmount, remount — your data will remain safe on disk
🎯 Objective: Mount an AWS EBS Volume without using LVM So far, you've used LVM to manage storage. But what if you just want to use an EBS volume directly, like a plug-and-play hard disk?
Let’s say you have one unused volume left: /dev/xvdh (14 GB). Let’s mount it directly to your EC2 instance.
Create a folder where you want to mount the disk:
mkdir /mnt/new_disk_mount
# So now in /mnt/, you’ll have:
/mnt/new_lv_mount ← for LVM-managed volume
/mnt/new_disk_mount ← for directly-mounted EBS diskBefore using a raw disk, you must format it and apply a file system.
mkfs -t ext4 /dev/xvdh
# mkfs: Make filesystem
# -t ext4: Choose file system type (EXT4 is default and most used in Linux)
# ⚠️ This will wipe the disk clean!Now mount the volume (bind it to the directory):
mount /dev/xvdh /mnt/new_disk_mountNow it's ready to use. Check it:
df -hYou’ll see something like:
/dev/xvdh 14G 24M 13.9G 1% /mnt/new_disk_mount✅ You can now create files inside /mnt/new_disk_mount and use the disk like normal storage!
| Feature | With LVM | Without LVM |
|---|---|---|
| Disk flexibility | Extend/Shrink volumes dynamically | Fixed size, no flexibility |
| Setup complexity | Higher (PV, VG, LV setup needed) | Very simple (just format & mount) |
| Use case | Dynamic apps, servers, scaling | Simple static storage (logs, media, etc.) |
Now let’s say your app is growing and you need more storage on an LVM volume — LVM makes this easy.
Let’s assume your volume group still has free space. To add 5 GB more to your logical volume:
lvextend -L +5G /dev/new_vg/new_lv
# -L +5G: Add 5 GB to existing size
# /dev/new_vg/new_lv: Your target LV
✅ This extends the volume at the LVM level.After extending the LV, you must tell the file system to use the new space:
resize2fs /dev/new_vg/new_lvWithout this, your file system will still act like it’s using the old size!
df -hYou’ll see that the /mnt/new_lv_mount volume now shows the increased space.
- LVM is powerful for managing growing applications or dynamic storage.
- Direct EBS volumes are quick and simple, great for static use cases.
- Combine both depending on your DevOps need and system architecture.