Operations 7 min read

Master KVM Disk Images: Inspect, Convert, and Snapshot Management with qemu-img & virsh

This guide explains how to inspect a KVM virtual machine's disk format, convert raw images to qcow2, and perform snapshot creation, listing, restoration, and deletion using qemu-img and virsh commands on a Linux host.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master KVM Disk Images: Inspect, Convert, and Snapshot Management with qemu-img & virsh

Inspecting Disk Format

Use qemu-img info to view the image details of a KVM virtual machine, revealing the file format (e.g., qcow2 ), virtual size, actual disk size, and snapshot list.

[root@ehs-as-04 images]# qemu-img info ehs-rac-01.qcow2
image: ehs-rac-01.qcow2
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 34G
cluster_size: 65536
Snapshot list:
ID  TAG               VM SIZE   DATE               VM CLOCK
1   ehs-rac-01-bak    1.6G 2019-09-09 16:00:13 00:16:16.672
2   ehs-rac-01-bak02  1.9G 2019-09-09 16:04:40 00:20:27.294
Format specific information:
  compat: 1.1
  lazy refcounts: true

Why Use qcow2 Instead of raw

KVM defaults to the raw image format, which offers the best performance but lacks advanced features such as image compression (zlib), AES encryption, and snapshot support. To leverage these capabilities, the disk must be in qcow2 format; if the image is already qcow2, no conversion is needed.

Converting Disk Format

When conversion is required, run:

# qemu-img convert -f raw -O qcow2 ehs-rac-01.img ehs-rac-01.qcow2

Replace -f with the source format and -O with the target format.

Snapshot Management

Create a snapshot : # virsh snapshot-create ehs-rac-01 Or create with an explicit name:

# virsh snapshot-create-as ehs-rac-01 ehs-rac-01-bak

List snapshots : # virsh snapshot-list ehs-rac-01 Output shows snapshot names, creation times, and states.

Snapshot XML files are stored under /var/lib/libvirt/qemu/snapshot/ehs-rac-01/.

Restoring a Snapshot

First ensure the VM is powered off: # virsh destroy ehs-rac-01 Then revert to the desired snapshot (by name or timestamp):

# virsh snapshot-revert ehs-rac-01 ehs-rac-01-bak02

For time‑based restoration, replace the snapshot name with its Unix timestamp.

Deleting a Snapshot

Identify the snapshot to delete, then run:

# virsh snapshot-delete ehs-rac-01 ehs-rac-01-bak

Verify removal with virsh snapshot-list, which should no longer display the deleted entry.

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.

LinuxsnapshotKVMqemu-imgvirshdisk format
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.