4. lvmthin

最後更新: 2024-05-04

前言

為何叫 Thin LV

blocks in a thin LV are allocated as they are written.

所以有 virtual size > size 情況

"-V" > "-L"

Thin LV != Thin Pool LV

The "Thin pool LV" contains blocks of physical storage(-L)

Thin LV 用到的 block 記錄到 "Thin pool (LV)"上面.

Thin Pool = Thin Pool LV

Thin Pool LV 的組成

A thin pool LV is created  by combining 2 standard LVs:

  1. a large data LV that will hold blocks for thin LVs
  2. a metadata LV that will hold metadata
    ( tracks which data blocks belong to each thin LV)

ThinPoolLV = data LV + metadata LV

Help

man lvmthin

目錄

  • 一句建立 thin pool LV
  • RAID1 的 Thin Pool LV
  • Create Thin LV in Thin Pool
  • Snapshot
  • Removing a Thin Pool
  • fstrim & discards
  • Merge thin snapshots
  • Zeroing mode
  • thin_check

 


一句建立 thin pool LV

 

不用分別建立 data LV, metadata LV 再轉換為 thin pool LV

lvcreate --type thin-pool -L LargeSize -n ThinPoolLV VG

i.e.

lvcreate --type thin-pool -L 10g -n MyThinPoolLV MyNVME

lvs -a | grep MyThinPoolLV

  MyThinPoolLV             MyNVME twi-a-tz--  10.00g             0.00   10.61
  [MyThinPoolLV_tdata]     MyNVME Twi-ao----  10.00g
  [MyThinPoolLV_tmeta]     MyNVME ewi-ao----  12.00m

 


RAID1 的 Thin Pool LV

 

# Default: --type raid1

lvcreate -m 1 -n tp0 -L 100g MyNVME         # Thin pool LV 最終會用這個名稱, 所以不用 tp0data

lvcreate -m 1 -n tp0meta -L 1g MyNVME      # meta 一般 1G 都夠用

lvs -a | grep tp0*

  tp0                      MyNVME rwi-a-r--- 100.00g                                    100.00
  [tp0_rimage_0]           MyNVME Iwi-aor--- 100.00g
  [tp0_rimage_1]           MyNVME Iwi-aor--- 100.00g
  [tp0_rmeta_0]            MyNVME ewi-aor---   4.00m
  [tp0_rmeta_1]            MyNVME ewi-aor---   4.00m
  tp0meta                  MyNVME rwi-a-r---   1.00g                                    100.00
  [tp0meta_rimage_0]       MyNVME iwi-aor---   1.00g
  [tp0meta_rimage_1]       MyNVME iwi-aor---   1.00g
  [tp0meta_rmeta_0]        MyNVME ewi-aor---   4.00m
  [tp0meta_rmeta_1]        MyNVME ewi-aor---   4.00m

# tp0 rename 成 "_tdata", tp0meta rename 成 "_tmeta"

lvconvert --type thin-pool --poolmetadata MyNVME/tp0meta MyNVME/tp0

lvs -a | grep tp0*
  LV                       VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  tp0                      MyNVME twi-a-tz-- 100.00g             0.00   1.61
  [tp0_tdata]              MyNVME rwi-aor--- 100.00g                                    100.00
  [tp0_tdata_rimage_0]     MyNVME iwi-aor--- 100.00g
  [tp0_tdata_rimage_1]     MyNVME iwi-aor--- 100.00g
  [tp0_tdata_rmeta_0]      MyNVME ewi-aor---   4.00m
  [tp0_tdata_rmeta_1]      MyNVME ewi-aor---   4.00m
  [tp0_tmeta]              MyNVME ewi-aor---   1.00g                                    100.00
  [tp0_tmeta_rimage_0]     MyNVME iwi-aor---   1.00g
  [tp0_tmeta_rimage_1]     MyNVME iwi-aor---   1.00g
  [tp0_tmeta_rmeta_0]      MyNVME ewi-aor---   4.00m
  [tp0_tmeta_rmeta_1]      MyNVME ewi-aor---   4.00m

Notes

A thin data LV can be converted to a thin pool LV without specifying a thin pool metadata LV.

LVM automatically creates a metadata LV from the same VG.

 


Create Thin LV in Thin Pool

 

i.e.

lvcreate -n ollama -V 100g --thinpool tp0 MyNVME

 

  LV            VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ollama        MyNVME Vwi-a-tz-- 100.00g tp0         0.00

Notes

建立時出現 WARNING

  /usr/sbin/thin_check: execvp failed: No such file or directory
  WARNING: Check is skipped, please install recommended missing binary /usr/sbin/thin_check!
  ...

 apt-get install thin-provisioning-tools

thin_check

 


Snapshot

 

Do not specify -L, --size when creating a thin snapshot.
A size argument will cause an old COW snapshot to be created.

# --snapshot, -s

lvcreate -n SnapLV --snapshot VG/ThinLV

i.e.

lvcreate -n ollama -s MyNVME/u22

activation skip

Thin  snapshots  are  created with the persistent "activation skip" flag, indicated by the "k" attribute. 

Use -K with lvchange or vgchange to activate thin snapshots with the "k" attribute.

 


Removing a Thin Pool

 

 * Removing a thin pool LV removes both the data LV and metadata LV and returns the space to the VG.

i.e.

# 只是例子, 別 copy 使用

lvremove MyVG/MyThinPoolLV

 


fstrim & discards

 

Removing files in a file system on top of a thin LV does not generally add free space back to the thin pool.  
Manually running the fstrim command can return space back to the thin pool that had been used by removed files.  
fstrim uses discards and will not work if the thin pool LV has discards mode set to ignore.

fstrim -v /mnt/X

查看 discards 設定

lvs -o+discards VG/ThinPoolLV

i.e.

lvs -o+discards MyNVME/MyThinPoolLV

  LV           VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Discards
  MyThinPoolLV MyNVME twi-a-tz-- 10.00g             0.00   10.61                            passdown

passdown (default)

Process discards in the thin pool and pass the discards down the the underlying device.

 


Merge thin snapshots

 

lvconvert --merge VG/SnapLV

If a merge is initiated while the LVs are open,
the effect of the merge is delayed until the origin thin LV is next activated.

umount /mnt/X

umount /mnt/Xs

lvchange -an vg/thin1

lvchange -ay vg/thin1

 


Zeroing mode

 

When a thin pool provisions a new data block for a thin LV,
  the new block is first overwritten with zeros.

The zeroing mode is indicated by the "z" attribute displayed by lvs.

lvs | grep tp0

tp0           MyNVME twi-a-tz-- 100.00g             0.00   1.61

設定

# -Z|--zero y(default)|n

lvcreate --type thin-pool -Z n -L 10g -n MyThinPoolLV MyVG

lvconvert --type thin-pool -Z n --poolmetadata MyVG/MyThinMetaLV MyVG/MyThinDataLV

lvchange -Z n MyVG/MyThinPoolLV

 


thin_check

 

validates thin provisioning metadata on a device or file

 * The tool cannot be run on live metadata

i.e.

# Analyses thin provisioning metadata on logical volume /dev/vg/metadata:

thin_check /dev/vg/metadata

 

Creative Commons license icon Creative Commons license icon