Search code examples
imageqemurebase

qemu-img commit complete backing chain or delete empty middle overlay


My current setup has three qcow2 images.

The layout is:

base (100GB) <- snap1 (empty) <- snap2 (80GB)

I don't want to commit that amount twice! Is it safe to rebase snap2 to base and then commit? If so. I guess I can rebase snap2 back to snap1 afterwards. Can't I?


Solution

  • I took matters in my own hands, since i don't wanted to wait for no answer for five years like in the only post i found about that question.

    Task: Removing the middle, rebase the outer to the base and back, again.

    base(system) <- middle(empty) <- outer(changes)
            to
    base(system) <- outer(changes)
            and back
    base(system) <- middle(empty) <- outer(changes)
    

    As long as the middle snapshot is empty, it is safe to use -u (unsafe). I didn't test if unsafe pulls data, yet.

    It does work. All what happens is, that the base seems to be read fully for validation. Removing AND inserting the/a snapshot in the middle is possible, if it is EMPTY. The check doesn't write anything, but when inserting a snapshot, it actually reads more than there is. Using the -u (unsafe) parameter makes this happen instantly. The base remains untouched and all changes remain within the outer snapshot. Since no commit was made, the middle snapshot remained empty the whole time.

    Task: The same, but the middle not empty.

    base(system) <- middle(changes) <- outer(empty or changes)
            to
    base(system) <- outer(empty or changes)
            back (doesn't make sense, read why)
    no
    

    This is a one way operation. You can only insert an empty snapshot into the middle, after rebasing the outer to the base. The whole base is read again and the data from the middle snapshot is pulled slowly upwards into the outer image. The middle snapshot can still be used, but rebasing the outer to it doesn't make any sense. You may delete it, if you don't want to branch. The data is available within the outer snapshot, now.