Moving LVM2 logical volumes from one physical volume to another – Part 1

So, on discovering a server that’s configured with the wrong disk layout, I find myself needing to consolidate all logical volumes onto a single physical volume (PV) so I can re-configure the other PV. The machine has the disk space, so it should be a matter of shuffling bits in a “shell-game” so I can clear off the second PV and re-build the disk array with the right RAID level.

LVM2 has the utility pvmove that can move physical extents from one disk to another. Maybe I can make this work for me 🙂

First hurdle: all physical disk blocks are allocated to LVM physical volumes. I need to shrink my first PV to make room for blocks from my second PV. To see how many blocks on PV 1 are in use, I run

pvdisplay -m

Which reports that all extents up to 96640 are in use. So I should be able to shrink the PV down to, say, 100000 extents safely. With 32MiB extents, the command to do this should be

pvresize -t /dev/sda3 --setphysicalvolumesize 3200000M

but I’m too chicken to run this on a live system. I need to set up a test machine to verify that this works.

UPDATE: So, it does work, but it turns out that a reboot is needed to update the kernel partition table after the next step, which is resizing the partitions.

(It might have been easier to just resize the partition first and then resize the PV with “pvresize /dev/sda3” and let it fill the new partition.)

After shrinking the sdb1 partition to match the new PV size, create a new partition, sda4, to hold the new PV. Create the new PV (I did it in system-config-lvm) and add it to the volume group (VG) of the logical volumes we want to move off of sdb1 as extents must be moved to a new PV in the same group.

I’m testing this on a VM now. I’ve already determined this will require a reboot, so I’m less enthused about the process already. :-/

This entry was posted in Linux and tagged . Bookmark the permalink.

Comments are closed.