12.5. 检查虚拟磁盘的一致性
在将磁盘镜像附加到虚拟机(VM)之前,请确保磁盘镜像没有问题,如损坏或碎片太多。为此,您可以使用 qemu-img check 命令。
如果需要,您还可以使用这个命令来尝试修复磁盘镜像。
先决条件
- 任何使用磁盘镜像的虚拟机(VM)都必须已关闭。
流程
对您要测试的镜像使用
qemu-img check命令。例如:# qemu-img check <test-name.qcow2> No errors were found on the image. 327434/327680 = 99.92% allocated, 0.00% fragmented, 0.00% compressed clusters Image end offset: 21478375424如果对磁盘镜像的检查发现问题,则命令的输出类似如下:
167 errors were found on the image. Data may be corrupted, or further writes to the image may corrupt it. 453368 leaked clusters were found on the image. This means waste of disk space, but no harm to data. 259 internal errors have occurred during the check. Image end offset: 21478375424要尝试修复检测到的问题,请使用
qemu-img check命令和all选项。但请注意,这可能只修复一些问题。警告修复磁盘镜像可能导致数据损坏或其他问题。在尝试修复前备份磁盘镜像。
# qemu-img check -r all <test-name.qcow2> [...] 122 errors were found on the image. Data may be corrupted, or further writes to the image may corrupt it. 250 internal errors have occurred during the check. Image end offset: 27071414272此输出表示在修复后磁盘镜像上发现的问题的数量。
-
如果需要进一步的磁盘镜像修复,您可以使用
guestfishshell 中的各种libguestfs工具。