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:

Copy to Clipboard Toggle word wrap
# 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:

Copy to Clipboard Toggle word wrap
# 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:

Copy to Clipboard Toggle word wrap
# 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:

Copy to Clipboard Toggle word wrap
# 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

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

    Copy to Clipboard Toggle word wrap
    # 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 Toggle word wrap
    # 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 Toggle word wrap
    # 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 Toggle word wrap
    # 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 Toggle word wrap
    # 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:

      Copy to Clipboard Toggle word wrap
        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:

      Copy to Clipboard Toggle word wrap
        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":

      Copy to Clipboard Toggle word wrap
        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:

    Copy to Clipboard Toggle word wrap
      report {
    ...
    }

Verification

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

    Copy to Clipboard Toggle word wrap
    # 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, 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:

    Copy to Clipboard Toggle word wrap
    # 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:

    Copy to Clipboard Toggle word wrap
    # 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 Toggle word wrap
    # 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:

    Copy to Clipboard Toggle word wrap
    # 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:

    Copy to Clipboard Toggle word wrap
    # 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:

    Copy to Clipboard Toggle word wrap
    # 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 Toggle word wrap
    # 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:

    Copy to Clipboard Toggle word wrap
    # 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 Toggle word wrap
    # 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 on your system
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat, Inc.