7

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

2 Answers 2

4

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.

1

You must have had a look at this page already, Online RAID1 Creation in Linux

It will be really straight forward if you could get two brand new drives, put them in a newly created RAID1 mirror with mdadm and use dd to transfer data from /dev/sda.

Or take a dd backup of your /dev/sda, use /dev/sdb to create a mirror and restore from backup.

Or still use /dev/sdb to create a RAID1 mirror with 1 disk, dd all the data across and then add /dev/sda in RAID mirror.

The approach followed in the post I have provided the link to, seems a bit risky, but if you have all the backup, why not try it.

1
  • seems a bit risky, but if you have all the backup, why not try it. Because time is money and also if ever there is a risk of data loss (or any other type of loss) no matter how prepared you are there's always the chance of a mistake (e.g. you're more tired than you realise and so you don't even realise that there's a problem). Of course if you have a backup make sure it works too! But if it's risky and you have a backup well sure, but not without considering it first (you might mean that but some might not think of it).
    – Pryftan
    Commented Dec 18, 2018 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .