问题

挂上故障硬盘后LVM操作会出现多重PV告警

# 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: Not using device /dev/sdb2 for PV eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG.
  WARNING: PV eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG prefers device /dev/sda2 because device is used by LV.
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <99.00g 4.00m

查看分区信息(由于新主机和故障主机是相同模板部署,可观察到两块硬盘UUID一致)

# lsblk -f
NAME            FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                      
├─sda1          xfs               a2bb0196-8c99-437d-b189-162a79cf17c5   /boot
└─sda2          LVM2_member       eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG 
  ├─centos-root xfs               08266a18-3bde-41bc-991b-afcf57578966   /
  ├─centos-swap swap              7c45b0d6-dd34-4fc2-bc80-433f2076de75   [SWAP]
  └─centos-home xfs               8f4ac471-bcab-4581-b132-40937d674493   /home
sdb                                                                      
├─sdb1          xfs               a2bb0196-8c99-437d-b189-162a79cf17c5   
└─sdb2          LVM2_member       eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG 
sr0  

导入并重命名复制LVM卷组

# vgimportclone -n newcentos /dev/sdb2
  WARNING: Not using device /dev/sdb2 for PV eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG.
  WARNING: PV eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG prefers device /dev/sda2 because device is used by LV.

查看更改后的lvm信息

# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda2  centos    lvm2 a--  <99.00g 4.00m
  /dev/sdb2  newcentos lvm2 a--  <99.00g 4.00m
# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  centos      1   3   0 wz--n- <99.00g 4.00m
  newcentos   1   3   0 wz--n- <99.00g 4.00m
# lvs
  LV   VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos    -wi-ao---- 46.99g                                                    
  root centos    -wi-ao---- 50.00g                                                    
  swap centos    -wi-ao----  2.00g                                                    
  home newcentos -wi------- 46.99g                                                    
  root newcentos -wi------- 50.00g                                                    
  swap newcentos -wi-------  2.00g  

启用vg

# vgchange newcentos -ay
  3 logical volume(s) in volume group "newcentos" now active
# lvs
  LV   VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos    -wi-ao---- 46.99g                                                    
  root centos    -wi-ao---- 50.00g                                                    
  swap centos    -wi-ao----  2.00g                                                    
  home newcentos -wi-a----- 46.99g                                                    
  root newcentos -wi-a----- 50.00g                                                    
  swap newcentos -wi-a-----  2.00g                                                    
[[email protected] ~]# lsblk -f
NAME               FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                         
├─sda1             xfs               a2bb0196-8c99-437d-b189-162a79cf17c5   /boot
└─sda2             LVM2_member       eM421B-tlch-czVB-UFau-VXmf-YeOq-0JZ7MG 
  ├─centos-root    xfs               08266a18-3bde-41bc-991b-afcf57578966   /
  ├─centos-swap    swap              7c45b0d6-dd34-4fc2-bc80-433f2076de75   [SWAP]
  └─centos-home    xfs               8f4ac471-bcab-4581-b132-40937d674493   /home
sdb                                                                         
├─sdb1             xfs               a2bb0196-8c99-437d-b189-162a79cf17c5   
└─sdb2             LVM2_member       nLKj0b-4xA3-AEO1-NB1l-aBBb-Ir2v-ckex0c 
  ├─newcentos-swap swap              7c45b0d6-dd34-4fc2-bc80-433f2076de75   
  ├─newcentos-home xfs               8f4ac471-bcab-4581-b132-40937d674493   
  └─newcentos-root xfs               08266a18-3bde-41bc-991b-afcf57578966   
sr0                                             

挂载(这里仅挂载root,其他诸如home按照以下步骤操作即可)

由于lvm的UUID依旧一致,会导致挂载失败,有以下两种处理方式

1.mount使用禁止uuid参数挂载

mount -o nouuid /dev/mapper/newcentos-root /opt/

2.修改uuid

# xfs_admin -U generate /dev/mapper/newcentos-root 
Clearing log and setting UUID
writing all SBs
new UUID = 5a462c67-9795-4f95-ac19-430ff34c6448

# mount /dev/mapper/newcentos-root /opt/

测试(查看挂载盘数据是否有异常)

# df -Th
Filesystem                 Type      Size  Used Avail Use% Mounted on
devtmpfs                   devtmpfs  908M     0  908M   0% /dev
tmpfs                      tmpfs     919M     0  919M   0% /dev/shm
tmpfs                      tmpfs     919M  8.6M  911M   1% /run
tmpfs                      tmpfs     919M     0  919M   0% /sys/fs/cgroup
/dev/mapper/centos-root    xfs        50G  1.3G   49G   3% /
/dev/sda1                  xfs      1014M  150M  865M  15% /boot
/dev/mapper/centos-home    xfs        47G   33M   47G   1% /home
tmpfs                      tmpfs     184M     0  184M   0% /run/user/0
/dev/mapper/newcentos-root xfs        50G  1.3G   49G   3% /opt