How to move a Volume Group LVM2 from one OS to another OS

This was tested only in CentOS:

To move a whole volume group from one system to another, the vgexport and vgimport commands can be used.
Below example involves the steps to move a volume group named “vmbsVG” from one system to another. The logical volume from this volume group is initially mounted at /vmbs1.

Un-mount the file system:

If required switch to rescue mode. Make sure that no users are accessing files on the active volume.

umount /vmbs1

Mark the volume group inactive:

Marking the volume group inactive removes it from the kernel and prevents any further activity on it.

vgchange -an vmbsVG
Output: vgchange -- volume group "vmbsVG" successfully deactivated

Export the volume group:

This prevents it from being accessed on the “old” host system and prepares it to be removed.

vgexport vmbsVG
Output: vgexport -- volume group "vmbsVG" successfully exported

Un-present the Disk:

Once the Disk has been unplugged from the server, it can be shutdown.
The Disk can now be presented to the new server on which VG vmbsVG has to be discovered.

In my case I am doing with ProxMox

Present the Disk to the new server:

When plugged into the new system it becomes /dev/sdx so an initial pvscan shows as below:

pvscan -- reading all physical volumes (this may take a while...)
pvscan -- inactive PV "/dev/sdx1" is in EXPORTED VG "vmbsVG" [335 MB / 335 MB free]
pvscan -- inactive PV "/dev/sdx2" is in EXPORTED VG "vmbsVG" [335 MB / 335 MB free]
pvscan -- total: 2 [2.35 GB] / in use: 2 [2.35 GB] / in no VG: 0 [0]

Import the Volume Group:

If importing on an LVM 2 system, run below command:

vgimport dataVG
Output: Volume group "vmbsVG" successfully imported

Else if importing on an LVM system, add the PVs that need to be imported:

vgimport vmbsVG /dev/sdx1 /dev/sdx2
vgimport -- doing automatic backup of volume group "vmbsVG"
vgimport -- volume group "vmbsVG" successfully imported and activated

Activate the volume group:

vgchange -ay vmbsVG

Mount the file system:

mkdir -p /vmbs1 # mount /dev/vmbsVG/lv_vmbs1 /vmbs1

Don’t forget to add the right entry in /etc/fstab file.

Source RHEL: