Expand storage with LVM.

RHEL 7.
I have a RHEL 7 base image installed. I only have one disk and the partitioning looks like this:



lvm> pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sda2  rhel lvm2 a--  19.51g    0 
lvm> vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  rhel   1   2   0 wz--n- 19.51g    0 
lvm> lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 17.51g                                             
  swap rhel -wi-ao----  2.00g                                             
lvm> 

I am going to add a new disk 20G in size.

lvm> pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
lvm> pvs
  PV         VG   Fmt  Attr PSize  PFree 
  /dev/sda2  rhel lvm2 a--  19.51g     0 
  /dev/sdb1       lvm2 a--  20.00g 20.00g
lvm> 

I want to expand my volume group 'rhel' to use the extra 20G

lvm> vgextend rhel /dev/sdb1
  Volume group "rhel" successfully extended
lvm> vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  rhel   2   2   0 wz--n- 39.50g 20.00g
lvm> 

I want to increase the size of my volume by 10G and create a new one of 5G.
"-L" to specify the new size.

lvm> lvextend -L 27G /dev/rhel/root
  Extending logical volume root to 27.00 GiB
  Logical volume root successfully resized
lvm>  lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 27.00g                                             
  swap rhel -wi-ao----  2.00g                                             
lvm> 

After expanding the volume, the next step is to resize the filesystem inside the volume. This can be done using the tools provided by the filesystem itself, or using '-r' with lvextend.

Now I create a new volume.

lvm> lvcreate rhel -n new_volume -L 5G
  Logical volume "new_volume" created
lvm> lvs
  LV         VG   Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  new_volume rhel -wi-a-----  5.00g                                             
  root       rhel -wi-ao---- 27.00g                                             
  swap       rhel -wi-ao----  2.00g                                             
lvm> 

'-n' to specify the name, otherwise it gets assigned a name authomatically. -L to specify the size, rhel is the volume group that will contain the new volume.

I can now format and mount the new volume:

# mkfs.xfs /dev/mapper/rhel-new_volume 
# mount /dev/mapper/rhel-new_volume /mnt

To mount during boot, add entry to fstab.

Now, my root partition is still 18G although I've extended the volume to 27G.

# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root         18G  975M   17G   6% /

This is a xfs file system, therefore I used:

# xfs_growfs /
# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root         27G  975M   27G   4% /

All done.