Rate This Document
Findability
Accuracy
Completeness
Readability

Merging Snapshots of External Drives to Release Storage Space for KVM+QEMU

Symptom

When the VM is running, snapshots fail to be merged. As a result, the storage space occupied by snapshots keeps increasing and cannot be released.

Key Process and Cause Analysis

  • The OS and software versions may have defects that cause snapshot merging failure.
  • Misoperations occur due to insufficient understanding of KVM, QEMU, and libvirt's snapshot management functions, thereby affecting the success rate of snapshot merging.

Conclusion and Solution

  1. You are advised to use the OS and software versions listed in Table 1.
    Table 1 OS and software requirements

    Item

    Version

    How to Obtain

    OS

    openEuler 22.03 LTS SP3

    https://www.openeuler.org/en/download/?version=openEuler%2024.03%20LTS

    qemu

    6.2.0-83

    Install it using a yum source.

    libvirt

    6.2.0-57

    Install it using a yum source.

  2. Create a snapshot when the VM is running.
    virsh snapshot-create-as --domain VM_NAME SNAPHOT_NAME SNAPHOT_DESC --disk-only --diskspec vda,snapshot=external --atomic
    • VM_NAME: VM name.
    • SNAPHOT_NAME: snapshot name.
    • SNAPHOT_DESC: snapshot description.
    • vda: specifies the VM drive that creates snapshots.
    • By default, external drive snapshots are stored in the same directory as the VM drive. After a snapshot is created, the VM drive device points to the created external drive snapshot. A maximum of 199 external drive snapshots can be created for each VM.
    • Query the VM drive information.
      virsh domblklist VM_NAME

  3. When the VM is running, merge snapshots (using blockcommit).
    virsh blockcommit --domain VM_NAME vda --base path_to_base_snapshot --top path_to_top_snapshot --wait --verbose
    • VM_NAME: VM name.
    • path_to_base_snapshot: absolute path of the basic file to be committed. The file cannot be the initial VM drive file.
    • path_to_top_snapshot: absolute path of the top file to be committed. The file cannot be the last external drive snapshot.
  4. Delete the merged snapshot files that are no longer needed. (Exercise caution when performing this operation.)

    Do not delete the initial VM drive file, the last external drive snapshot, and the basic external drive snapshot that is committed and merged.

    virsh snapshot-delete --domain VM_NAME SNAPHOT_NAME --metadata
    rm path_to_snapshot
    • VM_NAME: VM name.
    • SNAPHOT_NAME: snapshot name.
    • path_to_snapshot: absolute path of the snapshot file.