For performance reasons instead of using one large LVM volume, it might be replaced by multiple small striped (RAID0) volumes. There is no command to directly transform a single disk logical volume into a striped logical volume. This post will explain the procedure to perform the conversion.
This procedure can be performed in a live system, without the need to reboot. The procedure consists in create a mirror between the original volume and the new striped volumes. Once the mirroring is completed, we can remove the original volume from the mirror leaving only the striped volumes.
To be able to perform the conversion, the number of logical extents (LE) in the LVM logical volume (LV) must be divisible by the number of physical volumes (PV) that will be used in the future striped LV.
Check the number of assigned LE:
# lvdisplay --- Logical volume --- LV Path /dev/<VOLUME_GROUP>/<LOGICAL_VOLUME> LV Name <LOGICAL_VOLUME> VG Name <VOLUME_GROUP> LV UUID <VOLUME_UUID> LV Write Access read/write LV Creation host, time <HOSTNAME>, 2020-12-10 08:38:44 +0000 LV Status available # open 1 LV Size <10.00 GiB Current LE 2559 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0
In this case, the number of LE is 2559.
To know the number of needed LE, you can use:
– le = number of assigned LE, from previous command (2559 in this case)
– pv = number of striped PV to be used in future (ex: 5)
$ le=2559; pv=5; echo $((le%pv?(le/pv+1)*pv:le)) 2560
In this case one extra LE is needed. Example to extend the LV:
# lvresize --extents +1 /dev/<VOLUME_GROUP>/<LOGICAL_VOLUME> /dev/sdb Size of logical volume <VOLUME_GROUP>/<LOGICAL_VOLUME> changed from <10 GiB (2559 extents) to <10 giB (2560 extents). Logical volume <VOLUME_GROUP>/<LOGICAL_VOLUME> successfully resized.
After the LV is prepared proceed:
1. Add the new PVs to the LV creating a striped mirror. The number of stripes should be the number of PVs:
# lvconvert --type mirror -m 1 --mirrorlog core --stripes 2 /dev/<VOLUME_GROUP>/<LOGICAL_VOLUME> /dev/<PV1> /dev/<PV2> ... /dev/<PV5>
2. Remove the initial PV from the LV:
# lvconvert -m0 <VOLUME_GROUP>/<LOGICAL_VOLUME> /dev/<INITIAL_PV>
3. Remove the PV from LVM:
# vgreduce <VOLUME_GROUP> /dev/<INITIAL_PV> # pvremove /dev/<INITIAL_PV>