7.4. 修复物理卷元数据
如果不小心覆盖或者破坏了卷组物理卷元数据区域,您会看到出错信息显示元数据区域不正确,或者系统无法使用特定的 UUID 找到物理卷。您可能需要通过在物理卷的元数据区域写入新的元数据来修复物理卷数据,指定相同的 UUID 作为丢失的元数据。
警告
在正常的 LVM 逻辑卷中您应该不会进行这个操作过程。如果您指定了不正确的 UUID,您会丢失您的数据。
下面的例子显示排序的输出解个,您可以看到您的元数据是丢了还是被破坏了。
通过查看
/etc/lvm/archive 目录,您可能可以找到被覆盖的物理卷 UUID。在文件 VolumeGroupName_xxxx.vg 中查找该卷组最后的有效归档 LVM 元数据。
另外,您可以找到失活的卷并设定
partial (-P)选项,这样您就可以找到丢失的被破坏的物理卷的 UUID。
Use the
--uuid and --restorefile arguments of the pvcreate command to restore the physical volume. The following example labels the /dev/sdh1 device as a physical volume with the UUID indicated above, FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk. This command restores the physical volume label with the metadata information contained in VG_00050.vg, the most recent good archived metadata for the volume group. The restorefile argument instructs the pvcreate command to make the new physical volume compatible with the old one on the volume group, ensuring that the new metadata will not be placed where the old physical volume contained data (which could happen, for example, if the original pvcreate command had used the command line arguments that control metadata placement, or if the physical volume was originally created using a different version of the software that used different defaults). The pvcreate command overwrites only the LVM metadata areas and does not affect the existing data areas.
pvcreate --uuid "FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk" --restorefile /etc/lvm/archive/VG_00050.vg /dev/sdh1
# pvcreate --uuid "FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk" --restorefile /etc/lvm/archive/VG_00050.vg /dev/sdh1
Physical volume "/dev/sdh1" successfully created
You can then use the
vgcfgrestore command to restore the volume group's metadata.
vgcfgrestore VG
# vgcfgrestore VG
Restored volume group VG
现在您可以显示逻辑卷。
lvs -a -o +devices
# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Devices
stripe VG -wi--- 300.00G /dev/sdh1 (0),/dev/sda1(0)
stripe VG -wi--- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
下面的命令激活卷并显示激活的卷。
如果磁盘中的 LVM 元数据使用至少覆盖了它的数据的空间大小,这个命令可以恢复物理卷。如果覆盖元数据的数据超过了元数据区域,那么就有可能损害到卷中的数据。您可能可以使用
fsck 命令修复那些数据。