1. 3.10.1 qemu-img 命令

qemu-img 是 QEMU 的磁盘管理工具。qemu-img 工具的命令行基本用法如下:
qemu-img [standard options] command [command options]
常用的几种命令如下:


1.1. 1. check [-f fmt] filename

对磁盘镜像文件进行一致性检查,查找镜像文件中的错误。

# qemu-img check -f qcow2 test.qcow2
No errors were found on the image.
96063/819200 = 11.73% allocated, 88.04% fragmented, 86.12% compressed clusters
Image end offset: 2974613504

1.2. 2. create [-f fmt] [-b backing_file] [-o options] filename [size]

  • 创建一个格式为 fmt,大小为 size,文件名为 filename 的镜像文件。根据文件格式的不同,还可以添加一个或多个选项(options)来附加对文件的各种功能的设置。
  • “-b backing_file” 参数和 “-o backing_file=backfile” 参数效果一样。指定了后端镜像文件,创建的镜像文件仅记录与后端文件的差异部分。后端镜像文件不会被修改,除非在 QEMU monitor 中使用 “commit” 命令或使用 “qemu-img commit” 命令手动提交这些改动。这种情况下,size 参数不是必需的,默认值为后端镜像文件的大小。
  • size 选项用于指定镜像文件的大小,默认单位为字节(bytes),也支持 k、M、G、T,分别表示 kB、MB、GB、TB大小。
# qemu-img create -f qcow2 -o backing_file=Loongnix-server-20-loongarch64.qcow2,size=50G kvm-test.qcow2
Formatting 'kvm-test.qcow2', fmt=qcow2 size=53687091200 backing_file=Loongnix-server-20-loongarch64.qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16

# qemu-img create -f qcow2 kvm-test.qcow2 10G
Formatting 'kvm-test.qcow2', fmt=qcow2 size=10737418240 cluster_size=65536 lazy_refcounts=off refcount_bits=16

1.3. 3. commit [-f fmt] filename

提交 filename 文件中的更改到后端支持镜像文件中。

1.4. 4. convert -c [-f fmt] [-O output_fmt] [-o options] filename [filename2 [...]] output_filename

  • 将 fmt 格式的 filename 镜像文件根据 options 选项转换为格式为 output_fmt 的、名为 output_filename 的镜像文件。
  • “-c” 参数表示对输出的镜像文件进行压缩。 例如:
    # qemu-img convert -c -f qcow2 -O qcow2 test.qcow2 qcow2.backup
    

1.5. 5. info [-f fmt] filename

展示 filename 镜像文件的信息。

# qemu-img info test.qcow2 
image: test.qcow2
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 2.8G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

1.6. 6. snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename

  • “-l snapshot” 选项表示查询并列出镜像文件中的所有快照;
  • “-a snapshot” 选项表示让镜像文件使用某个快照;
  • “-c snapshot” 选项表示创建一个快照;
  • “-d snapshot” 选项表示删除一个快照。

1.7. 7.resize filename [--shrink] [+ | -]size

  • 改变镜像文件的大小。“+” 和 "-" 分别表示增加和减少镜像文件的大小,size 也支持 k、M、G、T 等单位。
  • “-size” 参数 必须与 “--shrink” 一起使用。
# qemu-img resize --shrink kvm-test.qcow2 -1G
Image resized.

# qemu-img resize kvm-test.qcow2 +2G
Image resized.
©龙芯开源社区 all right reserved,powered by Gitbook文档更新时间: 2023-05-19 06:36:14

results matching ""

    No results matching ""

    results matching ""

      No results matching ""