Rocky 9: grow an LVM volume and XFS (tested)
Test scope
Section titled “Test scope”Executed in a Rocky Linux 9.8 privileged container (Rocky 9.8 userspace, host kernel 5.14.0-687.54.1.el9_8) with a 2 GB loop file: pvcreate → vgcreate → lvcreate -Z n → dmsetup mknodes → mkfs.xfs → mount → lvextend → xfs_growfs → cleanup. Log: plans/content-expansion/evidence/logs/rocky-storage-lvm.log.
This is not a full virtual machine: the container shares the host kernel and has no udev by default, which is why the dmsetup mknodes step appears below. A real Rocky host does not need it.
Why the extra dmsetup step
Section titled “Why the extra dmsetup step”lvcreate -y -Z n -L 1G -n lvdata vglabdmsetup mknodesls /dev/mapper//dev/mapper/vglab-lvdataWithout udev, lvcreate succeeds but no node appears under /dev/mapper/, so mkfs.xfs /dev/vglab/lvdata fails with “device not found”. dmsetup mknodes creates the node manually. On a real host udev does this automatically.
Create PV/VG/LV and format
Section titled “Create PV/VG/LV and format”sudo dnf install -y lvm2 xfsprogstruncate -s 2G /var/tmp/lvm-lab.imgLOOP=$(sudo losetup -f --show /var/tmp/lvm-lab.img)sudo pvcreate -y "$LOOP"sudo vgcreate vglab "$LOOP"sudo lvcreate -y -Z n -L 1G -n lvdata vglabsudo dmsetup mknodessudo mkfs.xfs -q /dev/mapper/vglab-lvdata-Z n skips the wipe and avoids the container error “device not cleared”; a real host can omit it.
Growing takes two steps
Section titled “Growing takes two steps”sudo mount /dev/mapper/vglab-lvdata /mnt/lvmlabdf -h /mnt/lvmlab | tail -1sudo lvextend -L +512M /dev/mapper/vglab-lvdatadf -h /mnt/lvmlab | tail -1/dev/mapper/vglab-lvdata 960M 39M 922M 5% /mnt/lvmlabLogical volume vglab/lvdata successfully resized./dev/mapper/vglab-lvdata 960M 39M 922M 5% /mnt/lvmlabGrowing only the LV leaves df unchanged — the step most often missed.
Grow the filesystem
Section titled “Grow the filesystem”sudo xfs_growfs /mnt/lvmlab | tail -1df -h /mnt/lvmlab | tail -1data blocks changed from 262144 to 393216/dev/mapper/vglab-lvdata 1.5G 43M 1.4G 3% /mnt/lvmlabxfs_growfs takes the mount point; ext4 needs resize2fs <device> instead.
Clean up
Section titled “Clean up”sudo umount /mnt/lvmlabsudo dmsetup remove vglab-lvdatasudo vgremove -y vglabsudo pvremove -y "$LOOP"sudo losetup -d "$LOOP"rm -f /var/tmp/lvm-lab.imgIn a container remove the dm device before vgremove, otherwise the loop device stays busy and losetup -d fails.
Common traps
Section titled “Common traps”lvextendwithoutxfs_growfs:dfkeeps the old value;- Forgetting
dmsetup mknodesin a container: bothmkfsandmountreport a missing device; - Trying to shrink XFS: unsupported — back up and recreate.
Practice: run a safe grow
Section titled “Practice: run a safe grow”On any Rocky 9 (or AlmaLinux 9) host:
sudo dnf install -y lvm2 xfsprogstruncate -s 2G /var/tmp/lab.imgLOOP=$(sudo losetup -f --show /var/tmp/lab.img)sudo pvcreate -y "$LOOP" && sudo vgcreate vglab "$LOOP"sudo lvcreate -y -L 1G -n lvdata vglabsudo mkfs.xfs -q /dev/vglab/lvdatasudo mkdir -p /mnt/lvmlab && sudo mount /dev/vglab/lvdata /mnt/lvmlabsudo lvextend -L +512M /dev/vglab/lvdata && sudo xfs_growfs /mnt/lvmlabdf -h /mnt/lvmlabChecks:
lvs vglab→ 1.50gdf -h /mnt/lvmlab→ about 1.5Gxfs_info /mnt/lvmlab | grep data→ blocks 393216
常见问题
df did not change after lvextend — did the grow fail?
No. lvextend grows the logical volume (the block device); the filesystem still uses its old size. For XFS run xfs_growfs <mountpoint>, for ext4 resize2fs <device>, and df updates.
mkfs says the device does not exist inside a container?
Containers usually lack udev, so no node appears under /dev/mapper after lvcreate. Run dmsetup mknodes and use /dev/mapper/<vg>-<lv>; a real host does not need this.
Does growing affect running services?
Both lvextend and xfs_growfs work online without unmounting. Still confirm free extents in the VG, verify the mount point, and avoid rebooting or unmounting during the operation.
Next steps
Section titled “Next steps”- Post-install checks: 7 checks after install
- Log rotation: logrotate in practice
- Package management: dnf transaction rollback