On thy fly resize of root volume (LVM & XFS on CentOS 7) 1


To be able to resize the root partition quickly, use LVM. The following part of kickstart configuration sets up 1 GB /boot (non-LVM) partition on /dev/sda1 and root partition on /dev/sda2 (LVM).

zerombr
clearpart --all --initlabel --drives=sda

part /boot --fstype="xfs" --ondisk=sda --size=1024
volgroup cl --pesize=4096 pv.10
part pv.10 --fstype="lvmpv" --ondisk=sda --grow
logvol / --fstype="xfs" --size=1 --grow --name=root --vgname=cl

Then anytime you increase the size of the disk (probably from some management of VM), just execute following on running guest to immediately resize the volume.

# Automatically resize/grow the 2nd partition (disk is formatted with MBR so using sfdisk)
echo ",+" | sfdisk --force --unit B -N 2 /dev/sda

# Try reread partition table and notify kernel of changes
# Ignore reported warnings/errors as mentioned by Red Hat: https://access.redhat.com/solutions/199573
partprobe
partx --update /dev/sda

# Actual resizing of LVM/XFS
pvresize /dev/sda2
lvresize --extents +100%FREE --resizefs /dev/cl/root

Of course for different configurations, the names of devices/partitions/volumes will be different but here listed example works with above kickstart.


Leave a comment

One thought on “On thy fly resize of root volume (LVM & XFS on CentOS 7)