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 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.
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.