qcow2 is an image for qemu and it's good to emulate.
I know how to write data for qcow2 format, but I don't know how backing files in qcow2 work?
I found nothing tutorial said this.
Can anyone give me tips?
Backing file is external snapshot for qcow2 and the qemu will write COW data in the new image.
For example:
You have image A  and B, and A is backing file of B.
When you mount B to /dev/nbd and check its data, you'll find you can saw data of A.
That's because if there's no data in the range of B, qemu will read the same range of A.
An important notes: If qemu doesn't find A, you won't be able to mount B on /dev/nbd.
How backing file works in qcow2?