Creating an LVM Mirror for Fault Tolerance or Moving Data

  • 7009321
  • 09-Sep-2011
  • 30-Apr-2012

Environment

Novell Open Enterprise Server 2 (OES 2) Linux
SUSE Linux Enterprise Server 10
SUSE Linux Enterprise Server 11

Situation

The goal is to add fault tolerance to an existing LVM volume or to move a file system on an LVM device from one SAN disk to different SAN disk.

Resolution

For this procedure an additional disk is needed for each leg of the mirror, plus space for the mirror log device. It is usually best to have a dedicated disk for each leg of the mirror and the mirror log.

Add the additional devices to the volume group containing the pre-existing volume to be mirrored. For example,

server:~ # pvscan
  PV /dev/sdb   VG vg   lvm2 [196.00 MB / 96.00 MB free]
  Total: 1 [196.00 MB] / in use: 1 [196.00 MB] / in no VG: 0 [0   ]

server:~ # vgs

  VG   #PV #LV #SN Attr   VSize   VFree
  vg     1   1   0 wz--n- 196.00M 96.00M

server:~ # lvs

  LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%
  lv1  vg   -wi-ao 100.00M                             

server:~ # mount | grep exports

/dev/mapper/vg-lv1 on /exports/lv1 type ext3 (rw)

server:~ # cat /proc/partitions

major minor  #blocks  name

   8     0   15728640 sda
   8     1    1542208 sda1
   8     2   14185395 sda2
   8    16     204800 sdb
   8    32     204800 sdc
   8    48     204800 sdd
 253     0     102400 dm-0

After adding the free disks, the configuration might look like this:

server:~ # pvcreate /dev/sd[c-d]
  Physical volume "/dev/sdc" successfully created
  Physical volume "/dev/sdd" successfully created

server:~ # vgextend vg /dev/sd[c-d]

  Volume group "vg" successfully extended

server:~ # pvscan

  PV /dev/sdb   VG vg   lvm2 [196.00 MB / 96.00 MB free]
  PV /dev/sdc   VG vg   lvm2 [196.00 MB / 196.00 MB free]
  PV /dev/sdd   VG vg   lvm2 [196.00 MB / 196.00 MB free]
  Total: 3 [588.00 MB] / in use: 3 [588.00 MB] / in no VG: 0 [0   ]

server:~ # vgs

  VG   #PV #LV #SN Attr   VSize   VFree 
  vg     3   1   0 wz--n- 588.00M 488.00M

server:~ # lvs -a -o +devices
  LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%  Devices   
  lv1  vg   -wi-ao 100.00M                               /dev/sdb(0)

Convert the linear logical volume to a mirrored logical volume.
lvconvert -m1 /dev/vg/lv1

server:~ # lvconvert -m1 /dev/vg/lv1
  Logical volume lv1 converted.

server:~ # lvs -a -o +devices

  LV             VG   Attr   LSize   Origin Snap%  Move Log      Copy%  Devices                       
  lv1            vg   mwi-ao 100.00M                    lv1_mlog  88.00 lv1_mimage_0(0),lv1_mimage_1(0)
  [lv1_mimage_0] vg   iwi-ao 100.00M                                    /dev/sdb(0)                   
  [lv1_mimage_1] vg   iwi-ao 100.00M                                    /dev/sdc(0)                   
  [lv1_mlog]     vg   lwi-ao   4.00M                                    /dev/sdd(0)                   

server:~ # lvs -a -o +devices

  LV             VG   Attr   LSize   Origin Snap%  Move Log      Copy%  Devices                       
  lv1            vg   mwi-ao 100.00M                    lv1_mlog 100.00 lv1_mimage_0(0),lv1_mimage_1(0)
  [lv1_mimage_0] vg   iwi-ao 100.00M                                    /dev/sdb(0)                   
  [lv1_mimage_1] vg   iwi-ao 100.00M                                    /dev/sdc(0)                   
  [lv1_mlog]     vg   lwi-ao   4.00M                                    /dev/sdd(0)                   

This can be done while the logical volume is mounted. Use the lvs command to see the status of the mirror Copy%. If any of the disks ever fail, the logical volume will be converted back to a linear volume using the remaining physical disk. If the data got moved to another disk, the old disk can be simply remove. LVM will detect the lost disk and convert the volume back to a linear logical volume using the existing disk on the new SAN or location. Please make sure the data is backed up prior to doing this operation.