How to Move a Volume Group (LVM2) from One OS to Another

Moving a whole volume group from one system to another can be achieved using the vgexport and vgimport commands in LVM2. This guide provides an example of how to move a volume group named “vmbsVG” from one system to another. Please note that the steps outlined here have been tested on CentOS.

Note: Ensure that no users are accessing files on the active volume before proceeding with the following steps.

  1. Unmount the file system:
    If required, switch to rescue mode and unmount the file system mounted at /vmbs1.

    umount /vmbs1
    
  2. Mark the volume group inactive:
    Marking the volume group as inactive removes it from the kernel and prevents any further activity.

    vgchange -an vmbsVG
    

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

  3. Export the volume group:
    Exporting the volume group 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

  4. Unplug the disk from the old server:
    Once the disk has been unplugged, you can shut down the old server. The disk will be presented to the new server where the volume group “vmbsVG” needs to be discovered.

    Note: The following steps may vary depending on the server or virtualization platform being used.

  5. Present the disk to the new server:
    When the disk is plugged into the new system, it will be assigned a device name like /dev/sdx. Use the following command to scan for physical volumes:

    pvscan
    

    Output:

    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]
    
  6. Import the volume group:
    If importing on an LVM2 system, use the following command:

    vgimport vmbsVG
    

    Output: Volume group "vmbsVG" successfully imported

    If importing on an LVM system, specify the physical volumes (/dev/sdx1, /dev/sdx2) to be imported:

    vgimport vmbsVG /dev/sdx1 /dev/sdx2
    

    Output:

    vgimport -- doing automatic backup of volume group "vmbsVG"
    vgimport -- volume group "vmbsVG" successfully imported and activated
    
  7. Activate the volume group:
    Activate the imported volume group using the following command:

    vgchange -ay vmbsVG
    
  8. Mount the file system:
    Create a mount point and mount the logical volume from the volume group to the desired location, /vmbs1 in this example:

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

    Don’t forget to add the appropriate entry in the `/etc/f

stab` file to mount the file system automatically on boot.

For more information and detailed instructions, refer to the source documentation from Red Hat: Moving a Volume Group from One System to Another