How to Extend an LVM Logical Volume and Filesystem on CentOS

Logical Volume Management (LVM) makes Linux storage flexible. By default, CentOS installs the root filesystem on an LVM logical volume instead of a fixed-size partition, so you can grow it later, even across multiple physical disks. This guide explains how the LVM layers fit together and walks through extending a logical volume and its filesystem.

How LVM Works

LVM is built in layers, each on top of the last:

Physical Volumes (PV) → Volume Groups (VG) → Logical Volumes (LV) → Filesystems

A logical volume can only be allocated or extended within the free space of its volume group, which acts as the storage pool. For example, the root filesystem here lives on /dev/vg_prd00/lv_root inside the vg_prd00 volume group (lvdisplay output):

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

Check Free Space in the Volume Group

Out of the box, the volume group may not have enough free space:

# vgdisplay
  --- Volume group ---
  VG Name               vg_prd00
  Format                lvm2
  VG Access             read/write
  VG Status             resizable
  Cur LV                3
  Open LV               3
  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----

The Free PE / Size line tells you how much you can allocate. If it reads, say, 165 / 660.00 MiB, you only have 660 MB to give to logical volumes. To grow the root LV beyond that, you first have to extend the volume group.

Volume groups are made of physical volumes. This shows which physical volumes LVM knows about and which group each belongs to:

# 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----

Step 1: Add a Physical Volume to the Volume Group

If the volume group is short on space, add another physical volume. In VMware you can either add a new virtual disk or expand the existing one and create a new partition:

# Example 1: you added a new virtual hard disk, /dev/sdb
pvcreate /dev/sdb
vgextend vg_prd00 /dev/sdb

# Example 2: you expanded the existing sda disk
cfdisk /dev/sda   # create /dev/sda3 (reboot before it shows up)
pvcreate /dev/sda3
vgextend vg_prd00 /dev/sda3

Step 2: Extend the Logical Volume

# lvextend -L+10G /dev/vg_prd00/lv_root
Extending logical volume lv_root to XXXX GiB
Logical volume lv_root successfully resized

Step 3: Grow the Filesystem

Finally, resize the filesystem so it can use the extra 10 GB. For ext3/ext4:

# resize2fs /dev/vg_prd00/lv_root
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/vg_prd00/lv_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/lv_root to XXXX (4k) blocks.
The filesystem on /dev/vg_prd00/lv_root is now XXXX blocks long.

For XFS (the default on CentOS 7 and later):

xfs_growfs /dev/vg_name/lv_name

Also see adding a disk to CentOS LVM.