does anyone know if it's possible to migrate a QCOW2 volume to a ZFS volume while preserving snapshots?
Yes, I know. You may also like to know the answer, do you
There is one catch: the history in the QCOW2 file must be linear, otherwise it does not work properly. You also have to keep in mind that you cannot switch between snapshots in ZFS as you can in QCOW2, therefore QCOW2's snapshots are more capable than then ZFS ones with respect to virtualisation.
Idea is like this:
- go to the oldest snapshot in your QCOW2, mount it via qemu-nbd
- copy the block device to your ZFS zvol, dd is fine as a test (*)
- snapshot your ZFS
- unmount your QCOW2 and go to the next snapshot
I hope that helps and gives you enough to create a working example.
(*) You should write your own block-based copy program that omits already present blocks from overwriting, because this is a new write on ZFS and needs space. If you only copy blocks that are different, you can have a 'copy-on-write' kinda snapshot that really only holds changed data.