Linux – Detailed explanation of how virtual machine snapshots work

kvm-virtualizationlinuxsnapshotUbuntuvirsh

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?

Best Answer

  • 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

Related Topic