Skip to main content

LVM - extend the volume

To extend the volume, we have to attach new physical (virtual) disk on hypervisor.

Preparations

We need to understand which disk need to be extended: In my case it is a root which is full.

df -h

and verify it is LVM

lsblk

After adding the disk, it should appear in the list:

lsblk

Let's note which file system in use: 'XFS' or 'ext4', will be needed later..

lsblk -f

We are good to go, prepare for activities. Replace your values for variables dev and fs with correct ones. Subtract 0.1 from partition size:

export dev="/dev/sdc"

Disk need to be marked as a "Physical Volume" to be able to join the "volume group" and list:

pvcreate ${dev}
pvscan

First, let's define, which 'volume group' need to be extended

vgscan

In my case, it is ol_vbox. Let's define it:

export vg="ol_vbox"

Let add "new Physical Volume" to the "Virtual Group":

echo ${vg}
echo ${dev}
vgextend ${vg} ${dev}

List Physical Volumes, new disk should be shown

pvscan

Now it is a time to extend Logical Volume. Let's observe current ones first

lvdisplay

In my case, "Volume Group" is linked to "Logical Volume" has path "/dev/ol_vbox/root". Set up extension size.

export lv="/dev/ol_vbox/root"
export size="49.9G"

and extend "Logical Volume"

lvextend -L +${size} ${lv}

Depending on which file system is in use, note current partition size, expand it and check size again:

df -h

# for "ext4"
resize2fx ${lv}

# for "xfs"
xfs_growfs ${lv}

df -h

Q.E.D.

Storage management using LVM is a logical process, once understood.