convert 语法格式
qemu-img convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename
查看 vmdk 文件信息
qemu-img info ubuntu-server-01.vmdk
image: ubuntu-server-01.vmdk
file format: vmdk
virtual size: 20 GiB (21474836480 bytes)
disk size: 4.74 GiB
cluster_size: 65536
Format specific information:cid: 1755028391parent cid: 4294967295create type: monolithicSparseextents:[0]:virtual size: 21474836480filename: ubuntu-server-01.vmdkcluster size: 65536format:
将 vmdk 格式转为 raw 格式
转换格式
qemu-img convert ubuntu-server-01.vmdk ubuntu-server-01.img
查看 raw 文件信息
qemu-img info ubuntu-server-01.img
image: ubuntu-server-01.img
file format: raw
virtual size: 20 GiB (21474836480 bytes)
disk size: 4.65 GiB
查看文件大小
ls -lh
total 9.4G
-rw-r--r-- 1 root root 20G Jan 25 18:37 ubuntu-server-01.img
-rw-r--r-- 1 root root 4.8G Jan 25 18:32 ubuntu-server-01.vmdk
du -h ubuntu-server-01.*
4.7G ubuntu-server-01.img
4.8G ubuntu-server-01.vmdk
将 vmdk 格式转为 qcow2 格式
转换格式
qemu-img convert -f vmdk -O qcow2 ubuntu-server-01.vmdk ubuntu-server-01.qcow2
查看 qcow2 文件信息
qemu-img info ubuntu-server-01.qcow2
image: ubuntu-server-01.qcow2
file format: qcow2
virtual size: 20 GiB (21474836480 bytes)
disk size: 4.73 GiB
cluster_size: 65536
Format specific information:compat: 1.1lazy refcounts: falserefcount bits: 16corrupt: false
查看文件大小
ls -lh
total 15G
-rw-r--r-- 1 root root 20G Jan 25 18:37 ubuntu-server-01.img
-rw-r--r-- 1 root root 4.8G Jan 25 19:07 ubuntu-server-01.qcow2
-rw-r--r-- 1 root root 4.8G Jan 25 18:32 ubuntu-server-01.vmdk
du -h ubuntu-server-01.*
4.7G ubuntu-server-01.img
4.8G ubuntu-server-01.qcow2
4.8G ubuntu-server-01.vmdk