[libvirt-users] libvirt support for qcow2 rebase?

Kashyap Chamarthy kchamart at redhat.com
Wed Apr 17 17:42:49 UTC 2013


On 04/17/2013 07:05 PM, Skardal, Harald wrote:
> I have not found support in libvirt (nor virsh) for doing the equivalent of “qemu-img
> rebase ….”.
> 
>  
> 
> The use case:
> 
> You have copied a qcow2 stack and the new files have different names or reside in a
> different directory. Therefore you need to change the backing file.

>  
> 
> Is there a way  to do this? 

Um, I don't see it yet in libvirt.

But I recently did a small test for which does a diff of images using qemu-img rebase
(this was originally discussed documented by Rich Jones in qemu-img man page):

Posting the info here for convenience:

#----------------------------------------------------------------#
Use-case for 'diff' of images: Useful for converting a monolithic image back into a thin
image on top of a common base. (useful when you have copied or cloned a guest, and you
want to get back to a thin image on top of a template or base image)

NOTE: (1) the base-image is base-f17.img ; .

#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img info ../base-f17.qcow2
image: ../base-f17.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 5.0G
cluster_size: 65536
[root at localhost difftest]#
#----------------------------------------------------------------#
[root at localhost difftest]# rsync -avh --progress ../base-f17.qcow2 modified-f17.qcow2
[root at localhost difftest]# ls
modified-f17.qcow2
#----------------------------------------------------------------#

The modified-f17.qcow2 has 3 extra textfiles, and a directory /export  (that's the
'difference' between base-f17.img)
#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img info modified-f17.qcow2
image: modified-f17.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 5.0G
cluster_size: 65536
#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img create -f qcow2 -b modified-f17.qcow2 diff.qcow2
Formatting 'diff.qcow2', fmt=qcow2 size=5368709120 backing_file='modified-f17.qcow2'
encryption=off cluster_size=65536 lazy_refcounts=off
#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img info diff.qcow2
image: diff.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 196K
cluster_size: 65536
backing file: modified-f17.qcow2
[root at localhost difftest]#
#----------------------------------------------------------------#

Now, let's do the 'rebase' operation. (this is an expensive operation)
- At the end of operation, the diff.qcow2 will have its backing file changed to
'base-f17.qcow2'
- Note that: (In 'Safe mode', which is the default -- any clusters that differ between
backing_file and the old backing file of filename are merged into filename before actually
changing the backing file. )
#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img rebase -b ../base-f17.qcow2 diff.qcow2
#----------------------------------------------------------------#
[root at localhost difftest]# qemu-img info diff.qcow2
image: diff.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 1.4M
cluster_size: 65536
backing file: ../base-f17.qcow2
[root at localhost difftest]#
#----------------------------------------------------------------#

guestfish is able to boot into the diff, and also list the files added here (at this
point, we can discard 'modified.qcow2
#----------------------------------------------------------------#
[root at localhost difftest]# guestfish --rw -i -a diff.qcow2

Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help on commands
      'man' to read the manual
      'quit' to quit the shell

Operating system: Fedora release 17 (Beefy Miracle)
/dev/mapper/vg_none-lv_root mounted on /
/dev/sda1 mounted on /boot

><fs> ls /export
testfile1
testfile2
testfile3
><fs>
#----------------------------------------------------------------#

Now, the overlay is quite small, as it can be noticed here:
#----------------------------------------------------------------#
[root at localhost difftest]# ls -lash diff.qcow2
1.4M -rw-r--r--. 1 root root 1.5M Oct  4 05:58 diff.qcow2
[root at localhost difftest]#
#----------------------------------------------------------------#

Also, you can quickly boot into the diff.qcow2 to see what's up with it.
#----------------------------------------------------------------#
[root at localhost difftest]#  qemu-kvm -enable-kvm -m 1024 diff.qcow2  -nographic
#----------------------------------------------------------------#

Also posted here - http://kashyapc.fedorapeople.org/virt/img-diff-test.txt

Hope that somewhat answers your question.

>Is this a planned addition to libvirt?

> 
>  
> 
>    Harald
> 
> 
> 
> _______________________________________________
> libvirt-users mailing list
> libvirt-users at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-users
> 


-- 
/kashyap




More information about the libvirt-users mailing list