Ubuntu – How to resize an LVM partition? (i.e: physical volume)

gpartedlvmpartitioning

I want to shrink my second (LVM) partition, in order to create a new partition in the newly freed space. I am using the Live CD to do so, because I know I can't resize/move this partition while it is in use. When I opened GParted in the Live CD, I realized that I could not resize the partition, because when I right-click it, the option "resize/move" is disabled.

I tried to unmount it, to "lazy" unmount it (umount -l /dev/sda2) but it didn't work.

A screenshot from GParted:

GParted screenshot

Best Answer

There seems to be plenty of results on Google where people had similar problems. An example:

Back up all your important data before attempting this. Always assume that you can lose all your data when resizing partitions.

Shrink LVM without dataloss

This forum thread suggests the following procedure, in this example we shrink a partition from 10G to 9G:

First, we unmount.

sudo umount /dev/vg_blah/lv_blah

Check the file system.

sudo e2fsck -f /dev/vg_blah/lv_blah

Resize the file system and the logical volume. Doing this in one step can avoid mistakes which cause dataloss. (Note lvreduce parameter -L interprets G as 2^30 bytes and g as 10^9 bytes.)

sudo lvreduce --resizefs -L 9G /dev/vg_blah/lv_blah

(optional) Remove a physical drive from the volume group if desired (if you now have an unused drive).

sudo vgreduce vg_blah /dev/sdxy

All credit goes to brianmcgee.

Note: vgreduce will fail with cannot resize to xxxxx extents as later ones are allocated if you have another lv at the end of the disk - I had a swap lv, which I deleted. See How to shrink Ubuntu LVM logical and physical volumes? for help on that situation.