2

I would like to fully understand how virtual machine snapshots work. Although I have researched this subject I cannot seem to find a "high-level" overview of how snapshots work practically. My questions are:

Example scenario: I have an Ubuntu 12.04 host running KVM with an Ubuntu guest. The virtual machine is in the RAW format. I snapshot it using virsh command,

  1. Is the resulting file (the snapshot) bootable? Or is simply change data that requires the base image to be usable ?
  2. How does one roll back to a prior state ?
  3. Does having a lengthy snapshot chain degrade performance of the virtual machine? If so, why ?
  4. How does one manage / prune snapshots?
1

1 Answer 1

7
  • The Snapshot is part of a chain of images and requires the availability of all snapshots.
  • You can boot off the snapshot, but you must have all the previous images intact as well
  • Having a snapshot chain does degrade performance. Highly loaded server VMs should not be running off of snapshots at all
  • To manage snapshots, you simply try to keep the chain as short/flat as possible. man qemu-img for technical details
  • When you take a snapshot, a new empty image gets created. When you read a block from the image, you actually hit a pointer to the previous snapshot in the chain (on so on down the chain until you hit a block of data). When you write to a snapshot, the pointer gets replaced with a real block of data, and the snapshot image gets larger by that block.

To gain better understanding, start here

4
  • This explanations helps greatly. A follow up question: when a snapshot is created are automatically running from said snapshot? Or are you running from the original image until you need to restore to a prior state? Also, can you elaborate just a little on how to "flatten" the chain - just high level - I can deal with the technical side once I understand the concept a little better.
    – sardean
    Feb 1, 2014 at 1:45
  • For info on flattening the chain see redhat.com/archives/libvirt-users/2013-February/msg00095.html ; like my other link I think this is for qcow2, but I imagine the implementation for raw is similar.
    – sciurus
    Feb 1, 2014 at 2:12
  • When you create a snapshot with virsh, the record for the disk image used in the domxml changes to point at the snapshot instead of the base image. If you do it manually, you have to repoint the VM yourself. Make sure you always do that, because if the base changes underneath the snapshot, you are going to see data corruption. If you need to roll back, simply delete the snapshot and repoint the VM to the previous image in the chain
    – dyasny
    Feb 1, 2014 at 4:55
  • oh yes, and if this wasn't clear enough, if you snapshot an image, the base image should never be accessed in r/w mode, as long as there are snapshots in place. Only the last snapshot in the chain, the "leaf" can be r/w
    – dyasny
    Feb 1, 2014 at 7:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .