SoFunction
Updated on 2025-03-04

CentOS mount lvm partition VG duplicate problem and solution

CentOS mount lvm partition VG rename problem

Volume Group (VG) is a combination of one or more physical volumes. Volume groups combine multiple physical volumes together to form a manageable unit similar to a physical hard disk in a non-LVM system.

Specific reasons

The operating system of one of the centos servers in the company's business cannot be started, and the data needs to be restored and the hard disk is mounted on a server that can be started normally. However, the problem of VG duplicate name occurs and the situation cannot be mounted.

Solution

As shown below:

1. Use pvs/lvs/vgs to view the specific LVM situation

[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  centos lvm2 a--  556.66g 4.00m
  /dev/sdc1  centos lvm2 a--  279.39g    0 
  /dev/sdd2  centos lvm2 a--  278.39g 4.00m
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-a----- 491.09g                                                    
  home centos -wi------- 495.97g                                                    
  root centos -wi-ao----  50.00g                                                    
  root centos -wi-------  50.00g                                                    
  swap centos -wi-ao----  15.56g                                                    
  swap centos -wi-------  11.81g

[root@localhost ~]# vgs -v
    Cache: Duplicate VG name centos: Prefer existing gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6 vs new WTOf0a-fVj9-lNK2-AJOU-Q4nA-xuVk-H9AYi4
    Cache: Duplicate VG name centos: Prefer existing gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6 vs new WTOf0a-fVj9-lNK2-AJOU-Q4nA-xuVk-H9AYi4
    Cache: Duplicate VG name centos: Prefer existing WTOf0a-fVj9-lNK2-AJOU-Q4nA-xuVk-H9AYi4 vs new gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6
    Archiving volume group "centos" metadata (seqno 4).
    Archiving volume group "centos" metadata (seqno 4).
    Creating volume group backup "/etc/lvm/backup/centos" (seqno 4).
  VG     Attr   Ext   #PV #LV #SN VSize    VFree VG UUID                                VProfile
  centos wz--n- 4.00m   1   3   0  556.66g 4.00m WTOf0a-fVj9-lNK2-AJOU-Q4nA-xuVk-H9AYi4         
  centos wz--n- 4.00m   2   3   0 <557.79g 4.00m gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6   

The above finds that the VG names of the LVM of the existing system and the mounted hard disk (failed system) are duplicated, and there are multiple LVs of root and home.

2. Rename through vg's uuid

If the name of VG is changed, an error will be reported and the name needs to be changed through UUID, where uuid is viewed through the above vgs -v

[root@localhost ~]# vgrename gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6 centos01
  Processing VG centos because of matching UUID gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6
  Volume group "gEVmfo-SGj8-B3Ij-9O3U-jd3a-TftX-OMVfY6" successfully renamed to "centos01"

3. Check the lv status

I found that there are several inactive

[root@localhost ~]# vgs
  VG       #PV #LV #SN Attr   VSize    VFree
  centos     1   3   0 wz--n-  556.66g 4.00m
  centos01   2   3   0 wz--n- <557.79g 4.00m
[root@localhost ~]# lvscan
  ACTIVE            '/dev/centos/swap' [15.56 GiB] inherit
  ACTIVE            '/dev/centos/home' [491.09 GiB] inherit
  ACTIVE            '/dev/centos/root' [50.00 GiB] inherit
  inactive          '/dev/centos01/swap' [11.81 GiB] inherit
  inactive          '/dev/centos01/home' [495.97 GiB] inherit
  inactive          '/dev/centos01/root' [50.00 GiB] inherit

4. Modify the properties of vg

[root@localhost ~]# vgchange -ay /dev/centos01
  3 logical volume(s) in volume group "centos01" now active
[root@localhost ~]# lvscan
  ACTIVE            '/dev/centos/swap' [15.56 GiB] inherit
  ACTIVE            '/dev/centos/home' [491.09 GiB] inherit
  ACTIVE            '/dev/centos/root' [50.00 GiB] inherit
  ACTIVE            '/dev/centos01/swap' [11.81 GiB] inherit
  ACTIVE            '/dev/centos01/home' [495.97 GiB] inherit
  ACTIVE            '/dev/centos01/root' [50.00 GiB] inherit

5. Mount the directory

[root@localhost ~]# cd /
[root@localhost /]# mkdir centos01-root
[root@localhost /]# mkdir centos01-home
[root@localhost /]# mount /dev/centos01/root /centos01-root/
[root@localhost /]# mount /dev/centos01/home /centos01-home/
[root@localhost /]# cd centos01-root
[root@localhost centos01-root]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  sk  srv  sys  tmp  usr  var

Through the above operations, the files can be recovered.

Summarize

These are just personal experience. I hope you can give me a reference and I hope you can support me more.