Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming qcows2 snapshot plus backing file into standalone image file

Tags:

qemu

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?

like image 525
user2512377 Avatar asked Apr 07 '14 13:04

user2512377


People also ask

What is a QEMU backing file?

In essence, QCOW2(Qemu Copy-On-Write) gives you an ability to create a base-image, and create several 'disposable' copy-on-write overlay disk images on top of the base image(also called backing file).

What is a QCOW file?

qcow is a file format for disk image files used by QEMU, a hosted virtual machine monitor. It stands for “QEMU Copy On Write” and uses a disk storage optimization strategy that delays the allocation of storage until it is needed.


2 Answers

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.

like image 69
user2512377 Avatar answered Sep 30 '22 16:09

user2512377


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.

like image 34
Tigran Ghahramanyan Avatar answered Sep 30 '22 14:09

Tigran Ghahramanyan