-
-
Save ejemba/6f49c3a4c85b0fc20ca8871c4ff1a03e to your computer and use it in GitHub Desktop.
Using lvm thin provisioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment