Rocky Linux 10 Tutorial / Expand LVM logical volumes and XFS
To expand XFS on LVM in Rocky Linux 10, first check whether there is free space in the volume group, then increase the logical volume and also expand the XFS within it. Since logical volume size and file system size are separate, completing only one command successfully does not finish the task. In this article, we observe changes in both layers using a separate new practice disk and confirm PV addition and file preservation.
Roles of PV·VG·LV and XFS
LVM stands for Logical Volume Manager , and it is a function that combines storage devices to create and manage logical volumes. Physical Volume (PV) is the disk or partition used by LVM, the Volume Group (VG) is a pool of space collected from PVs, the Logical Volume (LV) is the block device allocated from that pool, and XFS is the file system that manages files within the LV.
| Hierarchy | Check command | Changes in this practice |
|---|---|---|
| PV · Physical Volume | pvs |
Use the first partition of the new disk, and add the second partition later. |
| VG · Volume Group | vgs |
Check the total and remaining allocated space of a separate lfvg23 group. |
| LV · Logical Volume | lvs, blockdev |
Expand /dev/lfvg23/data from 512 MiB → 1 GiB → 2 GiB. |
| XFS | xfs_info, df |
Expand the mounted file system to fit the larger LV. |
The remaining space in the VG, VFree, is space that has not yet been allocated to LV, and the free space in df is space available for use by files within an already created file system. The two values are not the same. PV, VG, and LV sizes may not exactly match the raw disk size due to metadata and allocation units.
The source lab used Rocky Linux 10.2, kernel 6.12.0-211.74.1.el10_2.x86_64, LVM2 2.03.36, and xfsprogs 6.16.0. Commands were executed on a Linux guest in a dedicated VirtualBox VM. The existing system VG rlm and the XFS data disks used in lessons 21 and 22 are not modified.
Distinguishing the new LVM-only disk and limiting the scope of practice
Use the new-disk identification procedure to verify serial number, capacity and existing use. The source lab created a new 4 GiB VDI, separate from its two existing disks. Its device was /dev/sdc, serial VBf1474d25-73f824a7, size 4294967296 bytes. The device name alone does not identify the target.
lsblk -b -o NAME,PATH,TYPE,SIZE,SERIAL,FSTYPE,MOUNTPOINTS
findmnt /
swapon --show
sudo pvs -o pv_name,pv_uuid,vg_name,pv_size,pv_free
sudo vgs -o vg_name,vg_uuid,vg_size,vg_free
sudo lvs -o lv_name,vg_name,lv_uuid,lv_size,lv_path
rpm -q lvm2 xfsprogs parted
For the practice, we use one new disk divided into two partitions of about 2 GiB each. Since this is practice for adding PVs using two partitions on the same disk, it does not create a configuration that provides redundancy against disk failure. Even when adding a new physical disk in actual operation, it is necessary to separately check the unique identification of the disk and whether the data should be preserved.
The LVM commands below specify --devices. This option designates the device used by the command and replaces the selection of the default devices file. It does not involve deleting the existing system device list or disabling global filters. Once the VG has two PVs, both PVs must be specified separated by a comma. The LVM devices manual explains device selection.
Setting automatic activation after reboot for a practice VG created in this way is outside the scope of the text. The practice PV is not registered in the default device list, and the entire process is completed in a single runtime environment covering creation, expansion, verification, and cleanup. If commands are resumed in a new terminal, device variables must be set to the actual values again.
Creating dedicated PV, VG, 512 MiB LV, and XFS
Save the entire example below in ~/lf-lvm23-create.sh. DISK and SERIAL are the actual values used in practice and should be replaced with the values confirmed in your own environment. Once the check passes, write operations that create the partition table, PV, VG, LV, and XFS will be executed. Do not apply this to a disk with existing data or to a system VG.
#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
DISK=/dev/disk/by-id/ata-VBOX_HARDDISK_VBf1474d25-73f824a7
SERIAL=VBf1474d25-73f824a7
REAL=$(readlink -f -- "$DISK")
test -b "$REAL"
test "$(lsblk -dn -o TYPE "$REAL")" = disk
test "$(lsblk -bdn -o SIZE "$REAL" | xargs)" = 4294967296
test "$(lsblk -dn -o SERIAL "$REAL" | xargs)" = "$SERIAL"
test "$(lsblk -nr -o NAME "$REAL" | wc -l)" -eq 1
MOUNTS=$(lsblk -dn -o MOUNTPOINTS "$REAL")
test -z "$MOUNTS"
HOLDERS=$(find "/sys/class/block/${REAL##*/}/holders" -mindepth 1 -maxdepth 1 -print -quit)
test -z "$HOLDERS"
SIGNATURES=$(wipefs --no-act --noheadings --output TYPE "$REAL")
test -z "$SIGNATURES"
ROOT_SOURCE=$(findmnt -nro SOURCE /)
ROOT_DEVICES=$(lsblk -snpr -o NAME "$ROOT_SOURCE")
if printf '%s\n' "$ROOT_DEVICES" | grep -Fxq -- "$REAL"; then
echo 'Refusing the root disk' >&2
exit 1
fi
KNOWN_VGS=$(vgs --noheadings -o vg_name)
if printf '%s\n' "$KNOWN_VGS" | grep -wq lfvg23; then
echo 'The lab VG name already exists' >&2
exit 1
fi
test ! -e /mnt/lf-lvm23
test ! -e /root/lf-course23-before
mkdir -m 700 /root/lf-course23-before
cp -a /etc/lvm /root/lf-course23-before/lvm
cp -a /etc/fstab /root/lf-course23-before/fstab
parted --script --align optimal "$DISK" mklabel gpt
parted --script --align optimal "$DISK" mkpart pv23a 1MiB 2049MiB
parted --script --align optimal "$DISK" mkpart pv23b 2049MiB 100%
parted --script "$DISK" set 1 lvm on
parted --script "$DISK" set 2 lvm on
partprobe "$DISK"
udevadm settle
parted --script "$DISK" align-check optimal 1
parted --script "$DISK" align-check optimal 2
P1=${DISK}-part1
pvcreate --devices "$P1" "$P1"
vgcreate --devices "$P1" lfvg23 "$P1"
lvcreate --devices "$P1" -L 512M -n data lfvg23
mkfs.xfs -L lfdata23 /dev/lfvg23/data
mkdir -m 755 /mnt/lf-lvm23
mount -t xfs /dev/lfvg23/data /mnt/lf-lvm23
printf 'lvm23-preserved\n' > /mnt/lf-lvm23/probe.txt
sha256sum /mnt/lf-lvm23/probe.txt
After confirming that the disk is new and contains no data, proceed by separating syntax checks from actual execution.
bash -n ~/lf-lvm23-create.sh
sudo bash ~/lf-lvm23-create.sh
For this new disk, the first partition was created from 1 to 2049 MiB, and the second from 2049 to approximately 4095 MiB, passing both alignment checks. First, only the first partition was initialized as a PV. Just setting the partition flag in lvm does not create a PV. Actual PV initialization is performed with pvcreate , and it is not executed with the force option on a device with existing data.
The variables below are redefined in the current general user shell after the script above finishes. They will also be used in the same shell later.
DISK=/dev/disk/by-id/ata-VBOX_HARDDISK_VBf1474d25-73f824a7
P1=${DISK}-part1
P2=${DISK}-part2
sudo pvs --devices "$P1" -o pv_name,pv_uuid,vg_name,pv_size,pv_free
sudo vgs --devices "$P1" -o vg_name,vg_uuid,vg_size,vg_free
sudo lvs --devices "$P1" -o lv_name,vg_name,lv_uuid,lv_size,lv_path
findmnt --mountpoint /mnt/lf-lvm23 -o TARGET,SOURCE,FSTYPE,UUID
sudo blockdev --getsize64 /dev/lfvg23/data
df -B1 -T /mnt/lf-lvm23
For this VG, about 1.5 GiB of the approximately 2 GiB remained, and the LV was exactly 536,870,912 bytes. The SHA-256 of the test file is 8e0a10d58418b0b91812822dcc2979a9e24182606484f7f00a943e0fd9a96eef. Recording the VG UUID, LV UUID, and filesystem UUID can reduce the need to estimate the target by name alone when resuming or cleaning up.
This example assumes a separate practice VG based on a regular block device. It is not a general-purpose script that automatically detects operational configurations using RAID, multipath, encryption, thin pools, etc. If the structure is different, such as if the existing VG is hidden outside the default devices list, you need to additionally investigate device and name conflicts.
Observe LV expansion and XFS expansion separately.
First, increase only the LV by 512 MiB within the free space of the VG. The plus sign in -L +512M means adding to the current size, and -L 1G indicates specifying the final size as 1 GiB. Confusing these two formats in operation may result in increasing more than needed or requesting an incorrect size.
sudo lvextend --devices "$P1" -L +512M /dev/lfvg23/data
sudo blockdev --getsize64 /dev/lfvg23/data
df -B1 -T /mnt/lf-lvm23
The LV has become 1,073,741,824 bytes, but the file system size in df remains the same. Next, expand the mounted XFS. xfs_growfs assumes the XFS to be expanded is mounted, and here you specify the mount point.
sudo xfs_growfs /mnt/lf-lvm23
sudo xfs_info /mnt/lf-lvm23
df -B1 -T /mnt/lf-lvm23
sudo sha256sum /mnt/lf-lvm23/probe.txt
In the source lab, the number of XFS data blocks increased from 131,072 to 262,144, and the test file hash was the same. The premise of logical volume expansion can be confirmed in lvextend manual , and the mount and expansion behavior of XFS can be confirmed in xfs_growfs manual .
| Observation Point | LV Byte Size | df's 1B-blocks |
|---|---|---|
| First 512 MiB | 536,870,912 | 469,762,048 |
| Extend only LV to 1 GiB | 1,073,741,824 | 469,762,048 · No change |
| Also extend XFS | 1,073,741,824 | 1,006,632,960 |
| Extend both LV and XFS to 2 GiB | 2,147,483,648 | 2,080,374,784 |
This is the actual value for this environment. The space displayed by df reflects calculations of internal logs and other file system spaces, so it may not equal the total size of the block device. Rather than expecting this number to appear in all environments, compare the changes when only the LV is increased versus when XFS is also expanded under the same conditions.
Add the PV to the VG and extend both layers together.
If the VG is too small to expand the LV as desired, you need to secure space for the VG first. Here, we create the second prepared empty partition as a PV and add it to the same VG. Do not rerun the command that initialized the first PV.
sudo wipefs --no-act "$P2"
sudo pvcreate --devices "$P2" "$P2"
DEVICES=$P1,$P2
sudo vgextend --devices "$DEVICES" lfvg23 "$P2"
sudo pvs --devices "$DEVICES" -o pv_name,pv_uuid,vg_name,pv_size,pv_free
sudo vgs --devices "$DEVICES" -o vg_name,vg_uuid,vg_size,vg_free
sudo lvs --devices "$DEVICES" -o lv_name,vg_name,lv_size
If an unexpected signature appears on the second partition, stop before pvcreate. After the actual vgextend, the VG size became about 3.99 GiB, with roughly 2.99 GiB free, but the LV remained 1 GiB. The vgextend manual describes adding PVs to a VG. This operation does not itself enlarge the LV or filesystem.
This time, using --resizefs, request LV and file system expansion together. Adding 1 GiB to the current 1 GiB LV results in a final size of 2 GiB.
sudo lvextend --devices "$DEVICES" --resizefs -L +1G /dev/lfvg23/data
sudo blockdev --getsize64 /dev/lfvg23/data
sudo lvs --devices "$DEVICES" -o lv_name,vg_name,lv_size
df -B1 -T /mnt/lf-lvm23
sudo xfs_info /mnt/lf-lvm23
sudo sha256sum /mnt/lf-lvm23/probe.txt
In actual execution, LVM called the XFS resize command, and the number of data blocks increased to 524,288. The source lab checked the changes in LV and XFS sizes and file hashes individually. Even if requested with a single command, the file system expansion part can fail, so if it fails, recheck the current LV size and file system size. Do not reduce it first thinking you will revert an LV that has already been expanded.
Requests larger than the available space in the VG should also be distinguished. This time, when requesting an additional 10 GiB with about 1.99 GiB of remaining space, it failed with Insufficient free space and exit code 5, and the LV remained 2 GiB. We do not reformat partitions or PVs to resolve this failure. First, determine whether additional PVs, device size expansion, or allocation planning is required.
Do not assume reduction and rollback are simply the reverse of expansion.
If you reduce an LV first when there are few files, you can cut the space referenced by the file system and cause corruption. Do not use lvreduce as a simple cancel command for expansion. Independent data backups and actual restoration verification are required even before expansion.
Do not assume that XFS can never shrink under any circumstances on Rocky Linux 10. The official Rocky Linux 10.1 announcement describes limited shrinking with xfs_growfs in some situations. The source lab's installed xfsprogs 6.16.0 manual also describes restrictions: shrinking must not remove the last allocation group (AG), and single-AG filesystems have additional limitations.
Such limited functionality does not guarantee reduction to arbitrary sizes or the safe recovery of the operating environment. This tutorial did not perform reduction. If you plan to move to a smaller storage space, check the support range and file system structure of that version and also consider a migration plan that restores backups to a new file system for verification.
Verification of practice data and cleaning of dedicated resources
After expansion, even if you unmount and remount, check whether the test files can be read. First, exit the shell and programs using the corresponding directory. In actual practice, after remounting, the contents lvm23-preserved matched the original hash.
cd /
sudo umount /mnt/lf-lvm23
sudo mount -t xfs /dev/lfvg23/data /mnt/lf-lvm23
sudo cat /mnt/lf-lvm23/probe.txt
sudo sha256sum /mnt/lf-lvm23/probe.txt
The following cleanup is a destructive operation that removes the lab LV lfvg23/data, VG lfvg23, and both lab PVs created during the exercises. Do not execute it if you plan to continue using the data. Proceed only when the VG and LV UUIDs recorded at creation, the current output, disk serial numbers, and mount sources all match, and any necessary data has been separately backed up. Do not change the names to rlm/root or another VG and run it.
sudo vgs --devices "$DEVICES" -o vg_name,vg_uuid,vg_size,vg_free
sudo lvs --devices "$DEVICES" -o lv_name,vg_name,lv_uuid,lv_size
sudo pvs --devices "$DEVICES" -o pv_name,pv_uuid,vg_name
sudo cp -a /mnt/lf-lvm23/probe.txt /root/lf-course23-before/probe.txt
sudo vgcfgbackup --devices "$DEVICES" -f /root/lf-course23-before/lfvg23-after-growth.vg lfvg23
cd /
sudo umount /mnt/lf-lvm23
sudo lvremove --devices "$DEVICES" /dev/lfvg23/data
sudo vgremove --devices "$DEVICES" lfvg23
sudo pvremove --devices "$DEVICES" "$P1" "$P2"
sudo rmdir /mnt/lf-lvm23
vgcfgbackup is a VG metadata backup, not a backup of file contents. In the exercises, test files were also separately backed up, and only the dedicated resources were removed. Removing the PV signature does not mean safely erasing the entire disk. The GPT and two partitions of the new disk remain, and the existing system disk and XFS data disk are preserved.
After cleanup, compare the existing system configuration and UUID again in the default pvs, vgs, and lvs. In the source verification, the existing system LV information, partition tables of the two existing disks, fstab, and the contents of 13 existing LVM configuration and metadata files were the same as before the operation. The metadata records of the new practice VG were retained as exercise materials.




