Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '09 at 14:41

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
4  
Step 0: Backup up the partition to be reduced! –  mdpc Aug 17 '09 at 14:53

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.