The ask here is to merge 2 volume groups with existing LVs and there should be no data loss. For the purpose of this post, we have 2 VGs – vg01 and vg02. Both have one LV each created inside them as shown below :

# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  cl     1   2   0 wz--n- 19.00g     0 
  vg01   1   1   0 wz--n- 20.00g 10.00g
  vg02   1   1   0 wz--n- 20.00g 10.00g
# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root cl   -wi-ao---- 17.00g                                                    
  swap cl   -wi-ao----  2.00g                                                    
  lv01 vg01 -wi-a----- 10.00g                                                    
  lv02 vg02 -wi-a----- 10.00g
# ls -lrt /dev/mapper/*
crw-------. 1 root root 10, 236 Oct  6 18:25 /dev/mapper/control
lrwxrwxrwx. 1 root root       7 Oct  6 18:25 /dev/mapper/cl-swap -> ../dm-1
lrwxrwxrwx. 1 root root       7 Oct  6 18:25 /dev/mapper/cl-root -> ../dm-0
lrwxrwxrwx. 1 root root       7 Oct  6 18:28 /dev/mapper/vg01-lv01 -> ../dm-2
lrwxrwxrwx. 1 root root       7 Oct  6 18:28 /dev/mapper/vg02-lv02 -> ../dm-3

Prerequisites for merging VGs

Before merging the two VGs into one make sure you have the below prerequisites met.
1. The logical volumes in the VG must be unique. They can be renamed before being moved (merged) if needed.
2. The PV extent size must be the same for both volume groups

=============================================================

Merging VGs with vgmerge

We can merge the VGs vg01 and vg02 into one single VG vg01. So, in other words, we want to get rid of VG vg02 without losing any data inside it. Follow the steps below :

1. Umount the mount points under both the VGs.

# umount /data01
# umount /u02

2. Deactivate the volume group we want to remove and merge with another VG. In our case it is vg02.

# vgchange -an vg02
  0 logical volume(s) in volume group "vg02" now active

3. Merge the volume groups

# vgmerge vg01 vg02
  Volume group "vg02" successfully merged into "vg01"

4. Activate the Logical volumes merged from vg02. In our case, we have only one volume from vg02, i.e. lv02:

# lvchange -ay vg01/lv02

Verify

Verify the VG and LVs if they are merged. You should now see both the LVs under the same VG.

# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  cl     1   2   0 wz--n- 19.00g     0 
  vg01   2   2   0 wz--n- 39.99g 19.99g
# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root cl   -wi-ao---- 17.00g                                                    
  swap cl   -wi-ao----  2.00g                                                    
  lv01 vg01 -wi-a----- 10.00g                                                    
  lv02 vg01 -wi-a----- 10.00g
# ls -lrt /dev/mapper/*
crw-------. 1 root root 10, 236 Oct  6 18:25 /dev/mapper/control
lrwxrwxrwx. 1 root root       7 Oct  6 18:25 /dev/mapper/cl-swap -> ../dm-1
lrwxrwxrwx. 1 root root       7 Oct  6 18:25 /dev/mapper/cl-root -> ../dm-0
lrwxrwxrwx. 1 root root       7 Oct  6 18:28 /dev/mapper/vg01-lv01 -> ../dm-2
lrwxrwxrwx. 1 root root       7 Oct  6 18:37 /dev/mapper/vg01-lv02 -> ../dm-3