Emulate a Device over a QCOW2 image
Although this is an old question I think it should be worth to show an interesting alternative.
I had the same problem, but the provided answer from Michael Hampton would not fit for me as the amount of data I had to transfer was too big and the time I had to do the operation would not be enough.
So below is what I made:
Create an empty QCOW2 image
In destination, create an empty QCOW2 image, for example:
$ qemu-img create -f qcow2 myimage.qcow2 500g
Connect the QCOW2 image using NBD to a device
There is a tool that allows you to emulate a device on top of a QCOW2 image. This is mostly used to get access to QCOW2 contents, but the device is read-writable so you can treat it as a standard block device:
$ modprobe nbd
$ qemu-nbd --connect /dev/nbd0 myimage.qcow2
Now you have a /dev/nbd0
device that is a block device just like any block device but any operation done over it will be performed on the QCOW2 image
Perform the transfer over the emulated device
You can use any network command, for example ssh
and dd
to make the magic work:
$ dd if=myoriginalimg bs=100M | pv -tebrap --size 500g | ssh myhost dd of=/dev/nbd0 bs=100M
I added a plus using pv
so you can monitor the progress. I further advice you to run this command inside a screen
or tmux
session if it may take very long so you do not loose your job!
Close the emulator
After the transfer is complete, you have a ready and converted QCOW2 image on myimage.qcow2
, but make sure you disconnect the emulator so kernel don't get angry on you!
$ qemu-nbd --disconnect /dev/nbd0
You are done! Now you have a ready converted image transmitted from a raw format from a network origin directly to a QCOW2 file without intermediates