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

<code>qemu-img info /var/lib/libvirt/images/ehs-rac-01.qcow2</code>

, 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:

<code>qemu-img convert -f raw -O qcow2 ehs-rac-01.img ehs-rac-01.qcow2</code>

Create a snapshot for the VM:

<code>virsh snapshot-create ehs-rac-01</code>

You can also assign an alias:

<code>virsh snapshot-create -as ehs-rac-01 ehs-rac-01-bak</code>

List existing snapshots:

<code>virsh snapshot-list ehs-rac-01</code>

Snapshot configuration files are stored under

/var/lib/libvirt/qemu/snapshot/ehs-rac-01/

.

Before reverting, shut down the VM:

<code>virsh destroy ehs-rac-01</code>

Revert to a specific snapshot by name:

<code>virsh snapshot-revert ehs-rac-01 ehs-rac-01-bak02</code>

Or revert by timestamp:

<code>virsh snapshot-revert ehs-rac-01 1500373324</code>

Delete a snapshot:

<code>virsh snapshot-delete ehs-rac-01 ehs-rac-01-bak</code>

After deletion, verify the remaining snapshots with

virsh snapshot-list ehs-rac-01

.

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

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