public
Last active

Using lvm thin provisioning

  • Download Gist
gistfile1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# Using lvm thin provisioning, per https://github.com/lxc/lxc/pull/67
 
# First we create a volume group to hold the thin pool
 
$ sudo vgcreate lxc /dev/sde3
 
# Then create a thin-pool named 'tp' within that volume group
 
$ sudo lvcreate -l 90%VG --type thin-pool --thinpool tp lxc
 
# Now, create a 8GB container with lvm as the backing store, allocated from the thin-pool above
 
$ sudo lxc-create -n precise-thin --fssize=8G -B lvm --thinpool tp -t ubuntu-cloud -- -r precise
 
# We can see below that this only allocated 0.64% of the thin-pool, or about 0.97GB here, and the same amount within the 'precise-thin' LV.
 
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
precise-thin lxc Vwi-a-tz- 7.81g tp 12.56
tp lxc twi-a-tz- 152.93g 0.64
 
# Finally, we clone the original container. It will default to snapshotting the original LV using the same thin-pool.
 
$ sudo lxc-clone -s precise-thin precise-copy
 
# The total amount of data allocated in the thin-pool is pretty much the same.
 
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
precise-copy lxc Vwi-a-tz- 7.81g tp precise-thin 12.59
precise-thin lxc Vwi-a-tz- 7.81g tp 12.56
tp lxc twi-a-tz- 152.93g 0.64
 
# Since I have a slightly old ubuntu-cloud image, let's run apt-get upgrade on one of the containers. The thin-pool usage is around 1.6GB now.
 
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
precise-copy lxc Vwi-aotz- 7.81g tp precise-thin 17.63
precise-thin lxc Vwi-a-tz- 7.81g tp 12.56
tp lxc twi-a-tz- 152.93g 1.09
 
# And if we do it again on the other container, we're now up to 2GB
 
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
precise-copy lxc Vwi-aotz- 7.81g tp precise-thin 17.63
precise-thin lxc Vwi-aotz- 7.81g tp 17.19
tp lxc twi-a-tz- 152.93g 1.33
 
# The best savings would be from keeping a fresh base image available for cloning, since in this case just the upgrade added ~400MB.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.