Can thin LVs be moved to a different LVM pool?

If I have (2) thin pools (vg/pool1) and (vg/pool2) inside the same volume group, with an LV inside the first pool, is there a LVM command to move that LV to the second pool? Would pvmove do that?

Alternately, if you have a thin LVM pool that is spread across two different PVs, can you easily specify that all the extents of LV X should be moved from PV Y to Z with the pvmove command?

Asked By: tgharold


I tried to do it using pvmove and it didn’t work. There is a reference on Google to a fix to the source code that would enable the pvmove command to allow for this but on my CentOS 7 machine it complained about my thin pool so I don’t know what version, if any, this fix is included in. Nor do I know if it works.

That said, moving an LV from one pool to the other should not be too hard. As a matter of fact, I moved mine between two pools that are in separate VGs (which shouldn’t matter in any case). Here’s what I did:

Call the LV my_logical_volume, the VGs first_vg and second_vg (these would be the same in your case), and the destination my_logical_volume2. I changed names of the LV in my instance; I’m not sure you can create two lvs with the same name in the same VG, even if they’re on different thin pools. You can try it. In any case, after the move you could always do an lvrename, easy peasy.

Here is the order of things:

# lvs
LV                VG        Attr       LSize   Pool      Origin Data%  Move Log Cpy%Sync Convert
my_logical_volume first_vg  Vwi-a-tz--  10.74g thinpool0         31.39  
thinpool1         second_vg twi-a-tz--   1.20t                    0.29        
thinpool0         first_vg  twi-a-tz-- 500.89g                   86.87                                 

Note the LSize on the logical volume, above. This command:

# lvcreate -V 10.74g -n my_logical_volume2 -T second_vg/thinpool1

…creates the proper number of LEs to match. Just use exactly the same
size as is displayed by lvs. Use lvdisplay to verify you have
created a logical volume of identical size; see the Current LE line
(if your resulting LE count is less, delete then recreate the lv but
add 0.01 to your size [the number following the -V]):

# lvdisplay first_vg/my_logical_volume
  --- Logical volume ---
  LV Path                /dev/first_vg/my_logical_volume
  LV Name                my_logical_volume
  VG Name                first_vg
  LV Pool name           thinpool0
  LV Size                10.74 GiB
  Mapped size            31.39%
  Current LE             2750

# lvdisplay second_vg/my_logical_volume2
  --- Logical volume ---
  LV Path                /dev/second_vg/my_logical_volume2
  LV Name                my_logical_volume2
  VG Name                second_vg
  LV Pool name           thinpool1
  LV Size                10.74 GiB
  Mapped size            0.00%
  Current LE             2750

So now just copy from the first lv to the newly-created one:

# time dd if=/dev/first_vg/my_logical_volume of=/dev/second_vg/my_logical_volume2 bs=4194304 conv=sparse

conv=sparse is critical with the dd otherwise all the space will be provisioned on your destination thin pool and it will no longer be thin :-).

Verify your new logical volume is to your liking. Once alles klarr, Herr Kommissar, you can rename your new LV if you want, remove the original (you did back it up before working on it, right?), etc.

Answered By: Mike S
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.