Operations 6 min read

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.

Raymond Ops
Raymond Ops
Raymond Ops
How to Inspect, Convert, and Manage KVM VM Snapshots with qemu-img and virsh

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.qcow2

Create 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-bak

List 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-bak02

Or 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxsnapshotKVMqcow2qemu-imgvirsh
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.