13.5. 检查虚拟磁盘的一致性


在将磁盘镜像附加到虚拟机(VM)之前,请确保磁盘镜像没有问题,如损坏或碎片太多。为此,您可以使用 qemu-img check 命令。

如果需要,您还可以使用这个命令来尝试修复磁盘镜像。

先决条件

  • 任何使用磁盘镜像的虚拟机(VM)都必须已关闭。

流程

  1. 对您要测试的镜像使用 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
    Copy to Clipboard Toggle word wrap

    如果对磁盘镜像的检查发现问题,则命令的输出类似如下:

    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
    Copy to Clipboard Toggle word wrap
  2. 要尝试修复检测到的问题,请使用 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
    Copy to Clipboard Toggle word wrap

    此输出表示在修复后磁盘镜像上发现的问题的数量。

  3. 如果需要进一步的磁盘镜像修复,您可以使用 guestfish shell 中的各种 libguestfs 工具。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat