Site Tools


wiki:qemu-disk-images

Table of Contents

QEMU Disk Images

qemu-img creates and manages virtual disk images for system-mode QEMU. The qcow2 (QEMU Copy-On-Write) format is standard—it's sparse, supports snapshots, and allows multiple VMs to share a base image without duplicating storage.

qemu-img create -f qcow2 disk.qcow2 20G        # create 20GB image
qemu-img create -b base.qcow2 -f qcow2 vm.img  # create from snapshot
qemu-system-x86_64 -hda disk.qcow2 -m 4G      # boot with -hda flag

-f qcow2 specifies the format. Other formats: raw (plain file, no features, fastest), qed (older), vmdk (VMware).

Snapshots are powerful for testing. Create a base image, install an OS, then create snapshots from it:

qemu-img create -f qcow2 base.qcow2 20G
qemu-system-x86_64 -hda base.qcow2              # install OS, then:
qemu-img create -b base.qcow2 -f qcow2 test.img # snapshot for testing
qemu-system-x86_64 -hda test.img                # changes go to test.img, base stays clean

If test.img gets corrupted, delete it and create a fresh snapshot from base.qcow2. The base image stays untouched.

Check image info:

qemu-img info disk.qcow2
qemu-img check disk.qcow2    # verify integrity

raw images are faster (no copy-on-write overhead) but waste space if sparse. qcow2 is slower but compact and feature-rich. For disk-heavy workloads, -f raw might be worth it; for snapshot workflows, qcow2 is essential.

Resize an image:

qemu-img resize disk.qcow2 +10G    # grow by 10GB
qemu-img resize disk.qcow2 30G     # shrink/expand to 30GB (risky, back up first)

Within the VM, resize the filesystem to match the new disk size (typically resize2fs for ext4).

wiki/qemu-disk-images.md · Last modified: (external edit)