Extending an LVM Pool

1 Check that the disk is increased

    fdisk -l #Check disk size

    Disk /dev/sda: 185.9 GB, 199715979264 bytes, 390070272 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000ccef8
    
    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 1050623 524288 83 Linux
    /dev/sda2 1050624 167772159 83360768 8e Linux LVM
  

We now have 100gb unassaigned after our disk was increased

2 ReCreate Partitions to suit the bigger disk

fdisk /dev/sda
  1. Choose d to remove a partition
  2. Choose the LVM partition (2 in this case)
  3. Choose n to create new partition
  4. Choose p to create a primary partition.
  5. Choose the same number of partition we need to create. (2 in this example)
  6. Press Enter twice to use the entire free space.
  7. We need to change the type of newly created partition type t.
  8. Which number of partition need to change, choose the number which we created its 2.
  9. Here we need to change the type, we set it back to LVM (8e).
  10. Press P to print the partitions and see what we created to just confirm.
  11. Here we can see the ID as 8e LINUX LVM.
  12. Write the changes (w) and exit fdisk.

If fdisk -l now shows the correct layout, you can continue, else reboot.

3 Resize the PV to include the new space

pvs # You will see it has not changed yet, still 79GB
PV         VG     Fmt  Attr PSize   PFree
/dev/sda2  centos lvm2 a--  <79.47g    0
            
pvresize /dev/sda2 
#Request PV to resize to suit new sda partition
pvs # The PV is now 179GB
PV         VG     Fmt  Attr PSize   PFree
/dev/sda2  centos lvm2 a--  <178.37g    99.72g

4 Check the free extents

vgdisplay |grep Free
Free  PE / Size       3124/ 99.72 GiB 

We have 3124 extends now to use

5 Add extents to a LV

lvextend -l +1000 /dev/centos/root
#add 1000 of them too a logical volume called root
#The remaining 2124 (64gb) are saved for later

5a Add the free space to a LV

(lazy method)
lvextend -L +50GB /dev/centos/root 
#add 50GB of to a logical volume called root
#You may have to fiddle with the numbers to get the right space added

5b Assign ALL free space

(extra lazy method)
lvextend -l +100%FREE /dev/centos/root #assign ALL space to the root

6 Resize the filesystem to use the available space

resize2fs /dev/centos/root #this can be done without unmounting

8 Confirm changes took effect

lvdisplay |grep Size
            
Alloc PE / Size       4093 / <131.72 GiB
            
df -h
/dev/mapper
/centos-root  xfs      131G   20G   109G    15%   
/

All good!