Este conteúdo não está disponível no idioma selecionado.
Chapter 7. Customizing the LVM report
LVM provides a wide range of configuration and command line options to produce customized reports. You can sort the output, specify units, use selection criteria, and update the lvm.conf
file to customize the LVM report.
7.1. Controlling the format of the LVM display
When you use the pvs
, lvs
, or vgs
command without additional options, you see the default set of fields displayed in the default sort order. The default fields for the pvs
command include the following information sorted by the name of physical volumes:
pvs
# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 VolumeGroupName lvm2 a-- 17.14G 17.14G
/dev/vdb2 VolumeGroupName lvm2 a-- 17.14G 17.09G
/dev/vdb3 VolumeGroupName lvm2 a-- 17.14G 17.14G
PV
- Physical volume name.
VG
- Volume group name.
Fmt
-
Metadata format of the physical volume:
lvm2
orlvm1
. Attr
- Status of the physical volume: (a) - allocatable or (x) - exported.
PSize
- Size of the physical volume.
PFree
- Free space remaining on the physical volume.
Displaying custom fields
To display a different set of fields than the default, use the -o
option. The following example displays only the name, size and free space of the physical volumes:
pvs -o pv_name,pv_size,pv_free
# 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
Sorting the LVM display
To sort the results by specific criteria, use the -O
option. The following example sorts the entries by the free space of their physical volumes in ascending order:
pvs -o pv_name,pv_size,pv_free -O pv_free
# 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
To sort the results by descending order, use the -O
option along with the -
character:
pvs -o pv_name,pv_size,pv_free -O -pv_free
# 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 pages on your system - Specifying the units for an LVM display
- Customizing the LVM configuration file
7.2. Specifying the units for an LVM display
You can view the size of the LVM devices in base 2 or base 10 units by specifying the --units
argument of an LVM display command. See the following table for all arguments:
Units type | Description | Available options | Default |
---|---|---|---|
Base 2 units | Units are displayed in powers of 2 (multiples of 1024). |
|
|
Base 10 units | Units are displayed in multiples of 1000. |
| N/A |
Custom units |
Combination of a quantity with a base 2 or base 10 unit. For example, to display the results in 4 mebibytes, use | N/A | N/A |
If you do not specify a value for the units, human-readable format (
r
) is used by default. The followingvgs
command displays the size of VGs in human-readable format. The most suitable unit is used and the rounding indicator<
shows that the actual size is an approximation and it is less than 931 gibibytes.Copy to Clipboard Copied! Toggle word wrap Toggle overflow vgs myvg
# vgs myvg VG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n <931.00g <930.00g
The following
pvs
command displays the output in base 2 gibibyte units for the/dev/vdb
physical volume:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs --units g /dev/vdb
# pvs --units g /dev/vdb PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 931.00g 930.00g
The following
pvs
command displays the output in base 10 gigabyte units for the/dev/vdb
physical volume:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs --units G /dev/vdb
# pvs --units G /dev/vdb PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 999.65G 998.58G
The following
pvs
command displays the output in 512-byte sectors:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs --units s
# pvs --units s PV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 1952440320S 1950343168S
You can specify custom units for an LVM display command. The following example displays the output of the
pvs
command in units of 4 mebibytes:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs --units 4m
# 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
You can customize your LVM configuration according to your specific storage and system requirements by editing the lvm.conf
file. For example, you can edit the lvm.conf
file to modify filter settings, configure volume group auto activation, manage a thin pool, or automatically extend a snapshot.
Procedure:
-
Open the
lvm.conf
file in an editor of your choice. Customize the
lvm.conf
file by uncommenting and modifying the setting for which you want to modify the default display values.To customize what fields you see in the
lvs
output, uncomment thelvs_cols
parameter and modify it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs_cols="lv_name,vg_name,lv_attr"
lvs_cols="lv_name,vg_name,lv_attr"
To hide empty fields for the
pvs
,vgs
, andlvs
commands, uncomment thecompact_output=1
setting:Copy to Clipboard Copied! Toggle word wrap Toggle overflow compact_output = 1
compact_output = 1
To set gigabytes as the default unit for the
pvs
,vgs
, andlvs
commands, replace theunits = "r"
setting withunits = "G"
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow units = "G"
units = "G"
Ensure that the corresponding section of the
lvm.conf
file is uncommented. For example, to modify thelvs_cols
parameter, thereport
section must be uncommented:Copy to Clipboard Copied! Toggle word wrap Toggle overflow report { ... }
report { ... }
Verification
View the changed values after modifying the
lvm.conf
file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvmconfig --typeconfig diff
# lvmconfig --typeconfig diff
Additional resources
-
lvm.conf(5)
man page on your system
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. Objects can be physical volumes (PVs), volume groups (VGs), or logical volumes (LVs). Statements are combined by logical and grouping operators.
To define selection criteria use the -S
or --select
option followed by one or multiple statements.
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 -S
option can also be used as a shortcut to avoid typing many names.
To see full sets of fields and possible operators, use the lvs -S help
command. Replace lvs
with any reporting or processing command to see the details of that command:
-
Reporting commands include
pvs
,vgs
,lvs
,pvdisplay
,vgdisplay
,lvdisplay
, anddmsetup info -c
. -
Processing commands include
pvchange
,vgchange
,lvchange
,vgimport
,vgexport
,vgremove
, andlvremove
.
Examples of selection criteria using the pvs
commands
The following example of the
pvs
command displays only physical volumes with a name that contains the stringnvme
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs -S name=~nvme
# pvs -S name=~nvme PV Fmt Attr PSize PFree /dev/nvme2n1 lvm2 --- 1.00g 1.00g
The following example of the
pvs
command displays only physical devices in themyvg
volume group:Copy to Clipboard Copied! Toggle word wrap Toggle overflow pvs -S vg_name=myvg
# 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
The following example of the
lvs
command displays only logical volumes with a size greater than 100m but less than 200m:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs -S 'size > 100m && size < 200m'
# lvs -S 'size > 100m && size < 200m' LV VG Attr LSize Cpy%Sync rr myvg rwi-a-r--- 120.00m 100.00
The following example of the
lvs
command displays only logical volumes with a name that containslvol
and any number between 0 and 2:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs -S name=~lvol[02]
# lvs -S name=~lvol[02] LV VG Attr LSize lvol0 myvg -wi-a----- 100.00m lvol2 myvg -wi------- 100.00m
The following example of the
lvs
command displays only logical volumes with araid1
segment type:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs -S segtype=raid1
# lvs -S segtype=raid1 LV VG Attr LSize Cpy%Sync rr myvg rwi-a-r--- 120.00m 100.00
Advanced examples
You can combine selection criteria with other options.
The following example of the
lvchange
command adds a specific tagmytag
to only active logical volumes:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvchange --addtag mytag -S active=1
# 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.
The following example of the
lvs
command displays all logical volumes whose name does not match_pmspare
and changes the default headers to custom ones:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs -a -o lv_name,vg_name,attr,size,pool_lv,origin,role -S 'name!~_pmspare'
# 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
The following example of the
lvchange
command flags a logical volume withrole=thinsnapshot
andorigin=thin1
to be skipped during normal activation commands:Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvchange --setactivationskip n -S 'role=thinsnapshot && origin=thin1'
# lvchange --setactivationskip n -S 'role=thinsnapshot && origin=thin1' Logical volume myvg/thin1s changed.
The following example of the
lvs
command displays only logical volumes that match all three conditions:-
Name contains
_tmeta
. -
Role is
metadata
. - Size is less or equal to 4m.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow lvs -a -S 'name=~_tmeta && role=metadata && size <= 4m'
# lvs -a -S 'name=~_tmeta && role=metadata && size <= 4m' LV VG Attr LSize [tp_tmeta] myvg ewi-ao---- 4.00m
-
Name contains
Additional resources
-
lvmreport(7)
man page on your system