Examples of how to use qemu-img
and qemu-nbd
for various disk image operations.
Mounting Raw Image via kpartx & Loop Device
Mounting Qcow2 via NBD
~ # modprobe nbd ~ # qemu-nbd --port 10999 --connect=/dev/nbd0 disk.qcow2 ~ # nbd-client localhost 10999 /dev/nbd0
Converting VirtualBox Images for KVM
~ # VBoxManage clonehd --format RAW input.vdi output.img ~ # qemu-img convert -f raw output.img -O qcow2 output.qcow2
Converting KVM Qcow2 to VirtualBox VDI
Compacting qcow2 Image Files
You have to zerofill the data on the disk first.
root@guest # sfill -fllvz
Then clone the image file
root@host # qemu-img convert -p -O qcow2 ./source.img ./packed.img