Notes on how to extend LVM partitions. I do this so infrequently that I forget how and have to look up the steps all the time. These are my own notes so that next time I will at least follow the same steps.

Assess Current Partition Space

Nagios just gave me warning notification my /usr partition has less than 20% free space. To check if that is accurate, I use the ‘df’ command with the file system in question. Unsurprisingly the alert seems accurate, and since this is a repeat alert, only temporarily addressed by freeing up space by hand, it is time to extend the partition on the volume.

$ df -h /usr
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-1        35G   27G  5.8G  83% /usr
$

Is There Unused Space Available?

Now it is time to display the volume group details, and see what I have yet to use. To do this I use the ‘vgdisplay’ command with the volume name. In this case it looks like I have in excess of 500GiB of unallocated space.

$ sudo vgdisplay vg
  --- Volume group ---
  VG Name               vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  42
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                8
  Open LV               7
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <1.82 TiB
  PE Size               4.00 MiB
  Total PE              476644
  Alloc PE / Size       338964 / 1.29 TiB
  Free  PE / Size       137680 / 537.81 GiB
  VG UUID               BMcdOB-vY2o-tZim-7DRU-BJBu-41hz-j9ed80
   
$

Increase Partition Size with LVMExtend

I think I will add 10GiB to the partition, leaving free space closer to 40% and silencing the Nagios complaint. This is done using the lvmextend command as seen below.

$ sudo lvextend -L +10G /dev/mapper/vg-usr 
  Size of logical volume vg/usr changed from 35.00 GiB (8960 extents) to 45.00 GiB (11520 extents).
    Logical volume vg/usr successfully resized.
$ 

Resize the File System

The file system needs to be resized to take advantage of the additional partition space. The ‘resize2fs’ command is ideal for this purpose.

$ sudo resize2fs /dev/mapper/vg-usr
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mapper/vg-usr is mounted on /usr; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/mapper/vg-usr is now 11796480 (4k) blocks long.

$ 

Validate Results

Run the ‘df’ command again to make sure change is as expected.

$ df -h /usr
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-1        45G   27G   16G  64% /usr
$

All is well, and until next time, peace out.