LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-23-2012, 10:09 AM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Rep: Reputation: 99
Question 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.
 
Old 05-23-2012, 10:49 AM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
Quote:
Originally Posted by vikas027 View Post
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
 
Old 05-23-2012, 11:02 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Original Poster
Rep: Reputation: 99
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.

Last edited by vikas027; 05-24-2012 at 06:21 AM.
 
Old 05-24-2012, 08:06 AM   #4
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 602

Rep: Reputation: 49
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"
 
Old 05-24-2012, 12:30 PM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Original Poster
Rep: Reputation: 99
Quote:
Originally Posted by r0b0 View Post
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.
 
Old 05-24-2012, 12:50 PM   #6
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
Quote:
Originally Posted by vikas027 View Post
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
 
Old 05-24-2012, 01:00 PM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Original Poster
Rep: Reputation: 99
Quote:
Originally Posted by custangro View Post
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.
 
Old 05-24-2012, 02:30 PM   #8
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
Quote:
Originally Posted by vikas027 View Post
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
 
Old 05-24-2012, 03:36 PM   #9
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Original Poster
Rep: Reputation: 99
Quote:
Originally Posted by custangro View Post
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.
 
Old 05-25-2012, 04:53 AM   #10
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian
Posts: 1,266

Original Poster
Rep: Reputation: 99
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM Partitions are equals to OS partitions? xeon123 Linux - Newbie 1 05-26-2011 06:45 PM
How to multiboot distros from LVM and/or Non-LVM partitions? kennybobby Fedora 2 12-07-2010 06:58 AM
Can I move an LVM as I can move an ISO tkmsr Linux - Server 5 10-05-2010 11:18 AM
LXer: Back Up (And Restore) LVM Partitions With LVM Snapshots LXer Syndicated Linux News 0 04-17-2007 11:16 AM
how do I add partitions to drives that have Logical Volume (LVM) partitions? The MJ Linux - Software 5 08-17-2006 06:15 PM


All times are GMT -5. The time now is 09:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration