1

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?

1
  • Do you need to resize just a logical volume or an LVM partition? For resizing a logical volume, niXar's answer is right.
    – mfriedman
    Aug 17, 2009 at 14:41

2 Answers 2

3

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:

  1. 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

  2. Reduce the logical volume with lvreduce to the target value

    $ sudo lvreduce -L 25G /dev/vg/mylv

  3. 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.

1
  • 4
    Step 0: Backup up the partition to be reduced!
    – mdpc
    Aug 17, 2009 at 14:53
0

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.

BTW: http://www.tldp.org/HOWTO/LVM-HOWTO/reducelv.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .