KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

Be more productive with Base Images (Part 3)

There’s a lesser known option that was added fairly recently to kvm-71 as an addition to the qemu-img command. It allows you to create a copy on write image while using the convert option. This option will probably not be as useful as basing images and rebasing images but it should at least be an option that you’re aware of. It’s a new b argument for creating copy on write images from base images while converting formats.

 

The syntax 

The syntax for the new argument when using the convert parameter with qemu-img is as follows:

qemu-img convert -O qcow2 -B master-windows2003-base.qcow2 master-windows2003.qcow2 final.qcow2  

Note the –B argument which tells qemu-img that the newly created image (final.qcow2) will be a copy on write image of the specified base image (master-windows2003-base.qcow2). What you’re basically saying is convert master-windows2003.qcow2 to final.qcow2 and let this converted image be a copy on write of the image specified by the –B argument. This essentially means that the master-windows2003.qcow2 and master-windows2003-base.qcow2 should have the same content but they may differ in location, format etc.
 

If you do a qemu-img info you’re your final.qcow2 image, it looks like the following.

qemu-img info final.qcow2

image: final.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.2G
cluster_size: 4096
backing file: master-windows2003-base.qcow2 (actual path: master-windows2003-base.qcow2)

Note that unlike copy on write images as described previously, these copy on write images are actually the same size as the backing file and actually take some time to convert.

 

Summary 

This concludes the short series on base images. In Part 1 and Part 2 of this series you’ve seen how to create images from base templates and rebasing your disk images. In this post, you’ve seen the new optional argument for the qemu-img command and how it might be used. You’ll probably not find yourself using this option very much but I think it’s always good to know your options. Personally, I can’t think of how I might use this option very much as it doesn’t really save much disk space or time and in that case I would probably opt for just a straight conversion. In any case now you know. 

See Also

Comments

A use case scenario for this option

I wanted to give you a use-case for this new option - to move the base image to a new location.  For example:

I have a read-only base image located at /vm/base/mybase.qcow2

And a differential image at /vm/server01/myserver.qcow2.

If I move my base and differential images to a new server, the base image must be found by the differential in the same location as when it was created (/vm/base/mybase.qcow2).

So on my new server, my images are as follows:
Base image at /home/user/base/mybase.qcow2
Differential at /home/user/server01/myserver.qcow2

I'll create a symlink to point /vm/base to /home/user/base temporarily

Then run the command in /vm/server01 :

qemu-img convert -f qcow2 -O qcow2 -B /home/user/base/mybase.qcow2 myserver.qcow2 NEWmyserver.qcow2

I can delete the old myserver image, and rename the new back to the old.

I am surprised that this functionality wasn't already there - at least, I hadn't found it until this option was added.

Re: Use case for convert option

That's a good use case Dave. Thinking about it, relocation must have been in mind when this option was created.

Rebasing multiple clones

This stuff has awesome potential. Thanks for breaking it down in plain language.

If my multiple clones all accumulate changes over time, to the point where they're not sharing any blocks from the master any more, how would you recommend I leverage rebasing at that point, to optimize for space?

Thanks,
Sheldon.

Chains of images

And is there a possibility to create a chain from base images? May be it would be slow, but convenient for experiments with configurations.

Re: chain of images

In theory I don't see why not but I"ve never tried that. Out of curiosity how many links in the chain are you thinking about? And what use case are you thinking about?

I'm looking for a way to

I'm looking for a way to reproduce somehow vmware snapshot system with kvm. It is very convenient for experiments with configuration of workstation images. I had a tree of images for different departments and possibility to return to the key point if i made a mistake somewhere. I hope that base images can reproduce this functionality.

Hi, This is exactly what

Hi,

This is exactly what VMWare snapshot feature is:
http://www.linux-kvm.com/content/how-you-can-use-qemukvm-base-images-be-...

You have your base VM image, then you create a snapshot file for all the changes you need. You can rebase the snapshot file to a new VM or discard it without touching the base VM image.

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.