[CentOS-virt] LVM-snapshot based KVM VMs

Thu Apr 26 07:38:02 UTC 2012
Alain Péan <alain.pean at lpp.polytechnique.fr>

Le 25/04/2012 23:21, Paul Basov a écrit :
>
> Good m/d/n guys, wanted to put idea through you before trying to 
> implement this.
>
> So afaik 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?
>
> And 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?
>

Hi Paul,

Indeed, your feeling is wrong. LVM snapshots do take some space. You 
need to reserve some space on your LVM volume group to store the 
snpashots (about 5 GB could be a good estimate, it depends on the size 
of the snapshot). It appears as Free extent when you display 
informations about your volume group. For exemple (in this case it  a 
Proxmox virtualization server) :

# vgdisplay
....
   --- Volume group ---
   VG Name               pve
   System ID
   Format                lvm2
   Metadata Areas        1
   Metadata Sequence No  8512
   VG Access             read/write
   VG Status             resizable
   MAX LV                0
   Cur LV                3
   Open LV               3
   Max PV                0
   Cur PV                1
   Act PV                1
   VG Size               1,36 TiB
   PE Size               4,00 MiB
   Total PE              357182
   Alloc PE / Size       356160 / 1,36 TiB
   Free  PE / Size       1022 / 3,99 GiB
   VG UUID               UcKh7L-rSyq-NYd5-Q12V-EP8I-7QbE-RD5z4M

Without Free PE (Free space), you will not be able to create a snapshot. 
What the snapshot do is to create a temporary logical volume in this 
free space to store the snapshot (at least the differences with the 
actual VM volume). Snapshots are mainly used to backup a live VM, 
without stopping it. When it is done, you remove the snapshot, hence the 
temporary logical volume.

See for example :
http://tldp.org/HOWTO/LVM-HOWTO/snapshotintro.html

Alain


-- 
=============================================================
Alain Péan - LPP/CNRS
Attention !! :  Nouveau numéro de Telephone : 01-44-27-92-39
Administrateur Système/Réseau
Laboratoire de Physique des Plasmas - UMR 7648
Observatoire de Saint-Maur
4, av de Neptune, Bat. A
94100 Saint-Maur des Fossés
=============================================================