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

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: lvm2 or lvm1.
  • 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
      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
      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
      PV         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

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:

Expand
Units typeDescriptionAvailable optionsDefault

Base 2 units

Units are displayed in powers of 2 (multiples of 1024).

  • b: Bytes.
  • s: Sectors, 512 bytes each.
  • k: Kibibytes.
  • m: Mebibytes.
  • g: Gibibytes.
  • t: Tebibytes.
  • p: Pebibytes.
  • e: Exbibytes.
  • h: Human-readable, the most suitable unit is used.
  • r: Human-readable with rounding indicator, works similarly to h with rounding prefix < or > to indicate how LVM rounds the displayed size to the nearest unit.

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

Units are displayed in multiples of 1000.

  • B: Bytes.
  • S: Sectors, 512 bytes each.
  • K: Kilobytes.
  • M: Megabytes.
  • G: Gigabytes.
  • T: Terabytes.
  • P: Petabytes.
  • E: Exabytes.
  • H: Human-readable, the most suitable unit is used.
  • R: Human-readable with rounding indicator, works similarly to H with rounding prefix < or > to indicate how LVM rounds the displayed size to the nearest unit.

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 4m.

N/A

N/A

  • If you do not specify a value for the units, human-readable format (r) is used by default. The following vgs 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.

    # 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:

    # 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:

    # 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:

    # 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:

    # 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

  1. Open the lvm.conf file in an editor of your choice.
  2. 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 the lvs_cols parameter and modify it:

        lvs_cols="lv_name,vg_name,lv_attr"
    • To hide empty fields for the pvs, vgs, and lvs commands, uncomment the compact_output=1 setting:

        compact_output = 1
    • To set gigabytes as the default unit for the pvs, vgs, and lvs commands, replace the units = "r" setting with units = "G":

        units = "G"
  3. Ensure that the corresponding section of the lvm.conf file is uncommented. For example, to modify the lvs_cols parameter, the report section must be uncommented:

      report {
    ...
    }

Verification

  • View the changed values after modifying the lvm.conf file:

    # lvmconfig --typeconfig diff

7.4. Defining LVM selection criteria

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, and dmsetup info -c.
  • Processing commands include pvchange, vgchange, lvchange, vgimport, vgexport, vgremove, and lvremove.

    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 string 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 the myvg volume group:

      # 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:

      # 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 contains lvol and 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.00m
    • The following example of the lvs command displays only logical volumes with a raid1 segment type:

      # 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 tag mytag to only active logical volumes:

      # 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:

      # 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 with role=thinsnapshot and origin=thin1 to be skipped during normal activation commands:

      # 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.
      # lvs -a -S 'name=~_tmeta && role=metadata && size <= 4m'
        LV         VG      Attr       LSize
        [tp_tmeta] myvg   ewi-ao---- 4.00m
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat
Torna in cima