Skip to main content

Command Palette

Search for a command to run...

LVM from Scratch to Advanced on AWS EC2 (Beginner-Friendly, Production-Safe Guide)

Published
3 min read
LVM from Scratch to Advanced on AWS EC2 (Beginner-Friendly, Production-Safe Guide)

Who This Blog Is For

This blog is written for:

  • Beginners learning Linux storage

  • DevOps aspirants practicing on AWS

  • Anyone preparing for Linux / AWS interviews

  • Readers who want hands-on, reproducible steps, not theory

No prior LVM knowledge is assumed.


Environment Used (Reproducible Setup)

This entire lab was performed on AWS, not on a local VM.

AWS Resources

  • EC2 Instance

    • OS: Ubuntu 24.04 LTS

    • Instance type: t2.micro / t3.micro (practice)

  • EBS Volumes

    • Root volume: 8 GB

    • Additional EBS volumes:

      • 10 GB

      • 12 GB

      • 14 GB

Note: On AWS, EBS volumes appear as NVMe devices (/dev/nvme*).


Step 1: Connect to EC2

ssh -i your-key.pem ubuntu@<public-ip>

Update packages:

sudo apt update

Step 2: Identify Disks (Important)

lsblk
df -h

You should see:

  • / → root filesystem

  • Unmounted disks like:

    • /dev/nvme1n1

    • /dev/nvme2n1

    • /dev/nvme3n1

These are empty EBS volumes.


Step 3: Understand LVM (Simple Explanation)

LVM has three layers:

  1. Physical Volume (PV)
    → Raw disk (EBS volume)

  2. Volume Group (VG)
    → Pool of storage created from PVs

  3. Logical Volume (LV)
    → Usable partition created from VG

This allows flexible storage growth without downtime.


Step 4: Create Physical Volumes

sudo pvcreate /dev/nvme1n1 /dev/nvme2n1

Verify:

pvs

Step 5: Create Volume Group

sudo vgcreate tws_vg /dev/nvme1n1 /dev/nvme2n1

Verify:

vgs

At this point, storage is pooled.


Step 6: Create Logical Volume

sudo lvcreate -L 10G -n tws_lv tws_vg

Verify:

lvs
lsblk

Step 7: Format the Logical Volume

sudo mkfs.ext4 /dev/tws_vg/tws_lv

Step 8: Mount the Logical Volume

sudo mkdir /mnt/tws_lv_mount
sudo mount /dev/tws_vg/tws_lv /mnt/tws_lv_mount

Verify:

df -h

Step 9: Test Data Persistence

cd /mnt/tws_lv_mount
mkdir devops
echo "LVM works on AWS!" > hello.txt

Unmount and remount:

sudo umount /mnt/tws_lv_mount
sudo mount /dev/tws_vg/tws_lv /mnt/tws_lv_mount
cat /mnt/tws_lv_mount/devops/hello.txt

✅ Data persists correctly.


Step 10: Add New EBS Volume (Real AWS Scenario)

A new 14 GB EBS volume was attached via AWS Console.

Verify:

lsblk

Step 11: Add New Disk to LVM

sudo pvcreate /dev/nvme3n1
sudo vgextend tws_vg /dev/nvme3n1

Step 12: Extend Logical Volume (Live)

sudo lvextend -L +5G /dev/tws_vg/tws_lv

At this stage:

  • lsblk → shows increased size

  • df -h → still shows old size

This is expected.


Step 13: Resize Filesystem (Critical Step)

sudo resize2fs /dev/tws_vg/tws_lv

Verify:

df -h

Filesystem is now expanded without downtime.


Production Tip (One Command)

sudo lvextend -L +5G -r /dev/tws_vg/tws_lv

Common Beginner Mistakes (Important)

  • Forgetting filesystem resize after lvextend

  • Formatting disks already used by LVM

  • Not verifying changes using lsblk and df -h

  • Confusing AWS NVMe device names


Why This Matters in Real DevOps

  • Storage can be expanded live

  • No service interruption

  • Works the same on AWS, Azure, GCP

  • Frequently asked interview topic


Happy learning and building on AWS.

More from this blog

LazyStack

18 posts