KVM storage and image formats¶
Part of the KVM overview. qcow2 versus raw, creating and inspecting images, and storage pools.
qcow2 vs raw¶
| qcow2 | raw | |
|---|---|---|
| Performance | Good (much improved in qcow2 v3) | Best |
| Snapshots | Built in | No |
| Copy-on-write / backing files | Yes | No |
| Space use | Sparse; grows on demand | Sparse if the filesystem supports it |
| Compression | Optional | No |
qcow2 is the sensible default; use raw when you need the last bit of I/O performance.
Create images¶
qemu-img create -f qcow2 /var/lib/libvirt/images/disk1.qcow2 10G # sparse
qemu-img create -f qcow2 -o preallocation=metadata /var/lib/libvirt/images/disk1.qcow2 10G # metadata preallocated
qemu-img create -f raw /var/lib/libvirt/images/disk1.raw 10G
Inspect and check¶
qemu-img info --backing-chain disk1.qcow2
qemu-img check disk1.qcow2
If qemu-img info reports raw for a file you expected to be qcow2, it was probably created as raw with the wrong extension (strings disk1.img | head shows filesystem signatures such as XFSB for raw XFS data).
Storage pools¶
virsh pool-list --all
virsh pool-define-as default_pool dir --target /var/lib/libvirt/images
virsh pool-build default_pool
virsh pool-start default_pool
virsh pool-autostart default_pool
virsh pool-info default_pool
For a dedicated disk, partition and format it, mount it (add it to /etc/fstab), then define a directory pool on the mount point.