qemu-img is a powerful command-line tool that lets youcreate, convert, and inspect virtual machine disk imageswith ease.It supports a wide range of image formats, including:QCOW2– the most common format with snapshot supportRAW– simple and fast, great for performanceVDI– used by VirtualBoxVMDK– VMware’s disk format…and many moreWithqemu-img, you can:Create new virtual machine disksConvert images between different formatsCheck and repair disk imagesResize or modify virtual machine disksPerfect for anyone working withKVM, Proxmox, VirtualBox, or VMwareenvironments.Example 1: Create a New ImageLet us create an image in the default libvirt storage pool path.sudo qemu-img create -f qcow2 /var/lib/libvirt/images/deb12.qcow220GCopy-f qcow2: Specifies the image format (QCOW2 is a common format for QEMU/KVM).20G: Creates a 20GB virtual disk.A virtual machine that uses the disk image can be created usingvirt-installsudo virt-install \ --namedebian12\ --ram4096\ --vcpus2\ --disk path/var/lib/libvirt/images/deb12.qcow2\ --os-variantdebian12\ --network bridgevirbr0 \ --graphics none \ --console pty,target_typeserial \ --location/var/lib/libvirt/images/debian-12.7.0-amd64-DVD-1.iso\ --extra-args consolettyS0,115200n8CopyInstallation will start in text mode.... ┌───────────────────────┤ [!!] Select a language ├────────────────────────┐ │ │ │ Choose the language to be used for the installation process. The │ │ selected language will also be the default language for the installed │ │ system. │ │ │ │ Language: │ │ │ │ C │ │ English │ │ │ │ Go Back │ │ │ └─────────────────────────────────────────────────────────────────────────┘ Tab moves; Space selects; Enter activates buttonsCopyExample 2: Resize an ImageWe can resize an image by adding extra10GBto it usingresizecommand option:qemu-img resize /var/lib/libvirt/images/deb12.qcow2 10GCopyExample 3: Inspect an ImageTheqemu-img infocommand provides detailed information about a virtual machine disk image, including its format, size, and metadata.qemu-img info /var/lib/libvirt/images/deb12.qcow2CopyExample 4: Converting between image formatsIt is generally straightforward to convert images from one format to another usingqemu-img:Image formatArgument to qemu-imgQCOW2 (KVM, Xen)qcow2QED (KVM)qedrawrawVDI (VirtualBox)vdiVHD (Hyper-V)vpcVMDK (VMware)vmdkRefer to the examples below to learn how image conversion can be done from one format to the other.Example 5: Grow image / filesystemGet default filesystem disk size usingqemu-img:IMAGEubuntu-24.04-amd64.img qemu-img info $IMAGECopyIn the output, we can confirm the disk size before growing it.image: ubuntu-24.04-amd64.img file format: qcow2 virtual size: 3.5 GiB (3758096384 bytes) disk size: 581 MiB cluster_size: 65536 Format specific information: compat: 1.1 compression type: zlib lazy refcounts: false refcount bits: 16 corrupt: false extended l2: false Child node /file: filename: ubuntu-24.04-amd64.img protocol type: file file length: 581 MiB (608755712 bytes) disk size: 581 MiBCopySuppose we want to grow disk size by20GBqemu-img resize $IMAGE 20GCopyConfirmation after the change:$ qemu-img info $IMAGE image: ubuntu-24.04-amd64.img file format: qcow2 virtual size: 23.5 GiB (25232932864 bytes) ...CopyThe-f formatflag is optional. If omitted,qemu-imgwill try to infer the image format.Convert a raw image file to a qcow2 image file.qemu-img convert -f raw -O qcow2 image.img image.qcow2Copyconvert a vmdk image file to a raw image file.qemu-img convert -f vmdk -O raw image.vmdk image.imgCopyConvert a vmdk image file to a qcow2 image file.qemu-img convert -f vmdk -O qcow2 image.vmdk image.qcow2CopyConvert qcow2 to vdiqemu-img convert -O vdi test.qcow2 test.vdiCopyConvert qcow2 to rawqemu-img convert -O raw test.qcow2 test.rawCopyConvert qcow2 to vmdkqemu-img convert -O vmdk test.qcow2 test.vmdk