First we need to have qemu installed on the system, for most of Linux systems, we can install “qemu-utils” for Windows we can download QEMU disk image utility from here
related questions
How to open raw disk from VMware
How to open qcow2 disk from VMware
How to open vdi disk from VMware
How to open raw disk from Hyper-V
How to open qcow2 disk from Hyper-V
How to open vdi disk from Hyper-V
How to open raw disk from VirtualBox
How to open qcow2 disk from VirtualBox
How to open vhdx disk from VirtualBox
How to open vmdk disk from VirtualBox
How to open vdi disk from kvm, Xen
How to open vmdk disk from kvm, Xen
How to open vhdx disk from kvm, Xen
How to open vmdk disk from kvm, Xen
…
For all those questions, we can just convert the exiting virtual disk/disk image to the correct format by following the guide, then attach to the correct format to the software
qemu-img command supported formats
Image format | Argument for -f and -O options |
---|---|
QCOW2 (KVM, Xen) | qcow2 |
RAW | raw |
VMDK (VMware) | vmdk |
VHD (Hyper-V) | vpc |
VHDX (Hyper-V) | vhdx |
VDI (VirtualBox) | vdi |
Convert from raw to qcow2
qemu-img convert -f raw -O qcow2 /data/source.raw /data/output.qcow2 -p
–f: Source file format (Can be omitted, the command will recognize the format automatically)
-O: Output format
-p: Show the progress bar (Optional)
# We can also use following command
qemu-img convert -f raw -O qcow2 /data/source.img /data/output.qcow2 -p
Convert from qcow2 to raw
qemu-img convert -O raw /data/source.qcow2 /data/output.raw
Convert vmdk, vhd, vhdx, vdi to raw
qemu-img convert -O raw /data/source.vmdk /data/output.raw qemu-img convert -O raw /data/source.vpc /data/output.raw qemu-img convert -O raw /data/source.vhdx /data/output.raw qemu-img convert -O raw /data/source.vdi /data/output.raw
Convert raw, vmdk, vpc, vhdx, vdi to qcow2
qemu-img convert -O qcow2 /data/source.raw /data/output.qcow2 qemu-img convert -O qcow2 /data/source.vmdk /data/output.qcow2 qemu-img convert -O qcow2 /data/source.vpc /data/output.qcow2 qemu-img convert -O qcow2 /data/source.vhdx /data/output.qcow2 qemu-img convert -O qcow2 /data/source.vdi /data/output.qcow2
Convert qcow2, raw, vpc, vhdx, vdi to vmdk
qemu-img convert -O vmdk /data/source.qcow2 /data/output.vmdk qemu-img convert -O vmdk /data/source.raw /data/output.vmdk qemu-img convert -O vmdk /data/source.vpc /data/output.vmdk qemu-img convert -O vmdk /data/source.vhdx /data/output.vmdk qemu-img convert -O vmdk /data/source.vdi /data/output.vmdk
Convert qcow2, raw, vmdk, vhdx, vdi to vpc
qemu-img convert -O vpc /data/source.qcow2 /data/output.vpc qemu-img convert -O vpc /data/source.raw /data/output.vpc qemu-img convert -O vpc /data/source.vmdk /data/output.vpc qemu-img convert -O vpc /data/source.vhdx /data/output.vpc qemu-img convert -O vpc /data/source.vdi /data/output.vpc
Convert qcow2, raw, vmdk, vpc, vdi to vhdx
qemu-img convert -O vhdx /data/source.qcow2 /data/output.vhdx qemu-img convert -O vhdx /data/source.raw /data/output.vhdx qemu-img convert -O vhdx /data/source.vmdk /data/output.vhdx qemu-img convert -O vhdx /data/source.vpc /data/output.vhdx qemu-img convert -O vhdx /data/source.vdi /data/output.vhdx
Convert qcow2, raw, vmdk, vpc, vhdx to vdi
qemu-img convert -O vdi /data/source.qcow2 /data/output.vdi qemu-img convert -O vdi /data/source.raw /data/output.vdi qemu-img convert -O vdi /data/source.vmdk /data/output.vdi qemu-img convert -O vdi /data/source.vpc /data/output.vdi qemu-img convert -O vdi /data/source.vhdx /data/output.vdi
Bonus
Create a virtual disk
qemu-img create -f raw -o size 10G /data/disk.raw
-f: Disk format
-o: Options, list of format specific options, name1=value1, name2=value2 etc. e.g. size=10G
Get into about a virtual disk
qemu-img info source.qcow2
Check virtual disk consistency (Only supports qcow2, vdi as of writing)
qemu-img check source.qcow2
Take Snapshot
qemu-img snapshot /data/source.qcow2 - /data/source.qcow2.snapshot
Note: raw format does not support snapshot, qcow2 does support snapshot
List snapshot
qemu-img snapshot /data/source.qcow2 -l
Delete snapshot
qemu-img snapshot -d /data/source.qcow2 # Delete specific snapshot with snapshot ID (2 in this example) qemu-img snapshot -d 2 /data/source.qcow2
Resize
qemu-img resize /data/disk +1G
Note: We can increase and decrease size on raw format, size of qcow2 format can only be increased
Reference : https://dannyda.com/2020/06/25/how-to-use-qemu-img-command-to-convert-between-vmdk-raw-qcow2-vdi-vhd-vhdx-formats-disk-images-qemu-img-create-snapshot-resize-etc/