Grow a volume with the filesystem still mounted

short · 30 min · Objective 1.3

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

  1. Create physical volumes on two of the loop devices with pvcreate, and confirm with pvs.
  2. Create a volume group from them: vgcreate labvg /dev/loop0 /dev/loop1. Check the free space with vgs.
  3. Create a 300M logical volume, format it xfs, and mount it at /mnt/lab.
  4. Fill it to about 90% with dd from /dev/zero and confirm with df -h.
  5. Now make the classic mistake deliberately: lvextend -L +100M WITHOUT -r. Run df -h and observe that the filesystem is unchanged. Explain the two layers.
  6. Complete it properly with xfs_growfs /mnt/lab -- note that it takes the MOUNT POINT, not the device -- and confirm df now shows the new size.
  7. Add the third loop device to the group with pvcreate and vgextend, and confirm the free extents increased. This is the answer to "the volume group is full".
  8. Try lvreduce on 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.