Which is better image format, raw or qcow2, to use as a baseimage for other VMs?

Solution 1:

For your specific use case (base image + qcow2 overlay), the RAW format should be preferred:

  1. It's faster: as it has no metadata associated, it is as fast as possible. On the other hand, Qcow2 has two layer of indirection that must be crossed before to hit the actual data
  2. As the overlay layer must be a Qcow2 file, you don't lose the ever-useful snapshot capability (RAW images don't support snapshots by themselves)

The choice between base image + qcow2 overlay vs multiple full copies depends on your priority:

  1. For absolute performance, use fallocated RAW images. This has the downside of not supporting snapshot, with in most environments is a too high price to pay
  2. For flexibility and space-efficiency use RAW base images + Qcow2 overlays.

Anyway, I found Qcow2 files somewhat fragile.

For my production KVM hypervisors I basically use two different setups:

  1. where performance is #1 I use LVM volumes directly attached to the virtual machines, and I use LVM snapshot capability to take consistent backups
  2. where I can sacrifice some performance for enhanced flexibility, I use a single, big LVM Thin Provisioned Volume + XFS + RAW images

Another possibility is to use a normal LVM volume + XFS + RAW images. The only downside is that normal (non-thin) LVM snapshots are very slow and snapshotting a busy normal LVM volume will kill performance (for the lifetime of the snapshot). Anyway, if you plan to use only a sporadic use of snapshots, this can be the simpler and safer bet.

Some references:
KVM I/O slowness on RHEL 6
KVM storage performance and Qcow2 prellocation on RHEL 6.1 and Fedora 16
KVM storage performance and cache settings on Red Hat Enterprise Linux 6.2
LVM thin volume explained

Solution 2:

Please be advised....if you are using linux you can use raw and get the same benifits of qcow2 as far as size goes.

...If your file system supports holes (for example in ext2 or ext3 on Linux or NTFS on Windows), then only the written sectors will reserve space.

https://docs.fedoraproject.org/en-US/Fedora/18/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Using_qemu_img.html

raw Raw disk image format (default). This can be the fastest file-based format. If your file system supports holes (for example in ext2 or ext3 on Linux or NTFS on Windows), then only the written sectors will reserve space. Use qemu-img info to obtain the real size used by the image or ls -ls on Unix/Linux.