FUN WITH LINUX

LVM: Thin provisioned volumes

11 March 2016

If we create logical volumes using LVM we have to define a fixed size for this volume and all the space for this volume will be allocated on disk at once. In a thin provisioned setup this is different. It will just allocate the space used and it will grow dynamically.

Concept

The setup for thin-provisioned volumes is slightly different than ordinary volumes. Normally we have a Volume Group and in this group we will create our Volumes. In a thin-provisioned setup we have our Volume Group and in this group we have to create a Thin-Pool in which we will create our Volumes.

Preparing

In the repositories of Debian(Jessie) and some other Distributions, the Thin-Provisioning-Tools are missing. That’s why we have to download and compile them for our own:

wget https://github.com/downloads/jthornber/thin-provisioning-tools/thin-provisioning-tools-v0.1.5.tar.bz2
tar xvfj thin-provisioning-tools-v0.1.5.tar.bz2
cd thin-provisioning-tools-v0.1.5
./configure
make
make install

Now we should have installed the programm “/usr/sbin/thin_check”(which is needed for thin-prov) correctly

Setup

First of all, we need to load  the dm-thin-pool kernel-module:

echo "dm-thin-pool" >> /etc/modules
modprobe dm-thin-pool

Now we can create a  new volume-group(2 Tera-Byte) for our thin-provisioned volumes:

vgcreate -s 2T vg0 /dev/sdc

..and then our thin-provisioning pool:

lvcreate -L 2T --thinpool pool vg0

Using this pool we can create our logical volumes:

lvcreate --thin vg0/pool --virtualsize 5G --name wwwdata

mkfs.ext4 /dev/vg0/wwwdata
mount /dev/vg0/wwwdata /var/www

Snapshots

A damn cool thing is thinly provisioned snapshots. They give us the ability to make recursive snapshots. You can read more about them here. If you have a setup like described above, you can create such snapshots just by executing the following command:

lvcreate --snapshot --name damn-cool-thin-snap /dev/vg0/wwwdata

Monitoring

If you think: “cool, it’s done”. You might be wrong. You definitely have to monitor the pool. It’s very important not to “Over Provisioning”!

To check the volumes you can use “lvs”:

root@tardis:~# lvs
  LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  pool vg0 twi-a-tz-- 1000.00g 7.51 11.42                           
  root vg0 -wi-ao---- 50.00g                                                     
  swap vg0 -wi-ao---- 4.00g                                                     
  tmp vg0 -wi-ao---- 6.00g                                                     
  var vg0 -wi-ao---- 50.00g                                                     
  wwwdata vg0 Vwi-aotz-- 800.00g pool 6.27                                   
  wwwdata-snapshot1 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1014 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1038 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1062 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1086 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1110 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1134 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1158 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1182 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1206 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1230 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1251 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1252 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1253 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1254 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1255 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1256 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1257 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1258 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1259 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1260 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1261 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1262 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1263 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1264 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot1265 vg0 Vri---tz-k 800.00g pool wwwdata                                        
  wwwdata-snapshot318 vg0 Vri---tz-k 800.00g pool wwwdata                                        

Final Words

Thin provisioning is a very cool thing to reduce disk-usage. Thin Snapshots allow us to create recursive snapshots. Even though, I would rather use BTRFS instead whenever it is possible.

[ Linux  Sysadmin  LVM  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti