Create raid1 from existing lvm local volume

lvmmdadm

I have an existing LVM, with one physical drive (say /dev/sdb),
and one volume group (say volgrp1), here I have three logical volumes (say lvSys, lvHome, lvSwap).

Now I worry about my data and by a second drive, completely identical to /dev/sdb and I want to create a mirrored device, that holds identical data to /dev/sdb but I want to keep all data while creating it.

Do I use mdadm or lvm-only?
And how do I do this?

I've searched the internet but understanding the whole lvm/mdadm thing is really neat stuff though.

So can anyone explain simple config to plug in an identical device and tell (lvm/mdadm/linux-kernel) to just mirror the data to /dev/sdc without loosing any data on /dev/sdb

Regards

Best Answer

If you want to mirror the whole drive, the simplest method would be to turn it into a RAID-1 array. It's possible to turn an existing partition (or whole disk, or any volume type really) into an mdraid RAID-1 array, it just requires a bit of manual fiddling. The idea is to ensure that there's enough free space at the end of the volume (128kB) for the metadata, and use metadata format 1.0, which puts metadata at the end of the volume, instead of the default 1.2 which puts metadata at the beginning. For a practical guide to converting an existing partition to RAID-1, see How to set up disk mirroring (RAID-1)

Once you've created the RAID-1 volume, your system should still be usable — that's an advantage of LVM: the physical volumes will be autodetected, and the logical volumes will be available under the same names. You may need to take steps to ensure that the mdadm driver is available in the kernel; for example, on Debian and derivatives, run update-initramfs.

Alternatively, you could create a RAID-1 array on the new disk (with the other half missing), create an LVM physical volume on it, extend the existing volume group to it, remove the existing PV from the VG, and finally extend the RAID array to the old disk. This would require more downtime, and all in all isn't particularly safer.

Alternatively, you can use LVM's own mirroring. The command lvconvert --mirror 1 converts a logical volume to a RAID-1 mirror. I wouldn't recommend this approach unless there are logical volumes that you don't want to mirror, because I find it easier to separate storage concerns such as mirroring from interface concerns such as snapshotting.

Related Question