Mounting LVM with same PV, LV, VG names as system

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/bingtianxuedi111/article/details/102392865

What happens when we try to use a disk that has the same LVM names as our system?

[root@st ~]# pvs
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda3  centos lvm2 a--  99.00g 4.00m

[root@st ~]# lvs
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----  6.99g
  opt  centos -wi-ao---- 20.00g
  root centos -wi-ao---- 32.00g
  swap centos -wi-ao----  4.00g
  tmp  centos -wi-ao----  4.00g
  var  centos -wi-ao---- 32.00g

[root@st ~]# vgdisplay
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               6
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               u5BLZG-ds9z-6dRh-0AI7-kAxD-n6lh-cvkKEw

[root@st ~]# vgrename aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl recover
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because of previous preference.
  Volume group "aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl" not found
  Cannot process volume group aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl

We can use vgimportclone to rename the extra volume names and then use. However if we do this the volume group will be permanently renamed. To mount on a target system with the original name, we need to boot from CDROM and rename the volume back.

[root@pe-test-st ~]# vgimportclone --basevgname recover /dev/sdb3
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.

[root@pe-test-st ~]# lvs
  LV   VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos  -wi-ao----  6.99g
  opt  centos  -wi-ao---- 20.00g
  root centos  -wi-ao---- 32.00g
  swap centos  -wi-ao----  4.00g
  tmp  centos  -wi-ao----  4.00g
  var  centos  -wi-ao---- 32.00g
  home recover -wi-------  6.99g
  opt  recover -wi------- 20.00g
  root recover -wi------- 32.00g
  swap recover -wi-------  4.00g
  tmp  recover -wi-------  4.00g
  var  recover -wi------- 32.00g

[root@pe-test-st ~]# vgchange -a y  recover
  6 logical volume(s) in volume group "recover" now active

[root@pe-test-st ~]# ls /dev/recover/
home  opt  root  swap  tmp  var

[root@pe-test-st ~]# mount -o ro,norecovery,nouuid /dev/recover/root /mnt

[root@pe-test-st ~]# ls /mnt
1    boot   dev  home  lib64       media  nsr  proc  run   srv  tmp  var
bin  cdrom  etc  lib   lost+found  mnt    opt  root  sbin  sys  usr

猜你喜欢

转载自blog.csdn.net/bingtianxuedi111/article/details/102392865