Skip to content

Creating LVM Thin Volumes⚓︎

Overview⚓︎

LVM Thin Volumes enable efficient disk space allocation by only using physical storage as data is written. This helps optimize disk utilization and allows for easier management of large numbers of snapshots and over-provisioning of storage.

See the LVM naming scheme to provide meaningful names for LVM Thin volumes in /dev/mapper/.

Process⚓︎

Bash
 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
# load the required kernel module
modprobe dm-thin-pool

# create the pv
pvcreate /dev/vda2

# create the vg, see naming scheme above
vgcreate boot_$(hostname -s | tr -d '-')_vg1 /dev/vda2

# create a 250G thin pool logical volume as a container for the thin extents
lvcreate -L 250G -T -n boot_$(hostname -s | tr -d '-')_vg1/boot_thin_lv1

# create the thin extents in the thin pool
lvcreate -V 300G -T boot_$(hostname -s | tr -d '-')_vg1/boot_thin_lv1 -n data_lv1
lvcreate -V 20G -T boot_$(hostname -s | tr -d '-')_vg1/boot_thin_lv1 -n var_lv1
lvcreate -V 25G -T boot_$(hostname -s | tr -d '-')_vg1/boot_thin_lv1 -n var_log_lv1

# create a contiguous swap extent
lvcreate -C y -L 8G boot_$(hostname -s | tr -d '-')_vg1 -n swap_lv1

# create the filesystem
mkfs.ext4 -L DATA /dev/boot_$(hostname -s | tr -d '-')_vg1/var_data_lv1
mkfs.ext4 -L VARLOG /dev/boot_$(hostname -s | tr -d '-')_vg1/var_log_lv1
mkfs.ext4 -L LOGAUDIT /dev/boot_$(hostname -s | tr -d '-')_vg1/var_log_audit_lv1
mkswap -L SWAP /dev/boot_$(hostname -s | tr -d '-')_vg1/swap_lv1

Monitoring Thin Volume Usage⚓︎

Bash Session
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# view usage
$ sudo lvs
  LV                VG                  Attr       LSize  Pool          Origin Data%  Meta%  Move Log Cpy%Sync Convert
  boot_thin_lv1     boot_attemptare_vg1 twi-aotz-- 25.00g                      91.06  37.92
  home_lv1          boot_attemptare_vg1 Vwi-aotz--  4.00g boot_thin_lv1        25.61
  nix_lv1           boot_attemptare_vg1 Vwi-aotz-- 14.00g boot_thin_lv1        99.26
  persist_lv1       boot_attemptare_vg1 Vwi-aotz--  8.00g boot_thin_lv1        20.81
  root_lv1          boot_attemptare_vg1 Vwi-aotz--  4.00g boot_thin_lv1        4.40
  swap_lv1          boot_attemptare_vg1 -wc-ao----  4.00g
  temp_lv1          boot_attemptare_vg1 Vwi-aotz--  5.00g boot_thin_lv1        88.61
  var_log_audit_lv1 boot_attemptare_vg1 Vwi-aotz--  1.00g boot_thin_lv1        4.95
  var_log_lv1       boot_attemptare_vg1 Vwi-aotz--  5.00g boot_thin_lv1        28.29
  var_lv1           boot_attemptare_vg1 Vwi-aotz--  2.00g boot_thin_lv1        5.45

References⚓︎