I have a qemu qcow2 disk snapshot dev.img
that is based off a backing file dev.bak
.
How can I merge both into a standalone devplus.img
, while leaving dev.bak
as it is?
Asked
Active
Viewed 1.1k times
18

Cristian Ciupitu
- 20,270
- 7
- 50
- 76

user2512377
- 501
- 1
- 3
- 9
2 Answers
18
I got some help from the qemu mailing list: First copy the original base file to your standalone image file:
cp dev.bak devplus.img
Then "rebase" the image file that was backed off the original file so that it uses the new file:
qemu-img rebase -b devplus.img dev.img
Then you can commit the changes in the dev file back into the new base:
qemu-img commit dev.img
Now you can use devplus.img as a standalone image file and get rid of dev.img if you wish, leaving the original dev.bak intact and not corrupting any other images that were based off it.

user2512377
- 501
- 1
- 3
- 9
11
qemu-img convert -O qcow2 dev.img devplus.img
This detects that dev.img is based off dev.bak and creates a standalone devplus.img.

Tigran Ghahramanyan
- 131
- 1
- 3
-
1Rebasing didn't work in my case, but this did - THANK YOU! (situation was: merging a "disk" snapshot, which was a mistake to create in the first place) – Jay Taylor Sep 20 '21 at 19:58
-
Much better way than via `commit`, keeps all input files intact (commit "wants" to change top layer at least), also can add `-c` to compress and get smaller size. – Martian2020 Dec 06 '22 at 13:17
-
`commit` answer is when one wants to flatten only part of backing chain. I don't see this answer can do that. – Martian2020 Dec 06 '22 at 13:23
-
@Martian2020 what does it mean "to flatten only part of backing chain"? Do you think it is relevant to original poster's question? – Tigran Ghahramanyan Dec 08 '22 at 07:09
-
well, generally speaking, it could be, image could be not directly based, but via long chain of backing images. Why do you ask? – Martian2020 Dec 08 '22 at 07:55
-
ok, now I get your point. thanks. – Tigran Ghahramanyan Dec 08 '22 at 15:42