I have a qemu image B.qcow2 that is a snapshot of A.qcow2. I created a copy of B.qcow2 by using cp B.qcow2 C.qcow2 and then worked on both B.qcow2 and C.qcow2 independently. Thus, B.qcow2 and C.qcow2 are eventually different but they have a common part (since C.qcow2 was copied from B.qcow2).

In order to save disk place, I wanted to know if it is possible (by using qemu-img or programmatically) to create another image common.qcow2 that will contain all common parts of B.qcow2 and C.qcow2, then remove this common part from B.qcow2 and C.qcow2 and rebase the images in such a way that B.qcow2 and C.qcow2 are based on common.qcow2 and common.qcow2 are based on A.qcow2?

1 Answer 1


The trick is to have one base image, and two images containing the differences to that. This can be implemented in the following way:

  1. To avoid confusion: mv B.qcow2 common.qcow2
  2. Rebase common on A: qemu-img rebase -b common.qcow2 A.qcow2
  3. Recreate B, based on common: git create -b common B.qcow2
  4. Rebase C on common: qemu-img rebase -b common.qcow2 C.qcow2

of course, now B.qcow2 is an "empty shell" with no changes relatively to common, and C contains all the changes between A and B, but there's no way to save any more space, and assuming it doesn't matter which of the two files contains the changes, this is as good as any other solution.

  • Thus, it seems i didn't understood how rebase worked exactly. I believe it does not only change a pointer but also check for differences Jul 5, 2021 at 14:27
  • 3
    In bullet 2., is that really git create -b common or could it be qemu-img create -b common.img?
    – A.B
    Jul 5, 2021 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .