Grow a volume with the filesystem still mounted
Task
Build the full LVM stack from loop devices, fill a volume, then extend it and its filesystem online -- and demonstrate the two-layer trap by extending the volume without the filesystem first.
Steps
- Create physical volumes on two of the loop devices with
pvcreate, and confirm withpvs. - Create a volume group from them:
vgcreate labvg /dev/loop0 /dev/loop1. Check the free space withvgs. - Create a 300M logical volume, format it xfs, and mount it at
/mnt/lab. - Fill it to about 90% with
ddfrom/dev/zeroand confirm withdf -h. - Now make the classic mistake deliberately:
lvextend -L +100MWITHOUT-r. Rundf -hand observe that the filesystem is unchanged. Explain the two layers. - Complete it properly with
xfs_growfs /mnt/lab-- note that it takes the MOUNT POINT, not the device -- and confirmdfnow shows the new size. - Add the third loop device to the group with
pvcreateandvgextend, and confirm the free extents increased. This is the answer to "the volume group is full". - Try
lvreduceon the xfs volume and read the refusal.
Verify
vgs labvg -o vg_name,vg_size,vg_free --noheadings
lvs labvg -o lv_name,lv_size --noheadings
df -h /mnt/lab | tail -1
xfs_info /mnt/lab | head -2
mount | grep -q '/mnt/lab' && echo "still mounted throughout"
The volume size from lvs and the filesystem size from df must agree after step 6 and must DISAGREE after step 5. That disagreement is the thing to be able to recognise.
Notes
Clean up by unmounting, vgremove labvg, pvremove each device and losetup -d each loop, then delete the image files. Doing the teardown is worth the two minutes -- an orphaned volume group on loop devices reappears confusingly after a reboot.