3

As far as I know, LVM snapshots basically don't take any "real" space on hard drives.

I'm using KVM virtualization on my hosts and let's say I create an LVM volume for my Linux VM, then install it properly, shut it down and take LVM snapshot of it.

Basically i've just cloned it (LVM2 snapshots are r/w).

I feed it to KVM and that's it? Can I snapshot this volume N number times and get N number of VMs that take zero actual space on actual hard drive?

When cloned VMs start writing, they will be actually writing only diffs from "master" VM. This looks like an interesting idea to manage a lot of "template" VMs while saving huge amounts of disk space.

Or maybe I'm just inventing the bicycle. What do you think? Is this possible?

jscott
  • 24,484
  • 8
  • 79
  • 100
Paul Basov
  • 163
  • 7

2 Answers2

3

LVM snapshots currently suffer horrible performance when you try to create multiple snapshots of the same origin at once, and you must reserve space for each snapshot separately, so this is not a good idea. You would be much better off using qcow2 images instead of raw lvm volumes, as they do have good snapshot support, and you can set up a read only base image for multiple read/write images for different VMs to use as a shared starting point.

psusi
  • 3,347
  • 1
  • 17
  • 9
2

if you do no write to your vm disk, yes, the snapshot takes 0 amount of disk, but as soon as you start writing, lvm snapshot space will start to fill, and it is full, your snapshot will die. that is why lvcreate -s still requires you to allocate some disk space. if all your vms are going to be readonly actually you can just use a cd or dvd.

however, you do save the base image size, as each snapshot will only take the incremental amount of space. so if your vms are all mostly read with little write, you still gain. as to performance you just have to test to see if it would work for you.

johnshen64
  • 5,865
  • 24
  • 17
  • You will lose some performance because snapshots are Copy-on-Write. This means that whenever some data changes between the original volume and the snapshot, it is copied to the snapshot. That's why making the snapshot is so fast. The cost comes when the volumes start to differ from each other. – Martijn Heemels Apr 25 '12 at 21:44
  • sure. i have not done that with kvm, but quite often with vmware where the idea is the same. someone took a snapshot and forgot about it, and eventually the vm ground to a halt. i tried to merge the snapshots and it took days and eventually crashed. snapshots are only good for short-term usage really such as taking a backup, testing an update, etc., in my experience, unless as i said there is very little write. – johnshen64 Apr 25 '12 at 21:56