Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Basically, I want to move / copy several logical volumes (lv) into a new volume group (vg). The new volume group reside on a new set of physical volumes. Does anyone know how to do that safely without damaging to the data inside those logical volumes??

share|improve this question
    
Can you provide more details ? Do you know how to make new VG and LV ? Are you moving a data partition or your root partition ? –  bodhi.zazen Dec 28 '11 at 17:31
    
@bodhi.zazen : Actually I was trying to move a kind of data partitions. What I meant by "kind of" was, those logical volumes are virtual machines. (i.e. those logical volumes are appeared to virtual machines as block devices). Anyway, I was able to handle the situation in my own way. The steps are given in my answer. However, you and all of you are welcome to comment on my method. If there is/are a better way(s) to do this kind of thing please be kind enough to share it. :) –  nobody Dec 29 '11 at 3:34
    
I would have first created the new PV/LV , shut down the VM, then copied the data with dd, boot the new VM and confirm it worked. –  bodhi.zazen Dec 29 '11 at 4:31
add comment

3 Answers 3

Okay, I was able to handle the situation in my own way. Here are the steps I took:

1) Take a snapshot of the targeting logical volume.

lvcreate --snapshot --name <the-name-of-the-snapshot> --size <the size> /dev/volume-group/logical-volume

Note : Size of the snapshot can be as large as or as small as you wish. What matters is having enough space to capture changes during snapshot period.

2) Create an image copy of the snapshot content using dd

dd if=/dev/volume-group/snapshot-name of=/tmp/backup.img

3) Create a new logical volume of enough size in the targeting (new) volume group.

lvcreate --name <logical-volume-name> --size <size> the-new-volume-group-name

4) Write data to the new logical volume from the image backup using dd

dd if=/tmp/backup.img of=/dev/new-volume-group/new-logical-volume

5) delete the snapshot and image backup using lvremove and rm respectively.

That's all folks... Hope this helps to someone :)

share|improve this answer
    
If someone has better option / method, let me know as well :-) –  nobody Dec 29 '11 at 5:25
add comment

There is no reason to copy it to a .img file first, just do the lvcreate first, then directly copy it over:

lvcreate --snapshot --name <the-name-of-the-snapshot> --size <the size> /dev/volume-group/logical-volume
lvcreate --name <logical-volume-name> --size <size> the-new-volume-group-name
dd if=/dev/volume-group/snapshot-name of=/dev/new-volume-group/new-logical-volume
share|improve this answer
add comment

vgmerge lets you merge two VGs. You can also use pvmove to move data within a VG, and vgsplit if you want to go back to multiple VGs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.