qemu-img 虚拟文件格式转换

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: 1755028391
    parent cid: 4294967295
    create type: monolithicSparse
    extents:
        [0]:
            virtual size: 21474836480
            filename: ubuntu-server-01.vmdk
            cluster size: 65536
            format: 

将 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.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: 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
posted @ 2025-02-15 03:38  小吉猫  阅读(166)  评论(0)    收藏  举报