summaryrefslogtreecommitdiff
path: root/man/lvmthin.8.in
blob: fafbd803b71856e77a4f51892ba8beda72f7d8c3 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
.TH "LVM-THIN" "8" "LVM TOOLS #VERSION#" "Red Hat, Inc" "\""

.SH NAME
lvm-thin - LVM thin provisioning

.SH DESCRIPTION

Blocks in a standard logical volume are allocated when the LV is created,
but blocks in a thin provisioned logical volume are allocated as they are
written.  Because of this, a thin provisioned LV is given a virtual size,
and can then be much larger than physically available storage.  The amount
of physical storage provided for thin provisioned LVs can be increased
later as the need arises.

Blocks in a standard LV are allocated (during creation) from the VG, but
blocks in a thin LV are allocated (during use) from a special "thin pool
LV".  The thin pool LV contains blocks of physical storage, and blocks in
thin LVs just reference blocks in the thin pool LV.

A thin pool LV must be created before thin LV's can be created within it.
A thin pool LV is created by combining two standard LV's: a large data LV
that will hold blocks for thin LVs, and a metadata LV that will hold
metadata.  The metadata tracks which data blocks belong to each thin LV.

Snapshots of thin LVs are efficient because the data blocks common to a
thin LV and its snapshot are shared.  Snapshots may be taken of thin LV's
or of other thin snapshots.  Blocks common to recursive snapshots are also
shared in the thin pool.  There is no limit to or degradation from
sequences of snapshots.

As thin LV's or snapshot LV's are written to, they consume data blocks in
the thin pool.  As free data blocks in the pool decrease, more free blocks
may need to be supplied.  This is done by extending the thin pool data LV
with additional physical space from the VG.  Removing thin LVs or
snapshots from the thin pool can also free blocks in the thin pool.
However, removing LVs is not always an effective way of freeing space in a
thin pool because the amount is limited to the number of blocks not shared
with other LVs in the pool.

Incremental block allocation from thin pools can cause thin LVs to become
fragmented.  Standard LVs generally avoid this problem by allocating all
the blocks at once during creation.


.SH Thin Terms

.TP
ThinDataLV
.br
thin data LV
.br
large LV created in a VG
.br
used by thin pool to store ThinLV blocks

.TP
ThinMetaLV
.br
thin metadata LV
.br
small LV created in a VG
.br
used by thin pool to track data block usage

.TP
ThinPoolLV
.br
thin pool LV
.br
combination of ThinDataLV and ThinMetaLV
.br
contains ThinLVs and SnapLVs

.TP
ThinLV
.br
thin LV
.br
created from ThinPoolLV
.br
appears blank after creation

.TP
SnapLV
.br
snapshot LV
.br
created from ThinPoolLV
.br
appears as a snapshot of another LV after creation



.SH Thin Usage

The primary method for using lvm thin provisioning:

.nf
1. create ThinDataLV

   Create an LV that will hold thin pool data.

   Command
   lvcreate -n ThinDataLV -L LargeSize VG

   Example
   # lvcreate -n poolA -L 100G vg

2. create ThinMetaLV

   Create an LV that will hold thin pool metadata.

   Command
   lvcreate -n ThinMetaLV -L SmallSize VG

   Example
   # lvcreate -n poolA_meta -L 1G vg

   # lvs
   poolA      vg          -wi-a-----  10.00g
   poolA_meta vg          -wi-a-----   1.00g

3. create ThinPoolLV

   Combine the data and metadata LVs into a thin pool LV.
   ThinDataLV is renamed to hidden ThinPoolLV_tdata.
   ThinMetaLV is renamed to hidden ThinPoolLV_tmeta.
   The new ThinPoolLV takes the previous name of ThinDataLV.

   Command
   lvconvert --thinpool VG/ThinDataLV --poolmetadata VG/ThinMetaLV

   Example
   # lvconvert --thinpool vg/poolA --poolmetadata vg/poolA_meta

   # lvs vg/poolA
   LV    VG  Attr       LSize  Pool Origin Data%
   poolA vg  twi-a-tz-- 10.00g               0.00

   # lvs -a
   poolA           vg          twi-a-tz--  10.00g
   [poolA_tdata]   vg          Twi-ao----  10.00g
   [poolA_tmeta]   vg          ewi-ao----   1.00g

4. create ThinLV

   Create a new thin LV from the thin pool LV.
   The thin LV is created with a virtual size.
   Multiple new thin LV's may be created in the thin pool.
   Thin LV names must be unique in the VG.
   The thinpool argument specifies which thin pool will
   contain the ThinLV.

   Command
   lvcreate --type thin -n ThinLV -V VirtualSize --thinpool VG/ThinPoolLV

   Example
   Create a thin LV in a thin pool:
   # lvcreate --type thin -n thinX -V 1T --thinpool vg/poolA

   Create another thin LV in the same thin pool:
   # lvcreate --type thin -n thinY -V 1T --thinpool vg/poolA

   # lvs vg/thinX vg/thinY
   LV    VG  Attr       LSize Pool  Origin Data%
   thinX vg  Vwi-a-tz-- 1.00t poolA          0.00
   thinY vg  Vwi-a-tz-- 1.00t poolA          0.00

5. create SnapLV

   Create snapshots of an existing ThinLV or SnapLV.

   Command
   lvcreate --type thin -n SnapLV -s ThinLV --thinpool VG/ThinPoolLV
   lvcreate --type thin -n SnapLV -s PrevSnapLV --thinpool VG/ThinPoolLV

   Example
   Create first snapshot of an existing ThinLV:
   # lvcreate --type thin -n snapX1 -s thinX --thinpool vg/poolA

   Create second snapshot of the same ThinLV:
   # lvcreate --type thin -n snapX2 -s thinX --thinpool vg/poolA

   Create a snapshot of the first snapshot:
   # lvcreate --type thin -n snapsnapX1 -s snapX1 --thinpool vg/poolA

   # lvs vg/snapX1 vg/snapX2 vg/snapsnapX1
   LV         VG  Attr       LSize Pool  Origin
   snapX1     vg  Vwi---tz-k 1.00t poolA thinX
   snapX2     vg  Vwi---tz-k 1.00t poolA thinX
   snapsnapX1 vg  Vwi---tz-k 1.00t poolA snapX1

6. activate SnapLV

   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.
   
   Command
   lvchange -ay -K VG/SnapLV
   
   Example
   # lvchange -ay -K vg/snapX1
   
   # lvs vg/snapX1
   snapX1 vg   Vwi-a-tz-k 1.00t poolA thinX
.fi
   

.SH Thin Topics

Specify devices for data and metadata LVs
.br
Tolerate device failures using raid
.br
Spare metadata LV
.br
Metadata check and repair
.br
Automatic pool metadata LV
.br
Activation of thin snapshots
.br
Removing thin pool LV's, thin LV's and snapshots
.br
Manually manage free data space of thin pool LV
.br
Manually manage free metadata space of a thin pool LV
.br
Using fstrim to increase free space in a thin pool LV
.br
Automatically extend thin pool LV
.br
Zeroing
.br
Discard
.br
Chunk size
.br
Size of pool metadata LV
.br
Create a thin snapshot of an external, read only LV
.br
Convert a standard LV to a thin LV with an external origin
.br
Single step thin pool LV creation
.br
Single step thin pool LV and thin LV creation
.br

\&

.SS Specify devices for data and metadata LVs

\&

The data and metadata LVs in a thin pool are best created on
separate physical devices.  To do that, specify the device name(s)
at the end of the lvcreate line.  It can be especially helpful
to use fast devices for the metadata LV.

.nf
lvcreate -n ThinDataLV -L LargeSize VG PV_Large
lvcreate -n ThinMetaLV -L SmallSize VG PV_Small
lvconvert --thinpool VG/ThinDataLV --poolmetadata VG/ThinMetaLV

Example
# lvcreate -n poolA -L 100G vg /dev/sdA
# lvcreate -n poolA_meta -L 1G vg /dev/sdB
# lvconvert --thinpool vg/poolA --poolmetadata vg/poolA_meta
.fi

See lvm.conf thin_pool_metadata_require_separate_pvs to set
default PV usage for thin pool creation.


.SS Tolerate device failures using raid

\&

To tolerate device failures, use raid for the pool data LV and
pool metadata LV.  This is especially recommended for pool metadata LVs.

.nf
lvcreate --type raid1 -m 1 -n ThinMetaLV -L SmallSize VG PVA PVB
lvcreate --type raid1 -m 1 -n ThinDataLV -L LargeSize VG PVC PVD
lvconvert --thinpool VG/ThinDataLV --poolmetadata VG/ThinMetaLV

Example
# lvcreate --type raid1 -m 1 -n poolA -L 100G vg /dev/sdA /dev/sdB
# lvcreate --type raid1 -m 1 -n poolA_meta -L 1G vg /dev/sdC /dev/sdD
# lvconvert --thinpool vg/poolA --poolmetadata vg/poolA_meta
.fi


.SS Spare metadata LV

\&

The first time a thin pool LV is created, lvm will create a spare
metadata LV in the VG.  This behavior can be controlled with the
option --poolmetadataspare y|n.  (Future thin pool creations will
also attempt to create the pmspare LV if none exists.)

To create the pmspare ("pool metadata spare") LV, lvm first creates
an LV with a default name, e.g. lvol0, and then converts this LV to
a hidden LV with the _pmspare suffix, e.g. lvol0_pmspare.

One pmspare LV is kept in a VG to be used for any thin pool.

The pmspare LV cannot be created explicitly, but may be removed
explicitly.

.nf
Example
# lvcreate -n poolA -L 10G vg
# lvcreate -n poolA_meta -L 10G vg
# lvconvert --thinpool vg/poolA --poolmetadata vg/poolA_meta

# lvs -a
[lvol0_pmspare] vg          ewi-------  10.00g
poolA           vg          twi---tz--  10.00g
[poolA_tdata]   vg          Twi-------  10.00g
[poolA_tmeta]   vg          ewi-------   1.00g
.fi

The "Metadata check and repair" section describes the use of
the pmspare LV.


.SS Metadata check and repair

\&

If thin pool metadata is damaged, it may be repairable.
Checking and repairing thin pool metadata is analagous to
running fsck on a file system.

When a thin pool LV is activated, lvm runs the thin_check command
to check the correctness of the metadata on the pool metadata LV.

To disable the thin_check step, set lvm.conf thin_check_executable to
an empty string ("").  This is not recommended.

To set options for the thin_check command, set lvm.conf thin_check_options.

If the thin_check command finds a problem with the metadata,
the thin pool LV is not activated, and the thin pool metadata should
be repaired.

Command to repair a thin pool LV:
.nf
lvconvert --repair VG/ThinPoolLV
.fi

Repair performs the following steps:

1. Creates a new, repaired copy of the metadata.
.br
lvconvert runs the thin_repair command to read damaged metadata
from the existing pool metadata LV, and writes a new repaired
copy to the VG's pmspare LV.

2. Replaces the thin pool metadata LV.
.br
If step 1 is successful, the thin pool metadata LV is replaced
with the pmspare LV containing the corrected metadata.
The previous thin pool metadata LV, containing the damaged metadata,
becomes visible with the new name ThinPoolLV_tmetaN (where N is 0,1,...).

If the repair works, the thin pool LV and its thin LVs can be activated,
and the LV containing the damaged thin pool metadata can be removed.
It may be useful to move the new metadata LV (previously pmspare) to a
better PV.

If the repair does not work, the thin pool LV and its thin LVs are lost.

If metadata is manually restored with thin_repair directly,
the pool metadata LV can be manually swapped with another LV
containing new metadata:

.nf
lvconvert --thinpool VG/ThinPoolLV --poolmetadata VG/NewThinMetaLV
.fi

The path to thin_check, thin_dump and thin_repair commands
can be set in lvm.conf.


.SS Automatic pool metadata LV

\&

A thin data LV can be converted to a thin pool LV without
specifying a thin pool metadata LV.  LVM will automatically
create a metadata LV from the same VG.

.nf
lvcreate -n ThinDataLV -L LargeSize VG
lvconvert --thinpool VG/ThinDataLV

Example
# lvcreate -n poolC -L 10G vg
# lvconvert --thinpool vg/poolC

# lvs -a
poolC           vg          twi-a-tz--  10.00g
[poolC_tdata]   vg          Twi-ao----  10.00g
[poolC_tmeta]   vg          ewi-ao----  16.00m
.fi


.SS Activation of thin snapshots

\&

When a thin snapshot LV is created, it is by default given the
"activation skip" flag.  This flag is indicated by the "k" attribute
displayed by lvs:

.nf
# lvs vg/snapX1
LV         VG  Attr       LSize Pool  Origin
snapX1     vg  Vwi---tz-k 1.00t poolA thinX
.fi

This flag causes the snapshot LV to be skipped, i.e. not activated,
by normal activation commands.  The skipping behavior does not
apply to deactivation commands.

A snapshot LV with the "k" attribute can be activated using
the -K (or --ignoreactivationskip) option in addition to the
standard -ay (or --activate y) option.

Command to activate a thin snapshot LV:
.nf
lvchange -ay -K VG/SnapLV
.fi

The persistent "activation skip" flag can be turned off during
lvcreate, or later with lvchange using the -kn
(or --setactivationskip n) option.
It can be turned on again with -ky (or --setactivationskip y).

When the "activation skip" flag is removed, normal activation
commands will activate the LV, and the -K activation option is
not needed.

Command to create snapshot LV without the activation skip flag:
.nf
lvcreate --type thin -n SnapLV -kn -s ThinLV --thinpool VG/ThinPoolLV
.fi

Command to remove the activation skip flag from a snapshot LV:
.nf
lvchange -kn VG/SnapLV
.fi

See lvm.conf auto_set_activation_skip to set default usage of
activation skip.


.SS Removing thin pool LV's, thin LV's and snapshots

\&

Removing a thin LV and its related snapshots returns the blocks it
used to the thin pool LV.  These blocks will be reused for other
thin LVs and snapshots.

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

lvremove of thin pool LV's, thin LV's and snapshots cannot be
reversed with vgcfgrestore.

vgcfgbackup does not back up thin pool metadata.


.SS Manually manage free data space of thin pool LV

\&

The available free space in a thin pool LV can be displayed
with the lvs command.  Free space can be added by extending
the thin pool LV. 

.nf
Example

1. A thin pool LV is using 26.96% of its data blocks.
# lvs
LV    VG           Attr       LSize   Pool  Origin Data%                                     
poolA vg           twi-a-tz--  10.00g               26.96                          

2. Double the amount of physical space in the thin pool LV.
# lvextend -L+10G vg/poolA

3. The percentage of used data blocks is half the previous value.
# lvs
LV    VG           Attr       LSize   Pool  Origin Data%                                          
poolA vg           twi-a-tz--  20.00g               13.48  
.fi

Other methods of increasing free data space in a thin pool LV
include removing a thin LV and its related snapsots, or running
fstrim on the file system using a thin LV.


.SS Manually manage free metadata space of a thin pool LV

\&

The available metadata space in a thin pool LV can be displayed
with the lvs -o+metadata_percent command.

Example

1. A thin pool LV is using 12.40% of its metadata blocks. 
.nf
# lvs -oname,size,data_percent,metadata_percent vg/poolA
LV    LSize   Data%  Meta% 
poolA  20.00g  13.48  12.40
.fi

2. Display a thin pool LV with its component thin data LV and thin metadata LV.
.nf
# lvs -a -oname,attr,size vg
LV              Attr       LSize
poolA           twi-a-tz--  20.00g
[poolA_tdata]   Twi-ao----  20.00g
[poolA_tmeta]   ewi-ao----  12.00m
.fi

3. Double the amount of physical space in the thin metadata LV.
.nf
# lvextend -L+12M vg/poolA_tmeta
.fi

4. The percentage of used metadata blocks is half the previous value.
.nf
# lvs -a -oname,size,data_percent,metadata_percent vg
LV              LSize   Data%  Meta%
poolA            20.00g  13.48   6.20
[poolA_tdata]    20.00g
[poolA_tmeta]    24.00m
.fi


.SS Using fstrim to increase free space in a thin pool LV

\&

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.

Example
 
A thin pool has 10G of physical data space, and a thin LV has a virtual
size of 100G.  Writing a 1G file to the file system reduces the
free space in the thin pool by 10% and increases the virtual usage
of the file system by 1%.  Removing the 1G file restores the virtual
1% to the file system, but does not restore the physical 10% to the
thin pool.  The fstrim command restores the physical space to the thin pool.

.nf
# lvs -a -oname,attr,size,pool_lv,origin,data_percent,metadata_percent vg
LV              Attr       LSize   Pool  Origin Data%  Meta%
poolA           twi-a-tz--  10.00g               47.01  21.03
thinX           Vwi-aotz-- 100.00g poolA          2.70       

# df -h /mnt/X
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg-thinX   99G  1.1G   93G   2% /mnt/X

# dd if=/dev/zero of=/mnt/X/1Gfile bs=4096 count=262144; sync

# lvs
poolA           vg   twi-a-tz--  10.00g               57.01  25.26                
thinX           vg   Vwi-aotz-- 100.00g poolA          3.70       

# df -h /mnt/X
/dev/mapper/vg-thinX   99G  2.1G   92G   3% /mnt/X

# rm /mnt/X/1Gfile

# lvs
poolA           vg   twi-a-tz--  10.00g               57.01  25.26                       
thinX           vg   Vwi-aotz-- 100.00g poolA          3.70       

# df -h /mnt/X
/dev/mapper/vg-thinX   99G  1.1G   93G   2% /mnt/X

# fstrim -v /mnt/X

# lvs
poolA           vg   twi-a-tz--  10.00g               47.01  21.03                     
thinX           vg   Vwi-aotz-- 100.00g poolA          2.70       
.fi


.SS Automatically extend thin pool LV

\&

An lvm daemon (dmeventd) will by default monitor the data usage of
thin pool LVs and extend them when the usage reaches a certain level.
The necessary free space must exist in the VG to extend the thin pool
LVs.

Command to enable or disable the monitoring and automatic extension
of an existing thin pool LV:

.nf
lvchange --monitor {y|n} VG/ThinPoolLV
.fi
 
The lvm.conf thin_pool_autoextend_threshold and thin_pool_autoextend_percent
options define the autoextend behavior.

thin_pool_autoextend_threshold is a percentage value that defines when
the thin pool LV should be extended.  Setting this to 100 disables
automatic extention.  The minimum value is 50.

thin_pool_autoextend_percent defines how much extra data space should
be added to the thin pool, in percent of its current size.

Warnings are emitted through syslog when the use of a pool reaches 80%,
85%, 90% and 95%.

Example

If thin_pool_autoextend_threshold is 70 and thin_pool_autoextend_percent is 20,
whenever a pool exceeds 70% usage, it will be extended by another 20%.
For a 1G pool, using 700M will trigger a resize to 1.2G. When the usage exceeds
840M, the pool will be extended to 1.44G, and so on.


.SS Zeroing

\&

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.  The option -Z
(or --zero) can be added to commands to specify the zeroing mode.

Command to set the zeroing mode when creating a thin pool LV:
.nf
lvconvert -Z{y|n} --thinpool VG/ThinDataLV --poolmetadata VG/ThinMetaLV
.fi

Command to change the zeroing mode of an existing thin pool LV:
.nf
lvchange -Z{y|n} VG/ThinPoolLV
.fi

If zeroing mode is changed from "n" to "y", previously provisioned
blocks are not zeroed.

Provisioning of large zeroed chunks impacts performance.

See lvm.conf thin_pool_zero to set default zeroing mode.


.SS Discard

\&

The discard behavior of a thin pool LV determines how discard requests
are handled.  Possible discard behaviors:

ignore: Ignore any discards that are received.

nopassdown: Process any discards in the thin pool itself and allow
the no longer needed extends to be overwritten by new data.

passdown: Process discards in the thin pool (as with nopassdown), and
pass the discards down the the underlying device.  This is the default
mode.

Command to display the current discard mode of a thin pool LV:
.nf
lvs -o+discards VG/ThinPoolLV
.fi
 
Command to set the discard mode when creating a thin pool LV:
.nf
lvconvert --discards {ignore|nopassdown|passdown}
    --thinpool VG/ThinDataLV --poolmetadata VG/ThinMetaLV
.fi

Command to change the discard mode of an existing thin pool LV:
.nf
lvchange --discards {ignore|nopassdown|passdown} VG/ThinPoolLV
.fi
 
.nf
Example
# lvs -o name,discards vg/poolA
poolA passdown

# lvchange --discards ignore vg/poolA
.fi

See lvm.conf thin_pool_discards to set the default discards mode.


.SS Chunk size

\&

The size of data blocks managed by a thin pool can be specified with
the --chunksize option when the thin pool LV is created.  The default
unit is kilobytes and the default value is 64KiB.  The value must be a
power of two between 4KiB and 1GiB.

When a thin pool is used primarily for the thin provisioning feature,
a larger value is optimal.  To optimize for a lot of snapshotting,
a smaller value reduces copying time and consumes less space.

Command to display the thin pool LV chunk size:
.nf
lvs -o+chunksize VG/ThinPoolLV
 
Example
# lvs -o name,chunksize
poolA 64.00k
.fi

See lvm.conf thin_pool_chunk_size to set the default chunk size.


.SS Size of pool metadata LV

\&

The amount of thin metadata depends on how many blocks are shared
between thin LVs (i.e. through snapshots).  A thin pool with many
snapshots may need a larger metadata LV.

The range of supported metadata LV sizes is 2MiB to 16GiB.
.br
The default size is estimated with the formula:
.br
ThinPoolLV_size / ThinPoolLV_chunk_size * 64b.

When creating a thin metadata LV explicitly, the size is specified
in the lvcreate command.  When a command automatically creates a
thin metadata LV, the --poolmetadatasize option can be used specify
a non-default size.  The default unit is megabytes.


.SS Create a thin snapshot of an external, read only LV

\&

Thin snapshots are typically taken of other thin LVs or other
thin snapshot LVs within the same thin pool.  It is also possible
to take thin snapshots of external, read only LVs.  Writes to the
snapshot are stored in the thin pool, and the external LV is used
to read unwritten parts of the thin snapshot.

.nf
lvcreate --type thin -n SnapLV -s VG/ExternLV --thinpool VG/ThinPoolLV
 
Example
# lvchange -an vg/lve
# lvchange --permission r vg/lve
# lvcreate --type thin -n snaplve -s vg/lve --thinpool vg/poolA

# lvs vg/lve vg/snaplve
LV      VG  Attr       LSize  Pool  Origin Data%
lve     vg  ori------- 10.00g
snaplve vg  Vwi-a-tz-- 10.00g poolA lve      0.00
.fi


.SS Convert a standard LV to a thin LV with an external origin

\&

A new thin LV can be created and given the name of an existing
standard LV.  At the same time, the existing LV is converted to a
read only external LV with a new name.  Unwritten portions of the
thin LV are read from the external LV.
The new name given to the existing LV can be specified with
--originname, otherwise the existing LV will be given a default
name, e.g. lvol#.

Convert ExampleLV into a read only external LV with the new name
ExternalLV, and create a new thin LV that is given the previous
name of ExampleLV.

.nf
lvconvert --type thin --thinpool VG/ThinPoolLV
      --originname ExternalLV --thin VG/ExampleLV

Example
# lvcreate -n lv_example -L 10G vg

# lvs
lv_example      vg          -wi-a-----  10.00g

# lvconvert --type thin --thinpool vg/poolC
          --originname lv_external --thin vg/lv_example

# lvs
LV              VG          Attr       LSize   Pool  Origin
lv_example      vg          Vwi-a-tz--  10.00g poolC lv_external
lv_external     vg          ori-------  10.00g
.fi


.SS Single step thin pool LV creation

\&

A thin pool LV can be created with a single lvcreate command,
rather than using lvconvert on existing LVs.
This one command creates a thin data LV, a thin metadata LV,
and combines the two into a thin pool LV.

.nf
lvcreate -L LargeSize --thinpool VG/ThinPoolLV

Example
# lvcreate -l1 --thinpool vg/poolC

# lvs vg/poolC
LV    VG  Attr       LSize Pool Origin Data%
poolC vg  twi-a-tz-- 8.00m               0.00

# lvs -a
poolC           vg          twi-a-tz--   8.00m
[poolC_tdata]   vg          Twi-ao----   8.00m
[poolC_tmeta]   vg          ewi-ao----   8.00m
.fi


.SS Single step thin pool LV and thin LV creation

\&

A thin pool LV and a thin LV can be created with a single
lvcreate command.  This one command creates a thin data LV,
a thin metadata LV, combines the two into a thin pool LV,
and creates a thin LV in the new pool.
.br
-L LargeSize specifies the physical size of the thin pool LV.
.br
-V VirtualSize specifies the virtual size of the thin LV.

.nf
lvcreate -L LargeSize -V VirtualSize -n ThinLV --thinpool VG/ThinPoolLV

Equivalent to:
lvcreate -L LargeSize --thinpool VG/ThinPoolLV
lvcreate --type thin -n ThinLV -V VirtualSize --thinpool VG/ThinPoolLV

Example
# lvcreate -L8M -V2G -n thinZ --thinpool vg/poolC

# lvs -a
poolC           vg          twi-a-tz--   8.00m
[poolC_tdata]   vg          Twi-ao----   8.00m
[poolC_tmeta]   vg          ewi-ao----   8.00m
thinZ           vg          Vwi-a-tz--   2.00g poolC
.fi