Lvm – Is it possible to mirror a striped LVM logical volume

lvm

I have a striped logical volume that is currently split between two physical drives (/dev/sda1 and /dev/sdb1). I now want to mirror this volume onto a third device (/dev/sdc1) that has been added into the volume group. A number of references I have found (e.g. Is it possible to convert striped logical volume to linear logical volume?) suggest this is possible with the following command:

lvconvert -m 1 /dev/volgroup/volume /dev/sdc1

However for me this results in the following error:

'--mirrors/-m' is not compatible with striped

Why isn't this working for me?

LVM version

LVM version:     2.02.133(2) (2015-10-30)
Library version: 1.02.110 (2015-10-30)
Driver version:  4.34.0

Best Answer

Try it like this

lvconvert -m1 /dev/volgroup/volume

Below is the command log of my test. I did it on loopback devices

Create 3 loopback devices

dd if=/dev/zero of=disk1 bs=1M count=100
dd if=/dev/zero of=disk2 bs=1M count=100
dd if=/dev/zero of=disk3 bs=1M count=200
[root@localhost ~]# losetup -f /root/disk1
[root@localhost ~]# losetup -f /root/disk2
[root@localhost ~]# losetup -f /root/disk3
[root@localhost ~]# losetup -a
/dev/loop0: [64768]:17900481 (/root/disk1)
/dev/loop1: [64768]:17900482 (/root/disk2)
/dev/loop2: [64768]:17900483 (/root/disk3)

Create PVs

[root@localhost ~]# pvcreate /dev/loop0
  Physical volume "/dev/loop0" successfully created
[root@localhost ~]# pvcreate /dev/loop1
  Physical volume "/dev/loop1" successfully created
[root@localhost ~]# pvcreate /dev/loop2
  Physical volume "/dev/loop2" successfully created
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/loop0        lvm2 ---  100.00m 100.00m
  /dev/loop1        lvm2 ---  100.00m 100.00m
  /dev/loop2        lvm2 ---  200.00m 200.00m
  /dev/sda2  centos lvm2 a--    7.51g  40.00m

Create VG and LV with 2 stripes

vgcreate StripedVG /dev/loop0 /dev/loop1
lvcreate -l +100%FREE -i2 -n StripedLV StripedVG
Using default stripesize 64.00 KiB.
Logical volume "StripedLV" created.

enter image description here

Format and mount

mkfs /dev/mapper/StripedVG-StripedLV
mount /dev/mapper/StripedVG-StripedLV /mnt

Now let's add our 3rd PV to VG

vgextend StripedVG /dev/loop2
Volume group "StripedVG" successfully extended

And now convert

[root@localhost ~]# lvconvert -m1 StripedVG/StripedLV
  StripedVG/StripedLV: Converted: 0.0%
  StripedVG/StripedLV: Converted: 83.3%
  StripedVG/StripedLV: Converted: 100.0%

Remove striped part from mirror

[root@localhost ~]# lvconvert -m0 StripedVG/StripedLV /dev/loop0 /dev/loop1
  Logical volume StripedLV converted.

enter image description here

And now get rid of the /dev/loop0 and /dev/loop1

[root@localhost ~]# vgreduce StripedVG /dev/loop0
  Removed "/dev/loop0" from volume group "StripedVG"
[root@localhost ~]# vgreduce StripedVG /dev/loop1
  Removed "/dev/loop1" from volume group "StripedVG"
[root@localhost ~]# pvremove /dev/loop0 /dev/loop1
  Labels on physical volume "/dev/loop0" successfully wiped
  Labels on physical volume "/dev/loop1" successfully wiped

So what we have finally is this

enter image description here

Edit 1:
What I described above works on CentOS 6, but doesn't work on CentOS 7.
I guess in CentOS 7 this rule kicks in.
Since striped != linear, it fails.

enter image description here

I just recompiled lvm rpm package from source but added extra debug

enter image description here

And here is output

[root@localhost x86_64]# lvconvert -m1 StripedVG/StripedLV
  '--mirrors/-m' is not compatible with striped
  arg_count = 1

  seg_is_linear = 0

  seg_is_mirrored = 0

So basically all 3 conditions evaluate to true and we enter error handling block.

arg_count=1 
!seg_is_linear = !(0) = 1
!seg_is_mirrored = !(0) = 1

Edit 2:
I found solution for CentOS 7. Instead of RAID 1 - we need to use --type mirror

lvconvert --type mirror -m 1 StripedVG/StripedLV

enter image description here

And then convert it to Linear and chose which PVs to remove

lvconvert -m0 StripedVG/StripedLV /dev/loop0 /dev/loop1

enter image description here

Related Topic