Skip to content

Resizing LVM

Grow lv

See also ./crytpsetup.md for growing encrypted LVM partions

Grow physical volume (eventually):

sudo pvresize /dev/sdx

Then grow logical volume:

sudo lvextend --resizefs --size +40G ubuntu-vg/home

or extend with max available free space on vg:

sudo lvextend --resize -l +100%FREE VolGroup00/LogVol00

If the automatic filesystem resize with --resize didn't work:

sudo resize2fs /dev/mapper/ubuntu--vg-home

grow lv to max

lvresize -l +100%FREE VolGroup00/LogVol00

Shrink PV

Example: Disk was cloned to slightly smaller disk:

WARNING: Device /dev/mapper/dapple has size of 468356272 sectors which is smaller than corresponding PV size of 487890944 sectors. Was device resized?

Show where segments were allocated:

pvs -v --segments /dev/mapper/dapple

Swap partition was at end of disk so we remove it before shrinking:

lvremove /dev/albatros-vg/swap_1

Now shrink to much less than actual disk size:

pvresize --setphysicalvolumesize 220g /dev/mapper/dapple

And then grow to max:

pvresize /dev/mapper/dapple

Shrink logical volume

  • Online shrinking is not supported
  • Offline shrinking with live CD

Boot from live cd, then:

cryptsetup luksOpen /dev/sda3 sda3_crypt
lvchange -ay dapple-vg/root

Use --resizefs support in lvreduce

First check the file system:

e2fsck -f /dev/dapple-vg/root

Then reduce the lv including the file system in one command:

lvreduce --resizefs -L 64M vg00/lvol1

Manually check, shrink and grow filesystem

e2fsck -f /dev/dapple-vg/root

# resize to ~90% of the desired size for safety
resize2fs /dev/dapple-vg/root 180G

lvreduce -L 200G /dev/dapple-vg/root

# Finally resize to the whole lv size
resize2fs /dev/dapple-vg/root