cloud cloud cloud

anntoin.com

Resizing LVM Logical Volumes

previous

Resizing LVM Logical Volumes

Resizing Logical Volumes is quite easy to do, but like all major modifications due care must be taken. I can’t stress enough how important it is to have a backup of your data.

This post is intended to be a simple guide for this common action. If you are unfamiliar with LVM or concepts like Logical Volumes and Volume Groups here is a thorough guide to LVM.

If your filesystem is supported by fsadm (ext2,ext3,ext4,ReiserFS and XFS) you can use the -r option of lvextend or lvreduce to resize the underlying filesystems for you all in one step. However, if your filesystem is not supported by fsadm, you will have to resize your filesystem manually, so for example to shrinking the rough steps are: umount, fsck, resize the filesystem, then lvreduce.

Key
Volume Group
Logical Volume
Filesystem
Used Space

Growing

  • The first thing we’ll want to do is check the current state of the storage. Use vgs to see how much free space is in the Volume Group and lvs to see the size of the Logical Volumes.1

  • To grow the volume use the command: lvextend -r -L +<size> <volumegroup>/<logicalvolume>. The size can be expressed with a suffix, e.g. lvextend -r -L +5G … Note: If no size argument is given the default is to the size of the volume, or partition.2

Shrinking

Shrinking is a little more involved than growing. Be aware that the filesystem will be temporarily unmounted by these commands.

  • Use df -h to see how much space is used in your filesystem. Here we have a underutilised filesystem we wish to shrink. 3

  • lvreduce -r -L -<size> <volumegroup>/<logicalvolume>


  1. There are other tools such as vgdisplay and lvdisplay but I find their output a little verbose. There is also a graphical tool system-config-lvm, but that may not be an option in your environment.

  2. Resizing granularity is Extent size (the defaults of 4M are fine for most cases).

  3. Note df is not always correct, see: http://serverfault.com/questions/232525/df-in-linux-not-showing-correct-free-space-after-file-removal, and http://www.c0t0d0s0.org/archives/6168-df-considered-problematic.html

next