Linux – Migrate 2-disks LVM to RAID1

linuxlvmraid1

I've got a machine with two physical identical hard drives which are currently set up with LVM as one logical volume. The original idea was to make use of as much "contiguous" space as possible in order to store a big amount of very large data. Time passed, and the current use of the machine changed, so now I'd rather have the two disks in RAID1, both for some extra safety (yes, I do make backups anyway) and 'cause I really don't need that much space anymore. The main concern is whether the second disk does actually have data on it, but I couldn't find any way to actually know how much data is stored on the physical volume.

I'm trying to figure out what the best way to do this would be, and what features does LVM offer me for this. Would I have to reinstall from scratch, or is there any way I could "split" the LVM and create a RAID1 array while keeping the data on – at least – the first disk (supposing the second one has no data on it)?

Thank you very much.

Best Answer

LVM supports some simple RAID configurations, including mirroring (RAID1).

Your best option will be to shrink the LV to a size such that it'll fit onto a single disk (using resize2fs -- assuming ext3/4 -- and lvresize), migrate the VG to a single PV (pvmove), then convert the LV to a mirror (lvconvert --mirror).

As an alternative, instead of converting the LV to a mirror, you could remove the second disk from the VG (lvremove), reformat it as a mdadm RAID1 array with one element, copy your data there, then remove the remaining LVM VG and add it to the array as a mirror.

It should go without saying, but I'll say it anyway: make sure you have a current backup before trying either of these approaches. There are a lot of ways you could easily screw things up and lose data. If possible, set up a scratch array and test on that (e.g, using a pair of USB thumb drives!) before making any changes to your live system.