Extending an LVM volume: Physical volumes (partitions) -> Volume groups -> Logical volume -> Filesystem

Logical Volume Management (AKA LVM) is for managing storage space.
In Centos, instead of installing the root filesystem directly to a fixed size partition, we setup LVM by default, and install the root filesystem to a Logical Volume, which may later be expanded, even across multiple physical devices.

How LVM works
In LVM, there are several layers, each builds on top of the other:

PV[s] (Physical Volumes) -> VG[s] (Volume Groups) -> LV[s] (Logical Volumes) -> Filesystems.

Logical Volumes are allocated/extended within the boundaries of their underlying storage pool which is called a Volume Group in LVM terminology.

For example, in Centos the filesystem is installed by default to the /dev/vg_prd00/lv_root Logical Volume, which is allocated within the vg_prd00 Volume Group:

— Logical volume —
LV Name /dev/vg_prd00/lv_root
VG Name vg_prd00
LV UUID —-uuid—-
LV Write Access read/write
LV Status available
# open 1
LV Size 50 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
Out of the box the vg_prd00 Volume Group might not have enough free space for you:

# vgdisplay
— Volume group —
VG Name vg_prd00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 63.51 GiB
PE Size 4.00 MiB
Total PE 16258
Alloc PE / Size 16258 / 63.51 GiB
Free PE / Size 0 /0
VG UUID —-uuid—-
We can only extend a Logical Volume within the free space of the underlying Volume Group. How much free space we currently have within the Volume Group can be seen in this part of the output:

Free PE / Size 165 / 660.00 MiB
In the above example we only have 660 MB to allocate to LVMs within the vg_prd00 Volume Group. So if we want to extend the root LV we’ll have to first extend the VG backs it up.

Volume Groups group together Physical Volumes. That’s why they’re called Volume Groups. This command will show us which Physical Volumes have been registered into LVM, and to which volume groups they have been assigned:

# pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name vg_prd00
PV Size 18.15 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4645
Free PE 165
Allocated PE 4480
PV UUID —-uuid—-
In this example we only have one Physical Volume (the /dev/sda2 partition) in the turnkey Volume Group.

Extending a Logical Volume
Bottom line: if the underlying Volume Group doesn’t have enough free space, to extend the Logical Volumeyou’ll first have to extend the underlying Volume Group by adding another Physical Volume to it.

In VMWare you could either create a new virtual hard disk device to add to the volume group, or extend an existing virtual hard disk device, create a new partition with cfdisk, and add the new partition to the Volume Group:

# example #1: you’ve added to VMWare a new virtual hard disk called /dev/sdb
pvcreate /dev/sdb
vgextend vg_prd00 /dev/sdb

# example #2: you’ve expanded the existing sda hard disk
cfdisk /dev/sda # creating /dev/sda3 (you need to reboot before you can see this)
pvcreate /dev/sda3
vgextend vg_prd00 /dev/sda3
After you’ve extended the Volume Group, you are free to extend the underlying Logical Volume:

# lvextend -L+10G /dev/vg_prd00/root
Extending logical volume root to XXXX GiB
Logical volume root successfully resized
Finally, you’ll have to resize the filesystem within /dev/turnkey/root so it can see that the underlying block device just got 10G bigger:

# resize2fs /dev/vg_prd00/root
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/vg_prd00/root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_prd00/root to XXXX (4k) blocks.
The filesystem on /dev/vg_prd00/root is now XXXX blocks longer.

#xfs_growfs /dev/vg_*name*/lv_*name*

Leave a Reply

Your email address will not be published.