DEV Community

Usama Tanoli
Usama Tanoli

Posted on

πŸͺ£ Thin Provisioning in LVM – Complete Step by Step Tutorial

πŸͺ£ Buckets of Water Example
Imagine you have 3 friends. Each one asks you for a 1-liter bucket of water.
But you only have 2 liters of water.

Instead of saying β€œno,” you give each friend an empty bucket and say:
πŸ‘‰ β€œDon’t worry, I’ll fill it only when you actually need it.”

This is thin provisioning.
You promise more than you physically have, but only allocate space when needed.

πŸ’Ύ In Storage Terms
Normal provisioning (thick):
If you create a 1 GB volume, the system immediately reserves 1 GB β€” even if you only store 10 MB. Wasteful.

Thin provisioning:
If you create a 1 GB thin volume, the system only uses space when you actually write data. If you write 10 MB, it consumes just 10 MB from the pool. Efficient.βš–οΈ Thin Provisioning vs. Thick Provisioning

Thick provisioning (traditional): Space is fully reserved upfront, whether you use it or not.

Thin provisioning: Space is allocated on demand, saving storage until it’s actually required.

πŸš€ Step by Step Implementation
We’ll start with a 10 GB disk (/dev/sda), create a 5 GB partition (/dev/sda1), build a thin pool (3 GB), then test how space is consumed.

1️⃣ Add New Disk
We attach a 10 GB disk (/dev/sda).

`

`
lsblk

`
`
Output:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 10G 0 disk

2️⃣ Create a Partition
Make a 5 GB partition and set type to Linux LVM (8e).

fdisk /dev/sda

Inside fdisk:

n β†’ new
p β†’ primary
+5G β†’ size
t β†’ change type β†’ 8e
w β†’ write

Sync partition table:

partprobe /dev/sda

Check:

lsblk

Output:

sda 10G
└─sda1 5G

3️⃣ Create PV and VG
Turn partition into a physical volume (PV):

pvcreate /dev/sda1

Create a volume group (VG):

vgcreate thin_vg /dev/sda1

Check:

vgs

Output:

VG #PV #LV #SN Attr VSize VFree
thin_vg 1 0 0 wz--n- 5.00g 5.00g

4️⃣ Create Thin Pool
We’ll make a 3 GB thin pool.

lvcreate -L 3G --thinpool tp_usama_pool thin_vg

Check:

lvs

Output:

LV VG Attr LSize Pool Origin Data% Meta%
tp_usama_pool thin_vg twi-a-tz-- 3.00g 0.00 11.13

5️⃣ Create Thin LVs
Let’s create 3 LVs of 1 GB each.

lvcreate -V 1G --thin -n thin_vol1 thin_vg/tp_usama_pool
lvcreate -V 1G --thin -n thin_vol2 thin_vg/tp_usama_pool
lvcreate -V 1G --thin -n thin_vol3 thin_vg/tp_usama_pool

6️⃣ Format and Mount
Format:

mkfs.ext4 /dev/thin_vg/thin_vol1
mkfs.ext4 /dev/thin_vg/thin_vol2
mkfs.ext4 /dev/thin_vg/thin_vol3

Create mount points:

mkdir -p /mnt/vol1 /mnt/vol2 /mnt/vol3

Mount:

for i in 1 2 3; do
mount /dev/thin_vg/thin_vol$i /mnt/vol$i
done

Check:

df -hT

Output:

/dev/mapper/thin_vg-thin_vol1 ext4 974M 24K 907M 1% /mnt/vol1
/dev/mapper/thin_vg-thin_vol2 ext4 974M 24K 907M 1% /mnt/vol2
/dev/mapper/thin_vg-thin_vol3 ext4 974M 24K 907M 1% /mnt/vol3

7️⃣ Test by Writing Data
Let’s write 500 MB to each LV.

for d in /mnt/vol1 /mnt/vol2 /mnt/vol3; do
dd if=/dev/zero of=$d/testfile.txt bs=1M count=500 status=progress
done

Now check usage:

lvs

Output (Data% increased):

thin_vol1 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61
thin_vol2 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61
thin_vol3 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61
tp_usama_pool thin_vg twi-aotz-- 3.00g 53.61 23.44

8️⃣ Create Another LV – Warning
Now try adding another 1 GB LV:

lvcreate -V 1G --thin -n thin_vol4 thin_vg/tp_usama_pool

Warning:

Sum of all thin volume sizes (4.00 GiB) exceeds the size of thin pool (3.00 GiB)

This is expected – thin provisioning allows it, but be careful.

9️⃣ Try to Extend Thin Pool (Fails)
Check free VG space:

vgs

Output:

thin_vg 1 5 0 wz--n- 5.00g 1.98g

Now try extending by 2G:

lvextend -L +2G /dev/thin_vg/tp_usama_pool

Error:

Insufficient free space

πŸ”Ÿ Add Another Partition and Extend
Let’s add another 5 GB partition (/dev/sda2).

fdisk /dev/sda

n β†’ new β†’ p β†’ 2 β†’ +5G β†’ w

partprobe /dev/sda

Create PV:

pvcreate /dev/sda2

Extend VG:

vgextend thin_vg /dev/sda2

Check:

vgs

Output:

thin_vg 2 5 0 wz--n- 9.99g 6.98g

Now extend thin pool:

lvextend -L +2G /dev/thin_vg/tp_usama_pool

Output:

Size changed from 3.00 GiB β†’ 5.00 GiB

πŸ” Monitoring
Check thin pool and LV usage:

lvs

Output

lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

thin_vol1 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61

thin_vol2 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61

thin_vol3 thin_vg Vwi-aotz-- 1.00g tp_usama_pool 53.61

thin_vol4 thin_vg Vwi-a-tz-- 1.00g tp_usama_pool 0.00

tp_usama_pool thin_vg twi-aotz-- 5.00g 32.17 16.85

Detailed:

lvdisplay thin_vg/tp_usama_pool

lvdisplay thin_vg/tp_usama_pool
--- Logical volume ---
LV Name tp_usama_pool
VG Name thin_vg
LV UUID nURAHU-0hld-xjOF-97cR-1srt-JdRH-YRcCsE
LV Write Access read/write (activated read only)
LV Creation host, time localhost.localdomain, 2025-09-22 22:07:39 +0500
LV Pool metadata tp_usama_pool_tmeta
LV Pool data tp_usama_pool_tdata
LV Status available
# open 0
LV Size 5.00 GiB
Allocated pool data 32.17%
Allocated metadata 16.85%
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 253:

🎯 Conclusion
Thin provisioning lets you over-commit space safely.

Only used data consumes real storage.

If the pool gets full, writes fail β†’ monitor regularly.

You can always add new disks / partitions and extend the pool.

Top comments (0)