15.6. 使用 CLI 管理虚拟磁盘镜像


虚拟磁盘镜像是 虚拟存储卷 的一种类型,以类似于作为硬盘为物理机器提供存储的方式向虚拟机(VM)提供存储。

在创建新虚拟机 时,libvirt 会自动创建一个新磁盘镜像,除非您另有指定。但是,根据您的用例,您可能希望创建和管理独立于虚拟机的磁盘镜像。

15.6.1. 使用 qemu-img 创建虚拟磁盘镜像

如果您需要一个独立于新虚拟机(VM)的新的虚拟磁盘镜像 创建一个存储卷 对您来说是不可行的,您可以使用 qemu-img 命令行工具。

流程

  • 使用 qemu-img 工具创建一个虚拟磁盘镜像:

    # qemu-img create -f <format> <image-name> <size>

    例如,以下命令创建一个名为 test-image 的 qcow2 磁盘镜像,大小为 30GB:

    # qemu-img create -f qcow2 test-image 30G
    
    Formatting 'test-img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=32212254720 lazy_refcounts=off refcount_bits=16

验证

  • 显示您创建的镜像的信息,并检查它是否具有所需的大小,且没有报告任何损坏:

    # qemu-img info <test-img>
    image: test-img
    file format: qcow2
    virtual size: 30 GiB (32212254720 bytes)
    disk size: 196 KiB
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        compression type: zlib
        lazy refcounts: false
        refcount bits: 16
        corrupt: false
        extended l2: false
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部