Tuesday, October 21, 2014

Mirror LVM logical volume using only two physical volumes

Task: Mirror LVM logical volume using only two physical volumes

Mirroring: All changes made to logical volume are synchronized across underlying physical volumes.

Suppose you have a volume data (1GB) in group test and you mant to mirror it to improve reliability. You will need at least one physical volume in the same group (test) of the same size or larger.

It's not recommended to place mirrored physical volumes on same physical drive because of two reasons:

  1. In case of disk failure - you will not be able to recover data. Simply you will lose both copies of data.
  2. To copy data between partitions on hard disk, head will need to move between two regions of HDD, that will reduce disk lifetime, increase and slow down write process. 

Prepearation:

  1. Add another physical volume to group test. Volume should be located on another physical drive and should have size of volume data or greater (1GB).
  2. Add physical volume to volume group test

Now we just tell LVM that it should persist data on 2 volumes (we want 1 additional copy of data), and no mirroring log. LVM will start to synchronize data between physical volumes in background.

sudo lvconvert -v -m 1 /dev/test/data --corelog

without --corelog mirroring would use at least 3 partitions (one additional partition for mirrorlog)

To disable mirroring:
sudo lvconvert -v -m 0 /dev/test/data

LVM will leave only one copy of data.

No comments:

Post a Comment