How can I reduce the size of an existing LVM partition without screwing the data in there?
What if that partition is the root (/) partition?
How can I reduce the size of an existing LVM partition without screwing the data in there?
What if that partition is the root (/) partition?
First you can't reduce a mounted partition (at least that's the case for ext{2,3,4}). You have to boot on a stick or something for /.
Then, to make sure I don't screw it, I do it in three steps:
Reduce the file system (need a fsck -f first) with resize2fs to slightly less (1G) than the target.
$ sudo fsck -f /dev/vg/mylv
$ sudo resize2fs /dev/vg/mylv 24G
Reduce the logical volume with lvreduce to the target value
$ sudo lvreduce -L 25G /dev/vg/mylv
Re-run resize2fs with no parameters on the device, it will pick up the block device's size.
$ sudo resize2fs /dev/vg/mylv
You could also simply calculate the right size by taking multiples of the extent size, but I find that the extra step is error prone, and when I have to do that kind of thing I don't have brain cycles to spare.
Do you want to resize a single LV (logical volume) or a PV (physical volume, disk LVM partition) ? There is nothing like "a LVM root partition". I guess that you have a root filesystem over LV. In such case follow niXar advice.
However if you want to resize a single LVM (disk) partition (i.e. a single PV) you can resize it using "pvresize" or "pvmove".
# man pvmove
# man pvresize
And don't forget to backup your data before starting to play with disk partitions or DM devices.