Adding a New Disk to an LVM Pool

1 Check Free Space

First you would check to see if the Volume group had any free space using either vgs or vgdisplay

            vgs
        
            VG     PV LV SN Attr   VSize    VFree
            centos   1   2   0 wz--n-  <79.47g    0 #the VFree column is zero, no space
                
            vgdisplay
            --- Volume group ---
              VG Name               centos
            <SNIP>
              VG Size               <79.47 GiB
              PE Size               32.00 MiB
              Total PE              2543
              Alloc PE / Size       2543 / <79.47 GiB
              Free  PE / Size       0 / 0  #The Free PE is Zero, no space left
              VG UUID               y79R98-0yM7-nAZZ-m00t-mhrp-0MgR-vkcbsi
        

Lets check the physical volumes incase we missed some space

            pvs
        
            PV         VG     Fmt  Attr PSize   PFree
            /dev/sda2  centos lvm2 a--  <79.47g    0 #PFree is also zero
          
            --- Physical volume ---
              PV Name               /dev/sda2
              VG Name               centos
              PV Size               <79.50 GiB / not usable 30.00 MiB
              Allocatable           yes (but full)
        
              PE Size               32.00 MiB
              Total PE              2543
              Free PE               0 #Free PE is zero here
              Allocated PE          2543
              PV UUID               LVA29B-NcbK-Teg6-AMnU-iJWQ-Nyhw-e9Apl8
    

So we need a new/bigger disk. If you find some Free PE, you can skip straight to Step 6

2 Partition the new Disk

            fdisk /dev/sdb #repeat this first step for all new disks required (/dev/sdc)
        
  1. Choose n to create new partition
  2. Choose p to create a primary partition.
  3. Choose which number of partition we need to create. 1 is good for a new disk.
  4. Press Enter twice to use the full space of the Disk or free space.
  5. We need to change the type of newly created partition type t.
  6. Which number of partition need to change, choose the number which we created its 1.
  7. Here we need to change the type, we need to create LVM so we going to use the type code of LVM as 8e, if we do not know the type code Press L to list all type codes.
  8. Press P to print the partitions and see what we created to just confirm.
  9. Here we can see the ID as 8e LINUX LVM.
  10. Write the changes (w) and exit fdisk.
fdisk -l #check

3 Add the Physical Volume to LVM (PV)

            pvcreate /dev/sdb1 #/dev/sdc1 /dev/sdd1 # add as applicable
            pvs #check the creation
        

4 Add the new PV to the existing VG

            vgextend centos /dev/sdb1
            
            vgs #we can recheck the VFree value now
        
            VG     PV LV SN Attr   VSize    VFree
            centos   1   2   0 wz--n-  <79.47g    50.00g #the VFree column is zero, no space
        

5 Check the free extents

(best method)

            vgdisplay |grep Free
          Free  PE / Size       1562  / 50.00 GiB 
        

We have 1562 extends now to use

6 Add some extents to a LV

(best method)

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

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

6b Assign ALL free space

(extra lazy method

            lvextend -l +100%FREE /dev/centos/root #assign ALL space to the root
    

7 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       3543 / <110.72 GiB
            df -h
            /dev/mapper/centos-root  xfs      127G   20G   109G    15%   /
        

All good