Chapter 7. Customizing the LVM report
LVM provides a wide range of configuration and command line options to produce customized reports and to filter the report’s output. You can sort the output, specify units, use selection criteria, and update the lvm.conf
file to customize the LVM report.
7.1. Controlling format of the LVM display
Whether you use pvs
, lvs
, or vgs
, these commands determine the default set of fields displayed and the sort order. You can control the output of these commands by executing the following commands.
Procedure
Change the default fields in the LVM display using the
-o
option:# pvs -o pv_name,pv_size,pv_free PV PSize PFree /dev/vdb1 17.14G 17.14G /dev/vdb2 17.14G 17.09G /dev/vdb3 17.14G 17.14G
Sort LVM display by using the
-O
option:# pvs -o pv_name,pv_size,pv_free -O pv_free PV PSize PFree /dev/vdb2 17.14G 17.09G /dev/vdb1 17.14G 17.14G /dev/vdb3 17.14G 17.14G
Display a reverse sort by using the
-O
argument along with the-
character:# pvs -o pv_name,pv_size,pv_free -O -pv_free PV PSize PFree /dev/vdb1 17.14G 17.14G /dev/vdb3 17.14G 17.14G /dev/vdb2 17.14G 17.09G
Additional resources
-
lvmreport(7)
,lvs(8)
,vgs(8)
, andpvs(8)
man page - Specifying the units for an LVM report display
- Customizing the LVM configuration file
7.2. Specifying the units for an LVM report display
You can view the size of the LVM devices in base 2 or base 10 units by specifying the --units
argument of the report command.
- Base 2 units
The default units are displayed in powers of 2, which is multiples of 1024. You can specify it using human-readable (
r
) with<
and>
rounding indicator, bytes (b
), sectors (s
), kilobytes (k
), megabytes (m
), gigabytes (g
), terabytes (t
), petabytes (p
), exabytes (e
), and human-readable (h
).The default display is
r
, when--units
is not specified. You can override the default by setting the units parameter in the global section of the/etc/lvm/lvm.conf
file.- Base 10 units
-
You can specify the units to be displayed in multiples of 1000 by capitalizing the unit specification (
R
,B
,S
,K
,M
,G
,T
,P
,E
,H
).
Procedure
Specify the units for the LVM for base 2 gigabytes units:
# pvs --units g /dev/vdb PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 931.00g 930.00g # vgs --units g myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n 931.00g 931.00g # lvs --units g myvg LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv myvg wi-a---- 1.OOg
Indicate the actual size of LVM by using the
r
option with the<
or>
prefix in the output:# vgs --units g myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n 931.00g 930.00g # vgs --units r myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n <931.00g <930.00 # vgs myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n <931.00g <930.00g
The
r
unit works similarly toh
(human-readable), but in addition, the reported value gets a prefix of<
or>
to indicate that the actual size is slightly more or less than the displayed size. LVM rounds the decimal value, causing non-exact sizes to be reported.It also shows how
--units g
or other--units
do not always display exactly correct sizes. It also shows the primary purpose ofr
, which is the<
to indicate that the displayed size is not exact. In this example, the value is not exact because the VG size is not an exact multiple of gigabytes, and .01 is also not an exact representation of the fraction.Specify the units for the LVM for base 10 gigabytes units:
# pvs --units G /dev/vdb PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 999.65G 998.58G # vgs --units G myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n 999.65G 998.58G # lvs --units G myvg LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv myvg wi-a---- 1.07G
Specify sectors (
s
), defined as 512 bytes, or custom units. The following example displays the output of thepvs
command as several sectors:# pvs --units s PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 1952440320S 1950343168S
Specify megabytes (
m
). The following example displays the output of thepvs
command in units of 4 MB:# pvs --units 4m PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 238335.00U 238079.00U
7.3. Customizing the LVM configuration file
By editing the lvm.conf
file, you can customize the LVM according to your specific storage and system requirements. For example, you can use lvm.conf
to modify filter settings, configure volume group auto activation, manage thin pool, or automatically extend a snapshot.
Procedure:
Display the default
lvm.conf
file:# lvmconfig --typeconfig default --withcomments
By default, the
lvm.conf
file contains only comments to display possible settings.Customize the
lvm.conf
file according to your requirements by uncommenting the setting inlvm.conf
. The following setting focuses on changing the default display of certain commands:In the
lvm.conf
file, adjust thelvs_cols
parameter to only print the specified fields:{ ... lvs_cols="lv_name,vg_name,lv_attr" ... }
Use this option instead of the
lvs -o lv_name,vg_name,lv_attr
command to avoid unnecessary frequent use of the-o
option.In the
lvm.conf
file, use thecompact_output=1
setting to avoid printing empty fields for thepvs
,vgs
, andlvs
commands:{ ... compact_output = 1 ... }
View the default values after modifying the
lvm.conf
file:# lvmconfig --typeconfig diff
Additional resources
-
lvm.conf(5)
man page
7.4. Defining LVM selection criteria
Selection criteria are a set of statements in the form of <field> <operator> <value>
, which use comparison operators to define values for specific fields. Objects that match the selection criteria are then processed or displayed. Statements are combined by logical and grouping operators. To define selection criteria use the -S
or --select
option followed by one or multiple statements.
Some LVM commands support the -S
option to select which objects to process based on certain attributes. These objects can be physical volumes (PVs), volume groups (VGs), or logical volumes (LVs).
The -S
option works by describing the objects to process, rather than naming each object. This is helpful when processing many objects and it would be difficult to find and name each object separately or when searching objects that have a complex set of characteristics. The select option can also be used as a shortcut to avoid typing many names.
Use the lvs -S help
command to see full sets of fields and possible operators. Replace lvs
with any reporting or processing command to see the details of that command.
Use selection criteria with LVM reporting and processing commands to only display or process the objects that satisfy chosen criteria:
-
Reporting commands include
pvs
,vgs
,lvs
,pvdisplay
,vgdisplay
,lvdisplay
, anddmsetup info -c
. -
Processing commands include
pvchange
,vgchange
,lvchange
,vgimport
,vgexport
,vgremove
, andlvremove
.
Procedure
Examples of selection criteria using the
pvs
command:# pvs PV VG Fmt Attr PSize PFree /dev/nvme2n1 lvm2 --- 1.00g 1.00g /dev/vdb1 myvg lvm2 a-- 1020.00m 396.00m /dev/vdb2 myvg lvm2 a-- 1020.00m 896.00m
# pvs -S name=~nvme PV Fmt Attr PSize PFree /dev/nvme2n1 lvm2 --- 1.00g 1.00g
# pvs -S vg_name=myvg PV VG Fmt Attr PSize PFree /dev/vdb1 myvg lvm2 a-- 1020.00m 396.00m /dev/vdb2 myvg lvm2 a-- 1020.00m 896.00m
Examples of selection criteria using the
lvs
commands:# lvs LV VG Attr LSize Cpy%Sync mylv myvg -wi-a----- 200.00m lvol0 myvg -wi-a----- 100.00m lvol1 myvg -wi-a----- 100.00m lvol2 myvg -wi------- 100.00m rr myvg rwi-a-r--- 120.00m 100.00
# lvs -S 'size > 100m && size < 200m' LV VG Attr LSize Cpy%Sync rr myvg rwi-a-r--- 120.00m 100.00
# lvs -S name=~lvol[02] LV VG Attr LSize lvol0 myvg -wi-a----- 100.00m lvol2 myvg -wi------- 100.00m
# lvs -S segtype=raid1 LV VG Attr LSize Cpy%Sync rr myvg rwi-a-r--- 120.00m 100.00
More advanced examples:
# lvchange --addtag mytag -S active=1 Logical volume myvg/mylv changed. Logical volume myvg/lvol0 changed. Logical volume myvg/lvol1 changed. Logical volume myvg/rr changed.
# lvs -a -o lv_name,vg_name,attr,size,pool_lv,origin,role -S 'name!~_pmspare' LV VG Attr LSize Pool Origin Role thin1 example Vwi-a-tz-- 2.00g tp public,origin,thinorigin thin1s example Vwi---tz-- 2.00g tp thin1 public,snapshot,thinsnapshot thin2 example Vwi-a-tz-- 3.00g tp public tp example twi-aotz-- 1.00g private [tp_tdata] example Twi-ao---- 1.00g private,thin,pool,data [tp_tmeta] example ewi-ao---- 4.00m private,thin,pool,metadata
# lvchange --setactivationskip n -S 'role=thinsnapshot && origin=thin1' Logical volume myvg/thin1s changed.
# lvs -a -S 'name=~_tmeta && role=metadata && size <= 4m' LV VG Attr LSize [tp_tmeta] myvg ewi-ao---- 4.00m
Additional resources
-
lvmreport(7)
man page