How to Inspect, Convert, and Manage KVM VM Snapshots with qemu-img and virsh
This guide shows how to check a KVM virtual machine's disk format, convert raw images to qcow2, create and list snapshots, revert to a specific snapshot, and delete snapshots using qemu-img and virsh commands on a Linux host.
First, verify the image format of the virtual machine by running
qemu-img info /var/lib/libvirt/images/ehs-rac-01.qcow2, which shows the file format (qcow2), virtual size, and existing snapshots.
KVM uses raw format by default for best performance, but features such as compression and encryption require the qcow2 format; if the image is already qcow2, no conversion is needed.
To convert a raw image to qcow2, use:
qemu-img convert -f raw -O qcow2 ehs-rac-01.img ehs-rac-01.qcow2Create a snapshot for the VM: virsh snapshot-create ehs-rac-01 You can also assign an alias:
virsh snapshot-create -as ehs-rac-01 ehs-rac-01-bakList existing snapshots: virsh snapshot-list ehs-rac-01 Snapshot configuration files are stored under /var/lib/libvirt/qemu/snapshot/ehs-rac-01/.
Before reverting, shut down the VM: virsh destroy ehs-rac-01 Revert to a specific snapshot by name:
virsh snapshot-revert ehs-rac-01 ehs-rac-01-bak02Or revert by timestamp: virsh snapshot-revert ehs-rac-01 1500373324 Delete a snapshot: virsh snapshot-delete ehs-rac-01 ehs-rac-01-bak After deletion, verify the remaining snapshots with virsh snapshot-list ehs-rac-01.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
