Okay, so I’m posting how to reduce the size of a LVM non-destructively. I’ve searched a fair bit for an simple guide on doing this and I eventually found some stuff that made me kind of stumble on the solution. I hope this brief guide helps someone save some real time.
I had an lvm spanning 7 partitions and decided I wanted to reduce it’s size. In short, the key is understanding the functional quirks of pvmove.
When making an lvm here’s basically the steps you follow:
1. Initialize partition
2. Create Volume Group
3. Activate Volume Group
4. Add Physical Volume (such as a partition or entire drive) to your Volume Group
5. Create or Expand your Logical Volume
6. Create or Expand your file system (in my case Reiserfs)
Removing a disk is simply this backwards which I’ll discuss at greater length below.
Removing a Partition/Disk from your LVM
1. Free up enough space from the file system that lives on the lvm to accommodate the drive/partition you wish to remove.
2. Resize the file system accordingly. Note that I always leave little buffers. So suppose there is 50Gb free on my lvm. If I wish to shink the file system on the LVM, I’ll reduce the size of that file system by something like 48Gb. Since many of these tools warn constantly of you possibly losing your data, you may as well pad things just so that you don’t accidentally overstep any bounds.
3. Reduce the size of your Volume Group. Use vgreduce – it’s easy, the command you’ll want to use will be something like:
vgreduce -L -48G my_lvm.
4. Now you need to reallocate Physical Extents. pvmove attempts to move PEs in blocks. If you tell pvmove to move a block of PEs and there is no sufficiently large chunk of free PEs elsewhere in your LVM then pvmove won’t place nicely. If you use pvdisplay to figure out where your free blocks are, you can transfer PEs off the partition you’re removing in chunks that meet the free space that already exists in your lvm. For example, suppose I wanted to transfer PE 0 to 16300 off /dev/sda, I’d use:
5. Once all PEs from the partition you’re removing have been moved, you need to remove the partition from the volume group. For this, use pvremove
Okay, so that there is a pretty casual little guide on removing partitions.. Post comments if you have any questions and would like more detail.