Show Table of Contents
6.4. 恢复物理卷元数据
如果不小心覆盖或者破坏了卷组物理卷元数据区域,则会看到出错信息显示元数据区域不正确,或者系统无法使用特定的 UUID 找到物理卷。此时可能需要通过在物理卷的元数据区域写入新的元数据来恢复物理卷数据,指定相同的 UUID 作为丢失的元数据。
警告
在正常的 LVM 逻辑卷中应该不会进行这个操作过程。如果指定了不正确的 UUID,则会丢失您的数据。
下面的例子显示排序的输出结果,可以看到您的元数据是丢了还是被破坏了。
# lvs -a -o +devices
Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Couldn't find all physical volumes for volume group VG.
Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Couldn't find all physical volumes for volume group VG.
...
通过查看
/etc/lvm/archive 目录,应该可以找到被覆盖的物理卷 UUID。在文件 VolumeGroupName_xxxx.vg 中查找该卷组最后的有效归档 LVM 元数据。
另外,还可以找到失活的卷并设定
partial (-P)选项,这样就可以找到丢失的被破坏的物理卷的 UUID。
# vgchange -an --partial
Partial mode. Incomplete volume groups will be activated read-only.
Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'.
...
使用
pvcreate 的 --uuid 和 --restorefile 选项恢复物理卷。下面的例子使用上述 UUID FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk 将 /dev/sdh1 设备标记为物理卷。这个命令使用 VG_00050.vg 中的元数据信息,即使用该卷组最新的好归档元数据恢复物理卷标签。restorefile 参数让 pvcreate 生成与卷组中旧的物理卷兼容的新物理卷,确保新的元数据不会被放在包含旧的物理卷元数据的区域(这有可能发生。例如:如果原始 pvcreate 命令使用了控制元数据放置位置的命令行参数,或者使用了应用不同默认选项的软件版本创建物理卷时,就会发生这种情况)。pvcreate 命令仅覆盖 LVM 元数据区域,不会影响现有的数据区域。
# pvcreate --uuid "FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk" --restorefile /etc/lvm/archive/VG_00050.vg /dev/sdh1
Physical volume "/dev/sdh1" successfully created
然后就可以使用
vgcfgrestore 命令恢复卷组的元数据。
# vgcfgrestore VG
Restored volume group VG
现在可以显示逻辑卷。
# 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)
下面的命令激活卷并显示激活的卷。
#lvchange -ay /dev/VG/stripe[root@link-07 backup]#lvs -a -o +devicesLV VG Attr LSize Origin Snap% Move Log Copy% Devices stripe VG -wi-a- 300.00G /dev/sdh1 (0),/dev/sda1(0) stripe VG -wi-a- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
如果磁盘中的 LVM 元数据至少使用了覆盖其数据的空间大小,这个命令可以恢复物理卷。如果覆盖元数据的数据超过了元数据区域,那么就有可能损害到卷中的数据。此时可以使用
fsck 命令修复那些数据。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.