6

I've a logical volume that is striped across three physical volumes. I had to move this logical volume to another physical volume. This worked nicely with pvmove command. However, I discovered later that the logical volume is still striped and now all three stripes are on the same physical volume. Is there any way to convert striped logical volumes to linear logical volumes? I'm using LVM2 on linux.

I figured that the obvious possibility is to rename the striped logical volume, create a new linear logical volume, and then copy data over, but that requires taking the filesystem system offline for some time. Unfortunately, I can't do that before the next week. Is there any better alternative?

JooMing
  • 815
  • 7
  • 11

2 Answers2

3

It is also possible to build a mirror first using another single PV, and split of the striped volume afterwards. This requires a free PV but then again I assume pvmove needs this as well.

If you have a volume lvsplit using PV's sda1 and sdb1 for example, and sdc1 is a (temporary) PV with enough free extents, you can do this:

lvconvert -m 1 /dev/volumegroupname/lvsplit

This will create a mirror from your striped volume, using sdc1 to build the mirror

...let the mirror build...

lvconvert -m 0 /dev/volumegroupname/lvsplit /dev/sda1 /dev/sdb1

This will convert the mirror back to a single volume taking out the extents on PV /dev/sda1 and /dev/sdb1, leaving sdc1 as the only PV for your now lineair LV.

You can then pvmove from sdc1 to another PV, or use the mirror technique instead of pvmove to migrate back to sda1 or sdb1.

Thomas Berger
  • 1,700
  • 13
  • 22
Sam
  • 46
  • 2
  • Nice solution! Although I got my problem solved in a different way while ago, I just had to try it on my a test machine (debian squeeze). It worked with one issue. Namely, the creation of a mirror from the split LV required the same amount of temporary PVs as used by the split LV. – JooMing Oct 15 '12 at 14:33
  • 1
    Hi! I'm trying to convert striped LV to linear with Sam's solution and it doesn't work. When running `lvconvert -m 1 ...` I receive `'--mirrors/-m' is not compatible with striped`. Any help? – Scyld de Fraud Oct 15 '14 at 20:40
  • `lvconvert -m1 ...` takes painfully long (I mean really long). You're better of doing a snapshot copy or rsync or cp-whatever to a new linear volume (preferably if the source LV ain't mounted/used). – rogerovo Sep 21 '15 at 07:00
2

However, I discovered later that the logical volume is still striped

Yeah, it's such a PITA. Kills performance dramatically (have had known this once upon a time).

Is there any better alternative?

Sure, but quite unpleasant. You'd have to pvmove all the extents so that they would be in logical order. I'd prefer scripting it by my own, but you can try using http://bisqwit.iki.fi/source/lvm2defrag.html (at your own risk, of course).

poige
  • 9,448
  • 2
  • 25
  • 52
  • Thank you for the hints! The link to lvm2defrag is very useful. I tried to use pvmove in a way that extents would be in a logical order (e.g. pvmove pv1:stripe1:start-end:stripe2:start:end pv2:start:end). It works, but stripes will be still there. – JooMing Feb 02 '11 at 09:28
  • Such pvmove would at least fix interleaving which otherwise degrade performance severely. I'm digging int extents merging now. – poige Feb 02 '11 at 09:38
  • Hi! Regarding segments merge: I've just tested pvmoving to another PV and back then; the result was single (merged) segment. – poige Feb 03 '11 at 19:03
  • @poige: How did you do that? I did move extents back and forth, but could not merge the stripes in the process. – JooMing Feb 09 '11 at 15:36
  • @JooMing, did you move them between different PVs? – poige Feb 09 '11 at 18:42
  • @poige: yes, between different PVs. – JooMing Feb 10 '11 at 14:43
  • Ough, I guess I know why. :-) Don't specify extents when moving between PVs. Just "from" and "to" PVs. – poige Feb 10 '11 at 16:06
  • @poige: Actually my first attempt was to use pvmove between PVs without specifying extents and then I discovered that all stripes are at the same physical volume. I also expected that it would merge extents. Meanwhile, I had a time window to take the file system offline and fixed this trouble with rsync. – JooMing Feb 11 '11 at 15:33
  • :-) I see. Well, my experience shows that pvmove's able to reduce the number of segments. Conditions are not that cleat though. :-) – poige Feb 11 '11 at 15:37