Linux course index · Linux Advanced category · Lesson 1 of 9
AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.
Learning goal
Create and expand an isolated LVM stack without touching the system disk.
Concepts and setup
A physical volume (PV) contributes space to a volume group (VG). An LV uses space from that group. The filesystem inside the LV is a separate layer. The site’s pvs, vgs, and lvs sequence helps you find where the free space is.
Work in a disposable VM with lvm2 and ext4 tools. Keep the same Bash session open. Stop after any error. This exercise initializes a unique file-backed loop device. Do not substitute /dev/sda, /dev/vda, or another existing disk.
Create a fresh PV, VG, LV, and ext4 filesystem
lab=$(mktemp -d)
vg="oe_lab_$(id -u)_$$"
truncate -s 384M "$lab/disk.img"
loopdev=$(sudo losetup --find --show "$lab/disk.img")
[[ $loopdev =~ ^/dev/loop[0-9]+$ ]] || exit 1
sudo losetup "$loopdev"
# Continue only if the output identifies your new disk.img.
sudo pvcreate "$loopdev"
sudo vgcreate "$vg" "$loopdev"
sudo lvcreate -L 96M -n data "$vg"
lv="/dev/$vg/data"
sudo mkfs.ext4 -q "$lv"
mkdir "$lab/mnt"
sudo mount "$lv" "$lab/mnt"
printf 'before resize\n' | sudo tee "$lab/mnt/proof.txt"
sudo lvs "$lv" -o vg_name,lv_name,lv_size
Possible output
/dev/loop8: ... (/tmp/tmp.ABC/disk.img)
...
before resize
VG LV LSize
oe_lab_1000_3250 data 96.00m
If the lab VM’s LVM policy does not allow the loop device, stop. Do not relax host-wide device scanning or substitute a real disk.
Grow both layers and verify the data
sudo lvextend -L +64M "$lv"
sudo resize2fs "$lv"
df -h "$lab/mnt"
cat "$lab/mnt/proof.txt"
sudo lvs "$lv" -o lv_name,lv_size
# Cleanup only after recording the results:
sudo umount "$lab/mnt" &&
sudo lvremove -y "$lv" &&
sudo vgremove -y "$vg" &&
sudo pvremove -y "$loopdev" &&
sudo losetup -d "$loopdev"
Possible output
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/oe_lab_1000_3250-data 150M ... ... ... /tmp/tmp.ABC/mnt
before resize
LV LSize
data 160.00m
The displayed sizes are examples. XFS requires a different grow tool and does not support ordinary shrinking. If cleanup fails, leave the backing file in place until you resolve the error.
Questions only
Quick-check questions
- Why can df stay unchanged immediately after lvextend?
- What does vgs show that lvs does not?
Assessment questions
- Identify the exact device the lab initialized and how you verified it.
- Explain why lvs and df can show different sizes after growth.
- What checks would you use to validate a real application storage expansion?
Questions and answers
Quick-check answers
- Why can df stay unchanged immediately after lvextend?
Answer — The LV has grown but the filesystem may still have its old size. - What does vgs show that lvs does not?
Answer — It shows group-wide capacity, including the unallocated space.
Assessment answer key
- Identify the exact device the lab initialized and how you verified it.
Answer — Only the new /dev/loopN associated with this lab’s disk.img. Inspect it with losetup before pvcreate. - Explain why lvs and df can show different sizes after growth.
Answer — lvs reports block capacity, while df reports filesystem space with its own overhead and accounting. - What checks would you use to validate a real application storage expansion?
Answer — Check the device, mount, capacity, and filesystem state, then read and write known application data in an approved test.
Source articles on this site
- Linux: LVM : Logical Volume Manager : Multiple Hard Disk and Partition and Volume Management
- Disk/Partition/Logical Volume (LVM) Management related commands in Centos/Redhat Linux #DevOps #RHCSA
- On File Systems and Linux Commands (Redhat/CentOs/Fedora)
- Q & A: Linux: Switch Users, Boot Process, File System
Continue the course
Next lesson 02 — NFS and On-Demand Mounting with AutoFS.
Linux course index · Linux Advanced category · Lesson 1 of 9
