Skip to content
Search Rocky Linux

    Browse this documentation

    Rocky 9: grow an LVM volume and XFS (tested)

    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.

    Terminal window
    lvcreate -y -Z n -L 1G -n lvdata vglab
    dmsetup mknodes
    ls /dev/mapper/
    /dev/mapper/vglab-lvdata

    Without 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.

    Terminal window
    sudo dnf install -y lvm2 xfsprogs
    truncate -s 2G /var/tmp/lvm-lab.img
    LOOP=$(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 vglab
    sudo dmsetup mknodes
    sudo 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.

    Terminal window
    sudo mount /dev/mapper/vglab-lvdata /mnt/lvmlab
    df -h /mnt/lvmlab | tail -1
    sudo lvextend -L +512M /dev/mapper/vglab-lvdata
    df -h /mnt/lvmlab | tail -1
    /dev/mapper/vglab-lvdata 960M 39M 922M 5% /mnt/lvmlab
    Logical volume vglab/lvdata successfully resized.
    /dev/mapper/vglab-lvdata 960M 39M 922M 5% /mnt/lvmlab

    Growing only the LV leaves df unchanged — the step most often missed.

    Terminal window
    sudo xfs_growfs /mnt/lvmlab | tail -1
    df -h /mnt/lvmlab | tail -1
    data blocks changed from 262144 to 393216
    /dev/mapper/vglab-lvdata 1.5G 43M 1.4G 3% /mnt/lvmlab

    xfs_growfs takes the mount point; ext4 needs resize2fs <device> instead.

    Terminal window
    sudo umount /mnt/lvmlab
    sudo dmsetup remove vglab-lvdata
    sudo vgremove -y vglab
    sudo pvremove -y "$LOOP"
    sudo losetup -d "$LOOP"
    rm -f /var/tmp/lvm-lab.img

    In a container remove the dm device before vgremove, otherwise the loop device stays busy and losetup -d fails.

    • lvextend without xfs_growfs: df keeps the old value;
    • Forgetting dmsetup mknodes in a container: both mkfs and mount report a missing device;
    • Trying to shrink XFS: unsupported — back up and recreate.

    On any Rocky 9 (or AlmaLinux 9) host:

    Terminal window
    sudo dnf install -y lvm2 xfsprogs
    truncate -s 2G /var/tmp/lab.img
    LOOP=$(sudo losetup -f --show /var/tmp/lab.img)
    sudo pvcreate -y "$LOOP" && sudo vgcreate vglab "$LOOP"
    sudo lvcreate -y -L 1G -n lvdata vglab
    sudo mkfs.xfs -q /dev/vglab/lvdata
    sudo mkdir -p /mnt/lvmlab && sudo mount /dev/vglab/lvdata /mnt/lvmlab
    sudo lvextend -L +512M /dev/vglab/lvdata && sudo xfs_growfs /mnt/lvmlab
    df -h /mnt/lvmlab

    Checks:

    1. lvs vglab → 1.50g
    2. df -h /mnt/lvmlab → about 1.5G
    3. xfs_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.