修复丢失的pv

在给RHEL进行扩容的时候提示有个lv找不到了。应该是分配给交换空间的lv找不到了,导致没法进行库容。下面是处理过程。

提示缺少一个pv导致无法继续


## 初始报错
[root@localhost ~]# pvdisplay
  /dev/rhel/swap: read failed after 0 of 4096 at 4294901760: 输入/输出错误
  /dev/rhel/swap: read failed after 0 of 4096 at 4294959104: 输入/输出错误
  WARNING: Device for PV iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE not found or rejected by a filter.
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               81PW3j-W2eg-19qX-27NN-e1zr-750q-7u5ZIy

  --- Physical volume ---
  PV Name               unknown device
  VG Name               rhel
  PV Size               2.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              511
  Free PE               9
  Allocated PE          502
  PV UUID               iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               rhel
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               2559
  Allocated PE          0
  PV UUID               UVulsk-WJ3R-y7ga-EYT7-dfd8-26hY-sUucWK

# 扩容分区报错
[root@localhost ~]# lvextend -L +10236m /dev/mapper/rhel-root
  WARNING: Device for PV iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE not found or rejected by a filter.
  Cannot change VG rhel while PVs are missing.
  Consider vgreduce --removemissing.

# 提示某个pv丢失了  
[root@localhost ~]# pvs
  /dev/rhel/swap: read failed after 0 of 4096 at 4294901760: 输入/输出错误
  /dev/rhel/swap: read failed after 0 of 4096 at 4294959104: 输入/输出错误
  WARNING: Device for PV iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE not found or rejected by a filter.
  PV             VG   Fmt  Attr PSize  PFree 
  /dev/sda2      rhel lvm2 a--  19.51g     0 
  /dev/sda3      rhel lvm2 a--  10.00g 10.00g
  unknown device rhel lvm2 a-m   2.00g 36.00m

添加一个磁盘

[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x14e3066c 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-8388607,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-8388607,默认为 8388607):
将使用默认值 8388607
分区 1 已设置为 Linux 类型,大小设为 4 GiB

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):L

 024  NEC DOS         81  Minix / 旧 Linu bf  Solaris        
 1  FAT12           27  隐藏的 NTFS Win 82  Linux 交换 / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 隐藏的 C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux 扩展      c7  Syrinx         
 5  扩展            41  PPC PReP Boot   86  NTFS 卷集       da  非文件系统数据 
 6  FAT16           42  SFS             87  NTFS 卷集       db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux 纯文本    de  Dell 工具      
 8  AIX             4e  QNX4.x 第2部分  8e  Linux LVM       df  BootIt         
 9  AIX 可启动      4f  QNX4.x 第3部分  93  Amoeba          e1  DOS 访问       
 a  OS/2 启动管理器 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad 休 eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 扩展 (LBA)  54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC  
11  隐藏的 FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq 诊断     5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  隐藏的 FAT16 <3 61  SpeedStor       ab  Darwin 启动     f2  DOS 次要       
16  隐藏的 FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  隐藏的 HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST 智能睡眠    65  Novell Netware  b8  BSDI swap       fd  Linux raid 自动
1b  隐藏的 W95 FAT3 70  DiskSecure 多启 bb  Boot Wizard 隐  fe  LANstep        
1c  隐藏的 W95 FAT3 75  PC/IX           be  Solaris 启动    ff  BBT            
1e  隐藏的 W95 FAT1 80  旧 Minix       
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# fdisk -l

磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00049ebe

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
/dev/sda3        41943040    62914559    10485760   8e  Linux LVM

磁盘 /dev/sdb:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x14e3066c

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     8388607     4193280   8e  Linux LVM

磁盘 /dev/mapper/rhel-root:18.8 GB, 18756927488 字节,36634624 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

fdisk: 打不开 /dev/mapper/rhel-swap-missing_2_0: 输入/输出错误


[root@localhost ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

[root@localhost ~]# pvs
  /dev/rhel/swap: read failed after 0 of 4096 at 4294901760: 输入/输出错误
  /dev/rhel/swap: read failed after 0 of 4096 at 4294959104: 输入/输出错误
  WARNING: Device for PV iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE not found or rejected by a filter.
  PV             VG   Fmt  Attr PSize  PFree 
  /dev/sda2      rhel lvm2 a--  19.51g     0 
  /dev/sda3      rhel lvm2 a--  10.00g 10.00g
  unknown device rhel lvm2 a-m   2.00g 36.00m

将新创建的pv管理到丢失的pv上

[root@localhost ~]# pvcreate --help
  pvcreate: Initialize physical volume(s) for use by LVM

pvcreate
        [--norestorefile]
        [--restorefile file]
        [--commandprofile ProfileName]
        [-d|--debug]
        [-f[f]|--force [--force]]
        [-h|-?|--help]
        [--labelsector sector]
        [-M|--metadatatype 1|2]
        [--pvmetadatacopies #copies]
        [--bootloaderareasize BootLoaderAreaSize[bBsSkKmMgGtTpPeE]]
        [--metadatasize MetadataSize[bBsSkKmMgGtTpPeE]]
        [--dataalignment Alignment[bBsSkKmMgGtTpPeE]]
        [--dataalignmentoffset AlignmentOffset[bBsSkKmMgGtTpPeE]]
        [--setphysicalvolumesize PhysicalVolumeSize[bBsSkKmMgGtTpPeE]
        [-t|--test]
        [-u|--uuid uuid]
        [-v|--verbose]
        [-y|--yes]
        [-Z|--zero {y|n}]
        [--version]
        PhysicalVolume [PhysicalVolume...]

[root@localhost ~]# pvcreate /dev/sdb1 --u iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE --norestorefile
  WARNING: Device for PV iUJdjw-C9S6-bRE7-jIdl-6kQ6-esLL-5vDGYE not found or rejected by a filter.
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvs
  /dev/rhel/swap: read failed after 0 of 4096 at 4294901760: 输入/输出错误
  /dev/rhel/swap: read failed after 0 of 4096 at 4294959104: 输入/输出错误
  PV         VG   Fmt  Attr PSize  PFree 
  /dev/sda2  rhel lvm2 a--  19.51g     0 
  /dev/sda3  rhel lvm2 a--  10.00g 10.00g
  /dev/sdb1  rhel lvm2 a-m   2.00g 36.00m

依旧报错

[root@localhost ~]# lvextend -L +10236m /dev/rhel/root
  Missing device /dev/sdb1 reappeared, updating metadata for VG rhel to version 7.
  Device still marked missing because of allocated data on it, remove volumes and consider vgreduce --removemissing.
  Cannot change VG rhel while PVs are missing.
  Consider vgreduce --removemissing.

强制移除丢失的lv


  [root@localhost ~]# vgreduce --removemissing rhel
  WARNING: Partial LV swap needs to be repaired or removed. 
  There are still partial LVs in VG rhel.
  To remove them unconditionally use: vgreduce --removemissing --force.
  Proceeding to remove empty missing PVs.
[root@localhost ~]# vgreduce --removemissing rhel --force
  Removing partial LV swap.
  Logical volume rhel/swap in use.

[root@localhost ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "rhel" using metadata type lvm2
[root@localhost ~]#  vgchange -a y 
  Refusing activation of partial LV rhel/swap.  Use '--activationmode partial' to override.
  2 logical volume(s) in volume group "rhel" now active

关闭交换空间

  [root@localhost ~]# lvs 
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 17.47g                                                    
  swap rhel -wi-ao--p-  4.00g                                                    
[root@localhost ~]# swapoff -v /dev/rhel/swap
swapoff /dev/rhel/swap
[root@localhost ~]# vgreduce --removemissing rhel
  WARNING: Partial LV swap needs to be repaired or removed. 
  There are still partial LVs in VG rhel.
  To remove them unconditionally use: vgreduce --removemissing --force.
  Proceeding to remove empty missing PVs.
[root@localhost ~]# vgreduce --removemissing rhel --force
  Removing partial LV swap.
  Logical volume "swap" successfully removed
  Wrote out consistent volume group rhel

这次允许扩容了

  [root@localhost ~]# lvextend -L +10236m /dev/rhel/root
  Size of logical volume rhel/root changed from 17.47 GiB (4472 extents) to 27.46 GiB (7031 extents).
  Logical volume root successfully resized.

参考文章:
http://blog.itpub.net/17203031/viewspace-774174/

你可能感兴趣的:(Linux/UNIX,Linux/UNIX运维实战)