How to move an LVM volume to a different host
There is nothing special going on here - one of those “note to self” posts. This is basically a recipe from LVM Howto. The only additional part is renaming of the volume group.
First, unmount the logical volume on the old system:
[root@syncthing ~]# umount /opt/data
[root@syncthing ~]# vgs
VG #PV #LV #SN Attr VSize VFree
data 1 1 0 wz--n- <500.00g 0
system 1 7 0 wz--n- <27.50g <9.85g
…then deactivate the volume group:
[root@syncthing ~]# vgchange -an data
0 logical volume(s) in volume group "data" now active
[root@syncthing ~]#
Next, export the volume group. This makes other LVM utilities to ignore the inactive VG:
[root@syncthing ~]# vgexport data
Volume group "data" successfully exported
[root@syncthing ~]#
Make sure the mount point is commented out in /etc/fstab, in case you need to power on the old system. Then, unpresent the LUN from the old system and present it to the new system. This all can be done with both systems online, but it requires a little more fiddling; rescanning SCSI bus, and so on.
Once the LUN is presented to the new system, rescan for physical volumes:
[root@syncthing ~]# pvscan
PV /dev/sdb is in exported VG app [<770.00 GiB / 0 free]
PV /dev/sda2 VG system lvm2 [<27.50 GiB / <9.85 GiB free]
Total: 2 [797.49 GiB] / in use: 2 [797.49 GiB] / in no VG: 0 [0 ]
Now, comes the VG renaming part. Here, volume group app is being renamed to data.
[root@syncthing ~]# vgrename app data
Volume group "app" successfully renamed to "data"
[root@syncthing ~]# vgs
VG #PV #LV #SN Attr VSize VFree
data 1 1 0 wzx-n- <770.00g 0
system 1 7 0 wz--n- <27.50g <9.85g
Now import the volume group - this makes the volume group known to the new system:
[root@syncthing ~]# vgimport data
Volume group "data" successfully imported
Finally, activate the VG on the new system…
[root@syncthing ~]# vgchange -ay data
1 logical volume(s) in volume group "data" now active
…and mount it.