.QCOW2
QEMU copy-on-write disk image, version 2
Introduction
QCOW2 is the disk image format of QEMU, and the usual format for virtual machines on Linux with KVM. The file only grows as the guest writes to the disk, so a large virtual disk starts out small.
QCOW2 supports snapshots, compression and encryption, and backing files: a new image
can record only the changes made on top of a base image, so many virtual machines can
share one base. Version 3 of the format, still saved with the .qcow2
extension, adds further features through a feature table in the header.
Software
- QEMU and qemu-img (Windows, macOS, Linux)
- Virtual Machine Manager, using libvirt (Linux)
- Proxmox Virtual Environment (Linux)
Structure
The file starts with a big-endian header beginning with the magic bytes
QFI followed by 0xFB, then the version number. The header gives
the size of the virtual disk, the cluster size, the path of any backing file, and the
positions of the tables that follow. The file is divided into clusters, 64 KB by
default.
A two-level table maps the virtual disk onto the file. The L1 table points to L2 tables, and each L2 entry points to the cluster that holds that part of the disk, or marks it as unallocated, zero or compressed. A separate refcount table counts how many times each cluster is used, which lets snapshots share clusters until one of them is written to.
0Header magicQFI\xFB, version, disk size, cluster size, table offsets72 bytes or more…Refcount table and refcount blocksclusters…L1 table pointers to the L2 tablesclusters…L2 tables pointers to data clustersclusters…Data clusters the written parts of the diskrepeated