Skip to content

Libvirt and qcow2 snapshots

wordpress meta

title: 'Libvirt and QCow2 Snapshots'
date: '2015-02-04T09:33:36-06:00'
status: publish
permalink: /libvirt-and-qcow2-snapshots
author: admin
excerpt: ''
type: post
id: 833
category:
    - KVM
    - Virtualization
tag: []
post_format: []

This article is for one specific use case I had. There is a lot more written around snapshots, qemu and libvirt. For my use case a qcow2 formatted image and KVM virtual machine. I wanted a way to capture machine state before an OS upgrade. So that I can roll back or revert in case something goes wrong. So for my case I do not care about live snapshots. I can shut the machine down before taking a consistent snapshot of the image.

Specifically I am using what is called an internal qcow2 snapshot.

https://libvirt.org/formatsnapshot.html

# virsh snapshot-create-as debian1 pre-update
Domain snapshot pre-update created
# virsh snapshot-list debian1
 Name                 Creation Time             State
------------------------------------------------------------
 pre-update           2015-02-04 09:22:18 -0600 shutoff

# virsh snapshot-current debian1
<domainsnapshot>
  <name>pre-update</name>
  <state>shutoff</state>
  <creationTime>1423063338</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='vda' snapshot='internal'/>
    <disk name='hda' snapshot='no'/>
  </disks>
[..]

Start VM and make some changes...and...Shutdown

# virsh snapshot-revert debian1 pre-update

Now start VM and changes should be gone.

** Note when I created the snapshots using virsh they did not show up in virt-manager. Probably needs a refresh in virt-manager. Appears like a bug. When I create a new snapshot in virt-manager I can see both(virsh created and virt-manager created). Or cwhen I ompletely quit virt-manager and re-open I see all.

Deletion of an old snapshot:

# virsh snapshot-delete debian1 pre-update
Domain snapshot pre-update deleted