Suppose you created an LVM mirror but your mirror log is on the wrong SAN device. SAN migration won't help you since these LUNs exist on different SAN machines altogehter. But how do you move the mirror log?

Let's create an LVM mirror:

  Last login: Sat Nov 23 17:36:23 2013
  [root@leonis ~]# ls /dev/sd*
  /dev/sda  /dev/sdb
  [root@leonis ~]# pvcreate /dev/sda
    Writing physical volume data to disk "/dev/sda"
    Physical volume "/dev/sda" successfully created
  [root@leonis ~]# pvcreate /dev/sdb
    Writing physical volume data to disk "/dev/sdb"
    Physical volume "/dev/sdb" successfully created
  [root@leonis ~]# vgcreate vgmir /dev/sda /dev/sdb
    Volume group "vgmir" successfully created
  [root@leonis ~]# lvcreate -l 45%FREE vgmir -n lvmir
    Logical volume "lvmir" created
  [root@leonis ~]# lvconvert -m 1 /dev/vgmir/lvmir 
    vgmir/lvmir: Converted: 0.2%
    vgmir/lvmir: Converted: 2.2%
  ...
    vgmir/lvmir: Converted: 99.5%
    vgmir/lvmir: Converted: 100.0%

Now lvs -a -o +devices will show you the detailed mirror configuration:

  LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices
  lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
  [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)
  [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)
  [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sdb(920)

In my case /dev/sdb and /dev/sdc were on different SAN machines and one machine was loaded quite heavily. Meaning we got a 160 IOPS maximum out of the entire mirror. Now all credit goes to our SAN admins for getting the utilization of the older SAN machine to the point where the LUN could easily deliver 4000 IOPS.

However there's one thing to consider: the mirror log. The mirror log generally incurs extra IOPS, so you want to create it on the faster/less loaded SAN machine. Two approaches immediately come to mind: a) convert the mirror from on disk log to in-memory then recreating it on the faster SAN machine; b) dropping the slower mirror leg entirely and recreating the mirror with the faster SAN as the mirror device.

Let's drop the mirror:

  [root@leonis ~]# lvconvert -m 0 vgmir/lvmir /dev/sdb
    Logical volume lvmir converted.

And recreate the mirror with the mirror log on ``/dev/sda``::

  [root@leonis ~]# lvs -a -o +devices,seg_pe_ranges
    LV      VG       Attr     LSize Pool Origin Data%  Move Log Copy%  Convert Devices        PE Ranges         
    lvmir   vgmir    -wi-a--- 3.59g                                            /dev/sda(0)    /dev/sda:0-919    
  [root@leonis ~]# lvconvert -m 1 vgmir/lvmir /dev/sdb:0-919 /dev/sda
    vgmir/lvmir: Converted: 0.2%
    vgmir/lvmir: Converted: 2.7%
    vgmir/lvmir: Converted: 99.8%
    vgmir/lvmir: Converted: 100.0%
  [root@leonis ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                                   /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                                   /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)                        
    [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sda(920)                      

The trick here is, since we don't have an option to specify the mirror leg explicitely we specify a PE range on /dev/sdb and the full /dev/sda and LVM figures out where to place the segments.

Let's convert that to a core mirror:

  [root@leonis ~]# lvconvert --mirrorlog core vgmir/lvmir
    Logical volume lvmir converted.
  [root@leonis ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                            /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                            /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                             100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                            /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                            /dev/sdb(0)                        

Then convert it back to a on-disk mirror::

  [root@leonis ~]# lvconvert --mirrorlog disk vgmir/lvmir /dev/sdb
    Logical volume lvmir converted.
  [root@leonis ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                                   /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                                   /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)                        
    [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sdb(920)                      

Converting the mirror-log to a core-log is clearly much faster and the only drawback seems to be that in case of a reboot the whole mirror will be resynced which is just as good as resyncing the mirror in the first place.

Moving an LVM mirror log

Follow me on Mastodon!