LVM tips and Hints

Resizing (extending) Logical Volumes and filesystems

Live LogicalVolume and Filesystem extension in a single step (-r)

Determine the free space/extents within the Volume Group

vgdisplay {vgname} | grep Free

Decide if you want to declare the size in relative or absolute terms

lvextend -r /dev/vgroot/lvtmp -L 30G         # set size to 30GB
      or
lvextend -r /dev/vgroot/lvtmp -L +5G         # increase size by 5GB
      or
lvextend -r /dev/vgroot/lvtmp -l +100%FREE   # increase the LV to use up all free extents within the VG

Live LogicalVolume extension with a separate step to extend the filesystem

Determine the free space/extents within the Volume Group

vgdisplay  | grep Free

Extend the Logical Volume

lvextend -L +100MB /dev/vgsys/tmp          # Increase  size by 100MB

Extend the Filesystem to fill the logical Volume

resize2fs /dev/vgsys/tmp                   # optional size parameter

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vgsys/tmp is mounted on /tmp; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vgsys/tmp to 557056 (4k) blocks.
The filesystem on /dev/vgsys/tmp is now 557056 blocks long.

Reconfigure swap

expanding swap

swapoff -a                                   # turn swap off

lvextend  /dev/vgroot/lvswap -L 30G          # set size to 30GB
      or
lvextend  /dev/vgroot/lvswap -L +5G          # increase size by 5GB
      or
lvextend  /dev/vgroot/lvswap -l +100%FREE    # increase the LV to use up all free extents within the VG

mkswap /dev/vgroot/lvswap                    # recreate the swap filesystem

swapon -a                                    # turn swap on

removing swap (to freee up disk for filesystem expansion)

swapoff -a

Edit /etc/fstab && remove the swap line, to stop it from activating upon next boot

/dev/vgsys/swap         swap      swap    defaults        0 0

Remove the swap logical volume

lvremove /dev/vgroot/lvswap

now you can use the swap space for something else

turn the swap back on

swapon -a

show the swap

swapon -s

free -g