Wednesday, March 30, 2016

Hot migrate linear LVM to striped

Initial linear LVM

Create the Pysical Volumes

root@lvmtest:~# pvcreate /dev/sdb /dev/sdc
  Physical volume "/dev/sdb" successfully created
  Physical volume "/dev/sdc" successfully created

Create the Volume Group

root@lvmtest:~# vgcreate MAIN /dev/sdb /dev/sdc

Create the Logical Volume

root@lvmtest:~# lvcreate -n LVMAIN -l 100%FREE MAIN
  Logical volume "LVMAIN" created

Create the filesystem, mount it

root@lvmtest:~# mkfs.xfs /dev/MAIN/LVMAIN

root@lvmtest:~# mkdir /mnt/mylvmvolume

root@lvmtest:~# mount /dev/MAIN/LVMAIN /mnt/mylvmvolume

root@lvmtest:~# df -h | grep MAIN
/dev/mapper/MAIN-LVMAIN   64G   33M   64G   1% /mnt/mylvmvolume

Create extra space

Add two new disks

root@lvmtest:~# pvcreate /dev/sdd /dev/sde
  Physical volume "/dev/sdd" successfully created
  Physical volume "/dev/sde" successfully created

Add the disks to the volumegroup

root@lvmtest:~# vgextend MAIN /dev/sdd /dev/sde

Make it stripe

Now.. you can’t move PE’s between logical volumes. So you have to do a little trick.
Create a mirror (-m 1) of the current data to the recently added space. And make it stripe (—stripes <number of disks>).
Do this in a screen. This can take days, depending on the size!

root@lvmtest:~# lvconvert -m 1 --mirrorlog core --stripes 2 /dev/MAIN/LVMAIN /dev/sdd /dev/sde
  Using default stripesize 64.00 KiB
  MAIN/LVMAIN: Converted: 0.0%
  MAIN/LVMAIN: Converted: 1.0%
  MAIN/LVMAIN: Converted: 2.4%
  MAIN/LVMAIN: Converted: 3.7%
  MAIN/LVMAIN: Converted: 5.1%

While the mirroring is in progress, we look at the stats…
Notice there is only one disk reading (sdb) and two are writing (the striped disks). Perfect!

root@lvmtest:~# iostat -m 2 /dev/sd[b-e]
Linux 3.16.0-45-generic (btrfs)         03/30/2016      _i686_  (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    1.26    0.00    0.00   98.74

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sdb             117.50        58.75         0.00        117          0
sdc               0.00         0.00         0.00          0          0
sdd             117.50         0.00        29.38          0         58
sde             117.50         0.00        29.38          0         58

.. and a little further down the progress data is read from sdc.

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sdb               0.00         0.00         0.00          0          0
sdc             134.50        67.25         0.00        134          0
sdd             134.50         0.00        33.62          0         67
sde             134.00         0.00        33.50          0         67


Let’s break the mirror and go live with the new disks:

root@lvmtest:~# lvconvert -m0 MAIN/LVMAIN /dev/sdb /dev/sdc
  Logical volume LVMAIN converted.

Remove the old disks from the volume group:

root@lvmtest:~# vgreduce MAIN /dev/sdb /dev/sdc
  Removed "/dev/sdb" from volume group "MAIN"
  Removed "/dev/sdc" from volume group "MAIN"

Remove the pysical volumes:

root@lvmtest:~# pvremove /dev/sdb /dev/sdc
  Labels on physical volume "/dev/sdb" successfully wiped
  Labels on physical volume "/dev/sdc" successfully wiped

There ya go. No downtime. Hot migrated from linear to striped!