LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Move LVM partitions from one server to another (https://www.linuxquestions.org/questions/linux-server-73/move-lvm-partitions-from-one-server-to-another-946471/)

vikas027 05-23-2012 10:09 AM

Move LVM partitions from one server to another
 
Hi All,

Few days ago, in an interview I was asked whether in RHEL/CentOS is it possible to move LVM partitions from one server to another servers.

Just for illustration, I will call the Server "A" which currently has LVM Filesystems and call the Server "B", on which I want to move the LVM Filesystems of Server "A".

I know that I can move VG (and its LVs obviously) from one server to another by exporting and importing it (if we have a shared storage or if we physically plug and unplug the disks), as also illustrated in this link too.
This was my answer too.

Now, is it possible to move (or copy) the VG from Server "A" to Server "B" without a shared storage or without plug/unplug-ing the disks.

Forgive my ignorance on this.

custangro 05-23-2012 10:49 AM

Quote:

Originally Posted by vikas027 (Post 4685654)
Hi All,

Few days ago, in an interview I was asked whether in RHEL/CentOS is it possible to move LVM partitions from one server to another servers.

Just for illustration, I will call the Server "A" which currently has LVM Filesystems and call the Server "B", on which I want to move the LVM Filesystems of Server "A".

I know that I can move VG (and its LVs obviously) from one server to another by exporting and importing it (if we have a shared storage or if we physically plug and unplug the disks), as also illustrated in this link too.
This was my answer too.

Now, is it possible to move (or copy) the VG from Server "A" to Server "B" without a shared storage or without plug/unplug-ing the disks.

Forgive my ignorance on this.

You can try doing a "snapshot" of the LV then move it over that way (using rsync, scp, etc)

The steps would basically go like this...

Create snapshot: (implies you have enough room in the VG to create the snapshot. I chose 1G...you can be more conservative with the size if you want. NOTE: snapshots are COW snapshots)

Code:

root@serverA# lvcreate --snapshot /dev/volumegroup/logvol --name logvol_snap --size 1G
Mount snapshot: (I like to mount it read-only to preserve the quiescence)

Code:

root@serverA# mount -o ro /dev/volumegroup/logvol_snap /mnt
Send to remote server: (using whatever method you want...I like using rsync)

Code:

root@serverA# rsync -auv --delete /mnt/ serverB:/path/to/dir/
--C

vikas027 05-23-2012 11:02 AM

Hi Custangro,

I just paid more attention to the steps listed by you. Here, you are just syncing two directories, but this won't move the VG or LVM Filesystem but its contents.

Is there any way out that I can move the entire VG to another server without removing disks from the primary server. Thanks.

r0b0 05-24-2012 08:06 AM

This is how we move LVs from one server to another:

Target machine:
Quote:

sudo sh -c "nc -l 7000 | pv | dd of=/dev/raidvg/$DISK"
Source machine:
Quote:

sudo sh -c "dd if=/dev/raidvg/$DISK bs=2M | pv | nc $TARGET 7000 -q 10"

vikas027 05-24-2012 12:30 PM

Quote:

Originally Posted by r0b0 (Post 4686369)
This is how we move LVs from one server to another:

Target machine:


Source machine:

Hi r0b0,

Thanks for the response.
My source machine (where LVM is present) is 192.168.1.20 and target machine is 192.168.1.10

I am getting the below error (invalid option -- q) when I am running this command on 192.168.1.20
Code:

# sh -c "dd if=/dev/vg1/lv1 bs=2M | pv | nc 192.168.1.10 7000 -q 10"
nc: invalid option -- q
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
          [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
          [-x proxy_address[:port]] [hostname] [port[s]]
  0B 0:00:00 [  0B/s] [<=>   
#

Any suggestions.

custangro 05-24-2012 12:50 PM

Quote:

Originally Posted by vikas027 (Post 4685689)
Hi Custangro,

I just paid more attention to the steps listed by you. Here, you are just syncing two directories, but this won't move the VG or LVM Filesystem but its contents.

Is there any way out that I can move the entire VG to another server without removing disks from the primary server. Thanks.

I would think you can run the commands I showed you on each LV in the VG

It would help if you could give us the output of

Code:

vgs
and

Code:

lvs
--C

vikas027 05-24-2012 01:00 PM

Quote:

Originally Posted by custangro (Post 4686591)
I would think you can run the commands I showed you on each LV in the VG

It would help if you could give us the output of

Code:

vgs
and

Code:

lvs
--C

Hi Custangro,

Please find the output of lvs and vgs.

Code:

root@box2:~# vgs
  VG    #PV #LV #SN Attr  VSize  VFree
  rootvg  1  3  0 wz--n- 11.88G 2.91G
  vg1      3  2  1 wz--n-  5.99G 5.60G
root@box2:~#
root@box2:~# lvs
  LV    VG    Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  lvhome rootvg -wi-a-  96.00M                                     
  lvroot rootvg -wi-ao  7.81G                                     
  lvswap rootvg -wi-ao  1.06G                                     
  lv1    vg1    owi-a- 200.00M                                     
  lv2    vg1    swi-a- 200.00M lv1    25.36                       
root@box2:~#

Here, I want to move VG vg1 (with its Logical Volumes lv1 & lv2) to other server whose IP is 192.168.1.10.

custangro 05-24-2012 02:30 PM

Quote:

Originally Posted by vikas027 (Post 4686602)
Hi Custangro,

Please find the output of lvs and vgs.

Code:

root@box2:~# vgs
  VG    #PV #LV #SN Attr  VSize  VFree
  rootvg  1  3  0 wz--n- 11.88G 2.91G
  vg1      3  2  1 wz--n-  5.99G 5.60G
root@box2:~#
root@box2:~# lvs
  LV    VG    Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  lvhome rootvg -wi-a-  96.00M                                     
  lvroot rootvg -wi-ao  7.81G                                     
  lvswap rootvg -wi-ao  1.06G                                     
  lv1    vg1    owi-a- 200.00M                                     
  lv2    vg1    swi-a- 200.00M lv1    25.36                       
root@box2:~#

Here, I want to move VG vg1 (with its Logical Volumes lv1 & lv2) to other server whose IP is 192.168.1.10.

Well here I would do the something similar

The steps would basically go like this...

Create snapshots:

Code:

root@serverA# lvcreate --snapshot /dev/vg1/lv1 --name lv1_snap --size 1G
root@serverA# lvcreate --snapshot /dev/vg1/lv2 --name lv2_snap --size 1G

Mount snapshots:

Code:

root@serverA# mkdir /mnt/lv1
root@serverA# mkdir /mnt/lv2
root@serverA# mount -o ro /dev/vg1/lv1_snap /mnt/lv1
root@serverA# mount -o ro /dev/vg1/lv2_snap /mnt/lv2

Create vg and lvs on remote server (where /dev/sdX is your disk):

Code:

root@serverB# vgcreate vg1 /dev/sdX
root@serverB# lvcreate --name lv1 --size 200M vg1
root@serverB# lvcreate --name lv2 --size 200M vg1
root@serverB# mkfs.ext4 /dev/vg1/lv1
root@serverB# mkfs.ext4 /dev/vg1/lv2
root@serverB# mkdir /mnt/{lv1,lv2}
root@serverB# mount  /dev/vg1/lv1 /mnt/lv1
root@serverB# mount /dev/vg1/lv2 /mnt/lv2

Send to remote server:

Code:

root@serverA# rsync -auv --delete /mnt/lv1_snap serverB:/mnt/lv1
root@serverA# rsync -auv --delete /mnt/lv2_snap serverB:/mnt/lv2

-C

vikas027 05-24-2012 03:36 PM

Quote:

Originally Posted by custangro (Post 4686675)
Well here I would do the something similar

The steps would basically go like this...

Create snapshots:

Code:

root@serverA# lvcreate --snapshot /dev/vg1/lv1 --name lv1_snap --size 1G
root@serverA# lvcreate --snapshot /dev/vg1/lv2 --name lv2_snap --size 1G

Mount snapshots:

Code:

root@serverA# mkdir /mnt/lv1
root@serverA# mkdir /mnt/lv2
root@serverA# mount -o ro /dev/vg1/lv1_snap /mnt/lv1
root@serverA# mount -o ro /dev/vg1/lv2_snap /mnt/lv2

Create vg and lvs on remote server (where /dev/sdX is your disk):

Code:

root@serverB# vgcreate vg1 /dev/sdX
root@serverB# lvcreate --name lv1 --size 200M vg1
root@serverB# lvcreate --name lv2 --size 200M vg1
root@serverB# mkfs.ext4 /dev/vg1/lv1
root@serverB# mkfs.ext4 /dev/vg1/lv2
root@serverB# mkdir /mnt/{lv1,lv2}
root@serverB# mount  /dev/vg1/lv1 /mnt/lv1
root@serverB# mount /dev/vg1/lv2 /mnt/lv2

Send to remote server:

Code:

root@serverA# rsync -auv --delete /mnt/lv1_snap serverB:/mnt/lv1
root@serverA# rsync -auv --delete /mnt/lv2_snap serverB:/mnt/lv2

-C

Hi Custangro,

I am sorry, I think I am unable to make you understand my query.

My aim is NOT to sync the data of the LVM filesystems but to copy (or move) the entire VG/LV to other server such that if I a type lvs or vgs on other server, I could see the copied/moved VGs/LVs onto new server.

For example, as of now vg1 (and lv1/2) are on box2 (192.168.1.20).
Code:

root@box2:~# vgs
  VG    #PV #LV #SN Attr  VSize  VFree
  rootvg  1  3  0 wz--n- 11.88G 2.91G
  vg1      3  2  1 wz--n-  5.99G 5.60G
root@box2:~#
root@box2:~# lvs
  LV    VG    Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  lvhome rootvg -wi-a-  96.00M                                     
  lvroot rootvg -wi-ao  7.81G                                     
  lvswap rootvg -wi-ao  1.06G                                     
  lv1    vg1    owi-a- 200.00M                                     
  lv2    vg1    swi-a- 200.00M lv1    25.36                       
root@box2:~#

I just want to know is there any way out that I can move vg1 (with lv1/2) to another server, such that if in case I run command vgs or lvs on box1 (192.168.1.10) the output is as follows and the data is intact.

Code:

root@box1:~# vgs
  VG    #PV #LV #SN Attr  VSize  VFree
  vg1      3  2  1 wz--n-  5.99G 5.60G
root@box1:~#
root@box1:~# lvs
  LV    VG    Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  lv1    vg1    owi-a- 200.00M                                     
  lv2    vg1    swi-a- 200.00M lv1    25.36                       
root@box1:~#

I hope I have made myself clear now. Sorry for the confusion. :)

vikas027 05-25-2012 04:53 AM

Hi All,

This link worked for me partially. Although, I had to create VG/LV myself, I wonder if there is a way to copy/move LVM metadata too.

I followed these steps.

I added similar disks on the target system (192.168.1.10) with VG and LV.

Code:

root@box1:~# pvcreate /dev/sd{b,c,d}
  Writing physical volume data to disk "/dev/sdb"
  Physical volume "/dev/sdb" successfully created
  Writing physical volume data to disk "/dev/sdc"
  Physical volume "/dev/sdc" successfully created
  Writing physical volume data to disk "/dev/sdd"
  Physical volume "/dev/sdd" successfully created
root@box1:~#
root@box1:~# vgcreate newvg1 /dev/sd{b,c,d}
  Volume group "vg1" successfully created
root@box1:~#
root@box1:~# lvcreate -L +200M -n newlv1 newvg1
  Logical volume "newlv1" created
root@box1:~#

Now, on source server (192.168.1.20)
Code:

root@box2:~# dd if=/dev/vg1/lv1 | ssh 192.168.1.10 dd of=/dev/newvg1/newlv1
Address 192.168.1.10 maps to box1.test.com, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.1.10's password:
409600+0 records in
409600+0 records out
209715200 bytes (210 MB) copied, 32.8713 seconds, 6.4 MB/s
409600+0 records in
409600+0 records out
209715200 bytes (210 MB) copied, 31.129 s, 6.7 MB/s
root@box2:~#

Now, finally I can mount my new LV filesystem.
Code:

root@box1:~# mount /dev/newvg1/newlv1 /mnt
root@box1:~# ls -lrth /mnt
total 14K
drwx------ 2 root root 12K May 24 16:24 lost+found
-rw-r--r-- 1 root root  26 May 24 17:59 file2
-rw-r--r-- 1 root root  54 May 24 18:00 file1
root@box1:~#

This is similar to what Custangro had suggested (the rsync way).

cosmicflush 03-08-2019 08:27 AM

"Rsync is a great remote server copy tool"
 
Quote:

Originally Posted by vikas027 (Post 4686728)
Hi Custangro,

I am sorry, I think I am unable to make you understand my query.

My aim is NOT to sync the data of the LVM filesystems but to copy (or move) the entire VG/LV to other server such that if I a type lvs or vgs on other server, I could see the copied/moved VGs/LVs onto new server.

Hi, I was looking for some answers on this topic myself and decided to register. Regarding your reply above it is very common to move large amounts of data with RSYNC. Of course, you can use it in all kinds of ways like incremental backups, but its also great for remote copy/backup. When you rsync any data for the first time it is the exact same thing as copying it except that you have lots of options and you can do dry runs with it to make sure it's going to the right place - that's especially nice with something as big as LVM2 logical volumes.

This is my first reply since I just signed up. Hope I did it right.

michaelk 03-08-2019 09:00 AM

cosmicflush,
Welcome to LinuxQuestions. This thread is 6 years old and so your comments will probably not help the OP (original poster). In most cases replying to old threads has little value. In searching be mindful of the age of the information since what was posted years ago might not be relevant today.


All times are GMT -5. The time now is 04:44 PM.