How do I move a Volume Group from one system to another?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux
  • LVM

Issue

  • How do I move a Volume Group from one system to another?

Resolution

To move a whole volume group from one system to a new system, the vgexport and vgimport commands can be used.

Note: These steps are only for the local disk, not for the Directl Lun mapped to the system.

When vgexport or vgimport is used, it is not necessary to move drives from one system to another. It is an administrative policy tool to prevent access to volumes while moving them to another system.

In this example we will run through the steps to move a volume group named design from one system to another. A logical volume from this volume group is initially mounted at /mnt/design/users:

  1. Stop all users/processes/application which is accessing the filesystem and then unmount the filesystem ( If required make use of "rescue" mode ). Make sure that no users are accessing files on the active volume.

    # umount /mnt/design/users
    
  2. Mark the volume group inactive. Marking the volume group inactive removes it from the kernel and prevents any further activity on it.

     # vgchange -an design
     vgchange -- volume group "design" successfully deactivated
    
  3. Export the volume group. This prevents it from being accessed on the "old" host system and prepares it to be removed.

    # vgexport design
     vgexport -- volume group "design" successfully exported
    
  4. When the machine is shut down, the disk can be unplugged and then connected to it's new machine.

  5. When plugged into the new system it becomes /dev/sdb so an initial pvscan shows:

    # pvscan
    pvscan -- reading all physical volumes (this may take a while...)
    pvscan -- inactive PV "/dev/sdb1"  is in EXPORTED VG "design" [996 MB / 996 MB free]
    pvscan -- inactive PV "/dev/sdb2"  is in EXPORTED VG "design" [996 MB / 244 MB free]
    pvscan -- total: 2 [1.95 GB] / in use: 2 [1.95 GB] / in no VG: 0 [0]
    

    In RHEL9, update the device file with imported PV.

     # lvmdevices --adddev /dev/path_to_disk 
    
  6. Import the volume group.

    • If importing on an LVM 2 system, run:
    # vgimport design
    Volume group "design" successfully imported
    
    • If importing on an LVM 1 system, add the PVs that need to be imported:
    # vgimport design /dev/sdb1 /dev/sdb2
    vgimport -- doing automatic backup of volume group "design"
    vgimport -- volume group "design" successfully imported and activated
    
  7. Activate the volume group.

    # vgchange -ay design
    
  8. Mount the file system.

    # mkdir -p /mnt/design/users
    # mount /dev/design/users /mnt/design/users
    

To make the change persistent after a system reboot put the entry below in /etc/fstab file:

/dev/design/users   /mnt/design/users    ext3   defaults 0 0

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments