Red Hat Training
A Red Hat training course is available for RHEL 8
Chapter 16. LVM selection criteria
You can use the -S
or --select
option with many LVM reporting and processing commands to define selection criteria for those commands:
- Reporting commands
Display only the lines that satisfy the selection criteria. Examples of reporting commands for which you can define selection criteria include
pvs
,vgs
,lvs
,pvdisplay
,vgdisplay
,lvdisplay
,lvm devtypes
, anddmsetup info -c
.To show all rows, including those that do not satisfy the selection criteria, specify the
-o selected
option in addition to the-S
option. All rows are displayed and a "selected" column that shows1
if the row matches the selection criteria and0
if it does not is added.- Processing commands
-
Process only the items that satisfy the selection criteria. Examples of processing commands for which you can define selection criteria include
pvchange
,vgchange
,lvchange
,vgimport
,vgexport
,vgremove
, andlvremove
.
Selection criteria are a set of statements that use comparison operators to define the valid values for particular fields to display or process. The selected fields are, in turn combined by logical and grouping operators.
When specifying which fields to display using selection criteria, there is no requirement for the field which is in the selection criteria to be displayed. The selection criteria can contain one set of fields while the output can contain a different set of fields:
- For a listing of available fields for the various LVM components, see Selection criteria fields.
- For a listing of allowed operators, see Selection criteria operators or the lvm(8) man page.
You can also see full sets of fields and possible operators by specifying the
help
(or?
) keyword for the-S
or--select
option of a reporting commands. For example, the following command displays the fields and possible operators for thelvs
command.# lvs -S help
-
You can specify time values as selection criteria for fields with a field type of
time
. For information on specifying time values, see Specifying time values.
16.1. Selection criteria field types
The fields you specify for selection criteria are of a particular type. The help output for each field displays the filed type inside the brackets. The following help output examples show the output indicating the field types string
, string_list
, number
, percent
, size
and time
.
lv_name - Name. LVs created for internal use are enclosed in brackets.[string] lv_role - LV role. [string list] raid_mismatch_count - For RAID, number of mismatches found or repaired. [number] copy_percent - For RAID, mirrors and pvmove, current percentage in-sync. [percent] lv_size - Size of LV in current units. [size] lv_time - Creation time of the LV, if known [time]
The following table describes the selection criteria field types.
Table 16.1. Selection criteria field types
Field type | Description |
---|---|
number | Non-negative integer value. |
size |
Floating point value with units, |
percent |
Non-negative integer with or without |
string | Characters quoted by ` or " or unquoted. |
string list | Strings enclosed by [ ] or { } and elements delimited by either "all items must match" or "at least one item must match" operator. |
The values you specify for a field can be the following:
- Concrete values of the field type.
-
Regular expressions that include any fields of the
string
field type, such as "+~" operator. - Reserved values, for example -1, unknown, undefined, undef are all keywords to denote an undefined numeric value.
- Defined synonyms for the field values, which can be used in selection criteria for values just as for their original values.
16.2. Selection criteria operators
The following table describes the selection criteria grouping operators.
Table 16.2. Selection criteria grouping operators
Grouping operator | Description |
---|---|
( ) | Used for grouping statements |
[ ] | Used to group strings into a string list (exact match) |
{ } | Used to group strings into a string list (subset match) |
The following table describes the selection criteria comparison operators and the field types with which you can use them.
Table 16.3. Selection criteria comparison operators
Comparison operator | Description | Field type |
---|---|---|
=~ | Matching regular expression | regex |
!~ | Not matching regular expression | regex |
= | Equal to | number, size, percent, string, string list, time |
!~ | Not equal to | number, size, percent, string, string list, time |
>= | Greater than or equal to | number, size, percent, time |
> | Greater than | number, size, percent, time |
<= | Less than or equal to | number, size, percent, time |
< | Less than | number, size, percent, time |
since | Since specified time (same as >=) | time |
after | After specified time (same as >) | time |
until | Until specified time (same as <=) | time |
before | Before specified time (same as <) | time |
The following table describes the selection criteria logical and grouping operators.
Table 16.4. Selection criteria logical and grouping operators
Logical and grouping operator | Description |
---|---|
&& | All fields must match |
, | All fields must match (same as &&) |
|| | At least one field must match |
# | At least one field must match (same as ||) |
! | Logical negation |
( | Left parenthesis (grouping operator) |
) | Right parenthesis (grouping operator) |
[ | List start (grouping operator) |
] | List end (grouping operator) |
{ | List subset start (grouping operator) |
} | List subset end (grouping operator) |
16.3. Selection criteria fields
There are different logical and physical volume selection criteria fields you can specify. The following examples describe them.
Table 16.5. Logical volume fields
Logical volume field | Description | Field type |
---|---|---|
| Unique identifier | string |
| Name (logical volumes created for internal use are encclosed in brackets) | string |
| Full name of logical volume group, namely VG/LV | string |
| Full pathname for logical volume (blank for internal logical volumes) | string |
|
Internal device mapper pathname for logical volume (in | string |
| For logical volumes that are components of another logical volume, the parent logical volume | string |
| logical volume layout | string list |
| logical volume role | string list |
| Set if mirror/RAID images underwent initial resynchronization | number |
| Set if mirror/RAID image is synchronized | number |
| Set if snapshot logical volume is being merged to origin | number |
| Set if logical volume is being converted | number |
| logical volume allocation policy | string |
| Set if snapshot merge failed | number |
| Set if snapshot logical volume is invalid | number |
| Set if logical volume is skipped on activation | number |
| For thin pools, behavior when full | string |
| Active state of the logical volume | string |
| Persistent major number or -+ if not persistent | number |
| Persistent minor number or -+ if not persistent | number |
| Read ahead setting in current units | size |
| Size of logical volume in current units | size |
| For thin and cache pools, the size of the logical volume that holds the metadata | size |
| Number of segments in logical volume | number |
| For snapshots and thins, the origin device of this logical volume | size |
| For snapshots and thins, the UUID of origin device of this LV. | string |
| For snapshots, the size of the origin device of this logical volume | size |
| For snapshot and thin pools and volumes, the percentage full if logical volume is active | percent |
| For snapshots, the percentage full if logical volume is active | percent |
| For cache and thin pools, the percentage of metadata full if logical volume is active | percent |
|
For Cache, RAID, mirrors, and | percent |
|
For Cache, RAID, mirrors, and | percent |
| For RAID, number of mismatches found or repaired | number |
| For RAID, the current synchronization action being performed | string |
| For RAID1, the number of outstanding writes allowed to write mostly devices | number |
| For RAID1, the minimum recovery I/O load in kiB/sec/disk | number |
| For RAID1, the maximum recovery I/O load in kiB/sec/disk | number |
| The integrity mode | string |
| The integrity block size | number |
| The number of integrity mismatches | number |
| For thin pools, how discards are handled in kernel | string |
|
For | string |
| For thin and cache pools, the logical volume holding the associated data | string |
| For thin and cache pools, the logical volume holding the associated metadata | string |
| For thin volumes, the thin pool logical volume for this volume | string |
| Tags, if any | string list |
| Configuration profile attached to this logical volume | string |
Table 16.6. Logical volume device combined info and status fields
Logical volume field | Description | Field type |
---|---|---|
| Selects according to both logical volume device info and logical volume status | string |
Table 16.7. Logical volume device info fields
Logical volume field | Description | Field type |
---|---|---|
| Currently assigned major number or -1 if logical volume is not active | number |
| Currently assigned minor number or -1 if logical volume is not active | number |
| Set if logical volume is suspended | number |
| Set if logical volume device is open | number |
Table 16.8. Logical volume device status fields
Logical volume field | Description | Field type |
---|---|---|
| Total cache blocks | number |
| Used cache blocks | number |
| Dirty cache blocks | number |
| Cache read hits | number |
| Cache read misses | number |
| Cache write hits | number |
| Cache write misses | number |
| The writecache block size | number |
| Total writecache blocks | number |
| Total writecache free blocks | number |
| Total writecache writeback blocks | number |
| logical volume health status | string |
Table 16.9. Physical volume label fields
Physical volume field | Description | Field type |
---|---|---|
| Unique identifier | string |
| Size of underlying device in current units | size |
| Name | string |
| Device major number | number |
| Device minor number | number |
| Free metadata area space on this device in current units | size |
| Size of smallest metadata area on this device in current units | size |
Table 16.10. Physical volume fields
Physical volume field | Description | Field type |
---|---|---|
| Offset to the start of data on the underlying device | number |
| Size of physical volume in current units | size |
| Total amount of unallocated space in current units | size |
| Total amount of allocated space in current units | size |
| Various attributes | string |
| Set if this device is missing in system | number |
| Total number of physical extents | number |
| Total number of allocated physical extents | number |
| Tags, if any | string list |
| Number of metadata areas on this device | number |
| Number of metadata areas in use on this device | number |
| Device ID such as the WWID | number |
| Type of device ID such as WWID | string |
Table 16.11. Volume group fields
Volume group field | Description | Field type |
---|---|---|
| Unique identifier | string |
| Name | string |
| Various attributes | string |
| Set if volume group is exported | number |
| Set if VG autoactivation is enabled | number |
| Set if volume group is partial | number |
| Set if VG is shared | number |
| Total size of volume group in current units | size |
| Total amount of free space in current units | size |
| System ID of the volume group indicating which host owns it | string |
| Size of physical extents in current units | size |
| Total number of physical extents | number |
| Total number of unallocated physical extents | number |
| Number of PVs in VG which are missing | number |
| Revision number of internal metadata that increments whenever it changes | number |
| Tags, if any | string list |
| Configuration profile attached to this volume group | string |
| Number of metadata areas on this volume group | number |
| Number of metadata areas in use on this volume group | number |
| Free metadata area space for this volume group in current units | size |
| Size of the smallest metadata area for this volume group in current units | size |
| Target number of in use metadata areas in the volume group | number |
Table 16.12. Logical volume segment fields
Logical volume segment field | Description | Field type |
---|---|---|
| Type of logical volume segment | string |
| Number of stripes or mirror legs | number |
| Number of data stripes or mirror/raid1 legs | number |
| For stripes, amount of data placed on one device before switching to the next | size |
| For mirrors, the unit of data copied when synchronizing devices | size |
| For snapshots, the unit of data used when tracking changes | size |
| For thin pools, the number of thin volumes in this pool | number |
| For thin pool, how discards are handled | string |
| For cache pools, how writes are cached | string |
| For thin pools, if zeroing is enabled | number |
| For thin pools, the transaction id | number |
| For thin volumes, the thin device id | number |
| Underlying devices used with starting extent numbers | string |
|
| string |
| The cache policy (cached segments only) | string |
| Cache settings or parameters (cached segments only) | string list |
Table 16.13. Physical volume segment fields
Physical volume segment field | Description | Field type |
---|---|---|
| Physical extent number of start of segment | number |
| Number of extents in segment | number |
You can use the synonyms listed in the following table for field values. These synonyms are usable in selection criteria as well as for values just like their original values. In this table, a field value of ""
indicates a blank string, which can be matched by specifying -S 'field_name=""'
.
In this table, a field indicated by 0
or 1
indicates a binary value. You can specify a --binary
option for reporting tools which causes binary fields to display 0 or 1 instead of what is indicated in this table as "some text" or "".
Table 16.14. Selection criteria synonyms
Field | Field value | Synonyms |
| allocatable | 1 |
| "" | 0 |
| exported | 1 |
| "" | 0 |
| missing | 1 |
| "" | 0 |
| extendable | 1 |
| "" | 0 |
| exported | 1 |
| "" | 0 |
| partial | 1 |
| "" | 0 |
| clustered | 1 |
| "" | 0 |
| writable | rw, read-write |
| read-only | r, ro |
| unmanaged | unknown, undefined, undef, -1 |
| initial image sync | sync, 1 |
| "" | 0 |
| image synced | synced, 1 |
| "" | 0 |
| merging | 1 |
| "" | 0 |
| converting | 1 |
| "" | 0 |
| allocation locked | locked, 1 |
| "" | 0 |
| fixed minor | fixed, 1 |
| "" | 0 |
| active locally | active, locally, 1 |
| "" | 0 |
| active remotely | active, remotely, 1 |
| "" | 0 |
| active exclusively | active, exclusively, 1 |
| "" | 0 |
| merge failed | failed, 1 |
| "" | 0 |
| snapshot invalid | invalid, 1 |
| "" | 0 |
| suspended | 1 |
| "" | 0 |
| live table present | live table, live, 1 |
| "" | 0 |
| inactive table present | inactive table, inactive, 1 |
| "" | 0 |
| open | 1 |
| "" | 0 |
| skip activation | skip, 1 |
| "" | 0 |
| zero | 1 |
| "" | 0 |
| writable | rw, read-write |
| read-only | r, ro |
| read-only-override | ro-override, r-override, R |
| error | error when full, error if no space |
| queue | queue when full, queue if no space |
| "" | undefined |
| "" | undefined |
| "" | undefined |
| "" | undefined |
16.4. Specifying time values
When specifying time values for LVM selection, you can use either a standardized time specification format or a more free-form specification, as described in Standard time selection format and Time specification formats sections.
You can specify the way time values are displayed with the report/time format
configuration option in the /etc/lvm/lvm.conf
configuration file. Information on specifying this option is provided in the lvm.conf
file. When specifying time values, you can use the comparison operator aliases since
, after
, until
, and before
.
16.4.1. Standard time selection format
You can specify time values for LVM selection in the following format:
date time timezone
Table 16.15. Time specification formats
Field | Field value |
---|---|
date | YYYY-MM-DD |
YYYY-MM, default DD=1 | |
YYYY, default MM=01 and DD=01 | |
time | hh:mm:ss |
hh:mm, default ss=0 | |
hh, default mm=0, default ss=0 | |
timezone (always with + or - sign) | +hh:mm or -hh:mm |
+hh or -hh |
The full date/time specification is YYYY-MM-DD hh:mm:ss
. Users are able to leave date/time parts from right to left. Whenever these parts are left out, a range is assumed automatically with second granularity. For example:
- "2015-07-07 9:51" means range of "2015-07-07 9:51:00" - "2015-07-07 9:51:59"
- "2015-07" means range of "2015-07-01 0:00:00" - "2015-07-31 23:59:59"
- "2015" means range of "2015-01-01 0:00:00" - "2015-12-31 23:59:59"
The following examples show the date/time specification as used in selection criteria:
lvs -S 'time since "2015-07-07 9:51"' lvs -S 'time = "2015-07"" lvs -S 'time = "2015"'
16.4.2. Freeform time selection format
You can specify the date/time specification in LVM selection criteria using the following entitles.
- weekday names ("Sunday" - "Saturday" or abbreviated as "Sun" - "Sat")
- labels for points in time ("noon", "midnight")
- labels for a day relative to current day ("today", "yesterday")
- points back in time with relative offset from today (N is a number)
- ( "N" "seconds"/"minutes"/"hours"/"days"/"weeks"/"years" "ago")
- ( "N" "secs"/"mins"/"hrs" … "ago")
- ( "N" "s"/"m"/"h" … "ago")
- time specification either in hh:mm:ss format or with AM/PM suffixes
- month names ("January" - "December" or abbreviated as "Jan" - "Dec")
The following examples the show the freeform
date/time specification as used in selection criteria:
lvs -S 'time since "yesterday 9AM"' lvs -S 'time since "Feb 3 years 2 months ago"' lvs -S 'time = "February 2015"' lvs -S 'time since "Jan 15 2015" && time until yesterday' lvs -S 'time since "today 6AM"'
16.5. Selection criteria display examples
A series of examples in this section show you how to use selection criteria for LVM display commands. The examples in this section use a system configured with LVM volumes that yield the following output when selection criteria are not used.
# lvs -a -o+layout,role
LV VG Attr LSize Pool Origin Data% Meta% Layout Role
root f1 -wi-ao---- 9.01g linear public
swap f1 -wi-ao---- 512.00m linear public
[lvol0_pmspare] vg ewi------- 4.00m linear private, \
pool,spare
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol2 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public, \
origin, \
thinorigin
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public, \
snapshot, \
thinsnapshot
pool vg twi-aotz-- 100.00m 0.00 1.07 thin,pool private
[pool_tdata] vg Twi-ao---- 100.00m linear private, \
thin,pool, \
data
[pool_tmeta] vg ewi-ao---- 4.00m linear private, \
thin,pool, \
metadata
The following command displays all logical volumes with lvol[13]
in their name, using a regular expression to specify this.
# lvs -a -o+layout,role -S 'lv_name=~lvol[13]'
LV VG Attr LSize Pool Origin Data% Layout Role
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public,snapshot,thinsnapshot
The following command displays all logical volumes greater than 500 megabytes in size.
# lvs -a -o+layout,role -S 'lv_size>500m'
LV VG Attr LSize Pool Origin Data% Layout Role
root f1 -wi-ao---- 9.01g linear public
swap f1 -wi-ao---- 512.00m linear public
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol2 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public,origin,thinorigin
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public,snapshot, \
thinsnapshot
The following command displays all logical volumes that include thin
as a logical volume role, indicating that the logical volume is used in constructing a thin pool. This example uses braces ({}) to indicate a subset in the display.
# lvs -a -o+layout,role -S 'lv_role={thin}'
LV VG Attr LSize Layout Role
[pool_tdata] vg Twi-ao---- 100.00m linear private,thin,pool,data
[pool_tmeta] vg ewi-ao---- 4.00m linear private,thin,pool,metadata
The following command displays all usable top-level logical volumes, which are the logical volumes with a role of public
. If you do not specify braces ({}) in a string list to indicate a subset, it is assumed by default; specifying lv_role=public
is equivalent to specifying lv_role={public}
.
# lvs -a -o+layout,role -S 'lv_role=public'
LV VG Attr LSize Pool Origin Data% Layout Role
root f1 -wi-ao---- 9.01g linear public
swap f1 -wi-ao---- 512.00m linear public
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol2 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public,origin,thinorigin
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public,snapshot,thinsnapshot
The following command displays all logical volumes with a thin layout.
# lvs -a -o+layout,role -S 'lv_layout={thin}'
LV VG Attr LSize Pool Origin Data% Meta% Layout Role
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol2 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public,origin, \
thinorigin
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public,snapshot, \
thinsnapshot
pool vg twi-aotz-- 100.00m 0.00 1.07 thin,pool private
The following command displays all logical volumes with a layout field that matches sparse,thin
exactly. Note that it is not necessary to specify the string list members for the match to be positive.
# lvs -a -o+layout,role -S 'lv_layout=[sparse,thin]'
LV VG Attr LSize Pool Origin Data% Layout Role
lvol1 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public
lvol2 vg Vwi-a-tz-- 1.00g pool 0.00 thin,sparse public,origin,thinorigin
lvol3 vg Vwi---tz-k 1.00g pool lvol2 thin,sparse public,snapshot,thinsnapshot
The following command displays the logical volume names of the logical volumes that are thin, sparse logical volumes. Note that the list of fields used for selection criteria do not need to be the same as the list of fields to display.
# lvs -a -o lv_name -S 'lv_layout=[sparse,thin]'
LV
lvol1
lvol2
lvol3
16.6. Selection criteria processing examples
The following series of examples show how to use selection criteria in commands that process LVM logical volumes.
This example shows the initial configuration of a group of logical volumes, including thin snapshots. Thin snapshots have the skip_activation
flag set by default. This example also includes the logical volume lvol4
, which also has the skip_activation
flag set.
# lvs -o name,skip_activation,layout,role
LV SkipAct Layout Role
root linear public
swap linear public
lvol1 thin,sparse public
lvol2 thin,sparse public,origin,thinorigin
lvol3 skip activation thin,sparse public,snapshot,thinsnapshot
lvol4 skip activation linear public
pool thin,pool private
The following command removes the skip_activation
flag from all logical volumes that are thin snapshots.
# lvchange --setactivationskip n -S 'role=thinsnapshot'
Logical volume "lvol3" changed.
The following command shows the configuration of the logical volumes after executing the lvchange
command. Note that the skip_activation
flag has not been unset from the logical volume that is not a thin snapshot.
# lvs -o name,active,skip_activation,layout,role
LV Active SkipAct Layout Role
root active linear public
swap active linear public
lvol1 active thin,sparse public
lvol2 active thin,sparse public,origin,thinorigin
lvol3 thin,sparse public,snapshot,thinsnapshot
lvol4 active skip activation linear public
pool active thin,pool private
The following command shows the configuration of the logical volumes after an additional thin origin/snapshot volume has been created.
# lvs -o name,active,skip_activation,origin,layout,role
LV Active SkipAct Origin Layout Role
root active linear public
swap active linear public
lvol1 active thin,sparse public
lvol2 active thin,sparse public,origin,thinorigin
lvol3 lvol2 thin,sparse public,snapshot,thinsnapshot
lvol4 active skip activation linear public
lvol5 active thin,sparse public,origin,thinorigin
lvol6 lvol5 thin,sparse public,snapshot,thinsnapshot
pool active thin,pool private
The following command activates logical volumes that are both thin snapshot volumes and have an origin volume of lvol2
.
# lvchange -ay -S 'lv_role=thinsnapshot && origin=lvol2' # lvs -o name,active,skip_activation,origin,layout,role LV Active SkipAct Origin Layout Role root active linear public swap active linear public lvol1 active thin,sparse public lvol2 active thin,sparse public,origin,thinorigin lvol3 active lvol2 thin,sparse public,snapshot,thinsnapshot lvol4 active skip activation linear public lvol5 active thin,sparse public,origin,thinorigin lvol6 lvol5 thin,sparse public,snapshot,thinsnapshot pool active thin,pool private
If you execute a command on a whole item while specifying selection criteria that match an item from that whole, the entire whole item is processed. For example, if you change a volume group while selecting one or more items from that volume group, the whole volume group is selected. This example selects logical volume lvol1
, which is part of volume group vg
. All of the logical volumes in volume group vg
are processed.
# lvs -o name,vg_name LV VG root fedora swap fedora lvol1 vg lvol2 vg lvol3 vg lvol4 vg lvol5 vg lvol6 vg pool vg # vgchange -ay -S 'lv_name=lvol1' 7 logical volume(s) in volume group "vg" now active
The following example shows a more complex selection criteria statement. In this example, all logical volumes are tagged with mytag
if they have a role of origin and either are named lvol[456]
or the logical volume size is more than 5 gigabytes.
# lvchange --addtag mytag -S '(role=origin && lv_name=~lvol[456]) || lv_size > 5g'
Logical volume "root" changed.
Logical volume "lvol5" changed.