LVM分区信息备份文件路径:/etc/lvm/backup

擦除lvm信息,模拟故障

# dd if=/dev/zero of=/dev/sdb bs=512 count=1 seek=1

损坏硬盘在新主机的信息

# 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               85775bb6-ab14-4b77-ad24-4e92ab5e353d   
└─sdb2                                                                   
sr0     

查看备份文件中PV的ID

# cat /etc/lvm/backup/oldcentos
......
       physical_volumes {

		pv0 {
			id = "zwxJ3m-rDEd-L1dM-wYnA-kfHM-m4ps-gyRP0p"
			device = "/dev/sdb2"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 249559040	# 118.999 Gigabytes
			pe_start = 2048
			pe_count = 30463	# 118.996 Gigabytes
		}
	}
......

修复pv

#  pvcreate -f --uuid  "zwxJ3m-rDEd-L1dM-wYnA-kfHM-m4ps-gyRP0p" --restorefile /etc/lvm/backup/oldcentos /dev/sdb2
  Couldn't find device with uuid zwxJ3m-rDEd-L1dM-wYnA-kfHM-m4ps-gyRP0p.
  Physical volume "/dev/sdb2" successfully created.

# 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               85775bb6-ab14-4b77-ad24-4e92ab5e353d   
└─sdb2          LVM2_member       zwxJ3m-rDEd-L1dM-wYnA-kfHM-m4ps-gyRP0p 
sr0        

修复VG

# vgcfgrestore -f /etc/lvm/backup/oldcentos oldcentos 
  Restored volume group oldcentos
# vgs
  VG     #PV #LV #SN Attr   VSize    VFree
  centos   1   3   0 wz--n-  <99.00g 4.00m
  oldcentos   1   3   0 wz--n- <119.00g 4.00m
# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos    -wi-ao---- 46.99g                                                    
  home oldcentos -wi------- 66.99g                                                    
  root centos    -wi-ao---- 50.00g                                                    
  root oldcentos -wi------- 50.00g                                                    
  swap centos    -wi-ao----  2.00g                                                    
  swap oldcentos -wi-------  2.00g   

启用VG,挂在测试

# vgchange -ay oldcentos
  3 logical volume(s) in volume group "oldcentos" now active
# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos    -wi-ao---- 46.99g                                                    
  home oldcentos -wi-a----- 66.99g                                                    
  root centos    -wi-ao---- 50.00g                                                    
  root oldcentos -wi-a----- 50.00g                                                    
  swap centos    -wi-ao----  2.00g                                                    
  swap oldcentos -wi-a-----  2.00g   
# mount /dev/oldcentos/root /opt
# ll -h /opt/root/
total 1.1G
-rw-------. 1 root root 1.3K Oct 26 20:05 anaconda-ks.cfg
-rw-r--r--. 1 root root 1.0G Oct 26 20:11 test

用相关工具检查文件系统健康

# xfs_repair /dev/newcentos/root 
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done