Questo contenuto non è disponibile nella lingua selezionata.
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 Copia collegamentoCollegamento copiato negli appunti!
LVM command output can be customized by controlling displayed fields, sorting options, and formatting for pvs, lvs, and vgs commands by using specific arguments.
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
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:lvm2orlvm1. -
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
-ooption. The following example displays only the name, size and free space of the physical volumes:# pvs -o pv_name,pv_size,pv_freePV 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
-Ooption. 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_freePV PSize PFree /dev/vdb2 17.14G 17.09G /dev/vdb1 17.14G 17.14G /dev/vdb3 17.14G 17.14GTo sort the results by descending order, use the
-Ooption along with the-character:# pvs -o pv_name,pv_size,pv_free -O -pv_freePV PSize PFree /dev/vdb1 17.14G 17.14G /dev/vdb3 17.14G 17.14G /dev/vdb2 17.14G 17.09G
7.2. Specifying the units for an LVM display Copia collegamentoCollegamento copiato negli appunti!
LVM display commands support customization of size unit output by using base 2, base 10, or custom units with the --units argument for flexible formatting.
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 followingvgscommand 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.# vgs myvgVG #PV #LV #SN Attr VSize VFree myvg 1 1 0 wz-n <931.00g <930.00gThe following
pvscommand displays the output in base 2 gibibyte units for the/dev/vdbphysical volume:# pvs --units g /dev/vdbPV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 931.00g 930.00gThe following
pvscommand displays the output in base 10 gigabyte units for the/dev/vdbphysical volume:# pvs --units G /dev/vdbPV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 999.65G 998.58GThe following
pvscommand displays the output in 512-byte sectors:# pvs --units sPV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 1952440320S 1950343168SYou can specify custom units for an LVM display command. The following example displays the output of the
pvscommand in units of 4 mebibytes:# pvs --units 4mPV VG Fmt Attr PSize PFree /dev/vdb myvg lvm2 a-- 238335.00U 238079.00U
7.3. Customizing the LVM configuration file Copia collegamentoCollegamento copiato negli appunti!
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.conffile in an editor of your choice. Customize the
lvm.conffile by uncommenting and modifying the setting for which you want to modify the default display values.To customize what fields you see in the
lvsoutput, uncomment thelvs_colsparameter and modify it:lvs_cols="lv_name,vg_name,lv_attr"To hide empty fields for the
pvs,vgs, andlvscommands, uncomment thecompact_output=1setting:compact_output = 1To set gigabytes as the default unit for the
pvs,vgs, andlvscommands, replace theunits = "r"setting withunits = "G":units = "G"
Ensure that the corresponding section of the
lvm.conffile is uncommented. For example, to modify thelvs_colsparameter, thereportsection must be uncommented:report { ... }
Verification
View the changed values after modifying the
lvm.conffile:# lvmconfig --typeconfig diff
7.4. Defining LVM selection criteria Copia collegamentoCollegamento copiato negli appunti!
LVM selection criteria use the -S option to filter and process physical volumes, volume groups, and logical volumes based on specific field values and operators.
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
pvscommands The following example of the
pvscommand displays only physical volumes with a name that contains the stringnvme:# pvs -S name=~nvmePV Fmt Attr PSize PFree /dev/nvme2n1 lvm2 --- 1.00g 1.00gThe following example of the
pvscommand displays only physical devices in themyvgvolume group:# pvs -S vg_name=myvgPV 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
lvscommands The following example of the
lvscommand displays only logical volumes with a size greater than 100m but less than 200m:# lvs -S 'size > 100m && size < 200m'LV VG Attr LSize Cpy%Sync rr myvg rwi-a-r--- 120.00m 100.00The following example of the
lvscommand displays only logical volumes with a name that containslvoland any number between 0 and 2:# lvs -S name=~lvol[02]LV VG Attr LSize lvol0 myvg -wi-a----- 100.00m lvol2 myvg -wi------- 100.00mThe following example of the
lvscommand displays only logical volumes with araid1segment type:# lvs -S segtype=raid1LV 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
lvchangecommand adds a specific tagmytagto only active logical volumes:# lvchange --addtag mytag -S active=1Logical volume myvg/mylv changed. Logical volume myvg/lvol0 changed. Logical volume myvg/lvol1 changed. Logical volume myvg/rr changed.The following example of the
lvscommand displays all logical volumes whose name does not match_pmspareand changes the default headers to custom ones:# 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,metadataThe following example of the
lvchangecommand flags a logical volume withrole=thinsnapshotandorigin=thin1to be skipped during normal activation commands:# lvchange --setactivationskip n -S 'role=thinsnapshot && origin=thin1'Logical volume myvg/thin1s changed.The following example of the
lvscommand displays only logical volumes that match all three conditions:-
Name contains
_tmeta. -
Role is
metadata. - Size is less or equal to 4m.
# lvs -a -S 'name=~_tmeta && role=metadata && size <= 4m'LV VG Attr LSize [tp_tmeta] myvg ewi-ao---- 4.00m-
Name contains
- Examples of selection criteria using the