How to use the command 'pvs' (with examples)

How to use the command 'pvs' (with examples)

The pvs command in Linux is designed to display information regarding physical volumes. Physical volumes are integral components of the Linux LVM (Logical Volume Manager); they are storage devices or space that form part of a volume group. The pvs command helps system administrators gain insights into their disk storage by providing detailed information on these physical volumes, facilitating effective volume management.

Display Information About Physical Volumes

Code:

pvs

Motivation:

The command pvs without any additional options is often used when a system administrator wants to get a quick overview of all the physical volumes available on a system. It simplifies the task of monitoring the state of each physical volume, allowing the user to make informed decisions about storage allocation, restructuring, or optimization of volume groups.

Explanation:

  • pvs: This command on its own fetches and displays the list of all physical volumes recognized by the LVM. It retrieves essential details such as the name of the physical volume, volume group association, size, and more.

Example Output:

  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda1  vg0    lvm2 a--  100.00g 0   
  /dev/sdb1  vg1    lvm2 a--  500.00g 100.00g

Display Non-Physical Volumes

Code:

pvs -a

Motivation:

Using pvs -a is particularly important when troubleshooting or validating any missing physical volumes. This command is useful for displaying potential devices that can be converted to physical volumes but aren’t yet designated as such. It helps to identify devices that might be overlooked when considering expansion or depletion of storage resources.

Explanation:

  • -a: This option expands the search to all devices, listing non-physical volumes. It ensures that every block device, which might be a physical volume, is displayed in the output, whether currently used as a physical volume or not.

Example Output:

  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda1  vg0    lvm2 a--  100.00g 0   
  /dev/sdb1  vg1    lvm2 a--  500.00g 100.00g
  unknown    unknown ---       20.00g 

Change Default Display to Show More Details

Code:

pvs -v

Motivation:

The verbose option -v provides additional detail over the standard display. This enhanced verbosity is advantageous when detailed diagnosis of the existing physical volumes is necessary, such as when preparing a report, auditing configurations, or seeking in-depth technical information about the volumes.

Explanation:

  • -v: Stands for verbose mode. This option enriches the output with supplementary information which might not be displayed in the default mode. This can include additional properties or metadata related to each physical volume.

Example Output:

  Wiping    PV          VG     Fmt  Attr PSize  PFree  DevSize PV UUID                               
  [2.5G]    /dev/sda1   vg0    lvm2 a--  100.00g 0     100.00g  xpJ1f6-afSQ-QVx4-P74k-Q5mB-dphd-T67sVM
  [510.00m] /dev/sdb1   vg1    lvm2 a--  500.00g 100g  500.00g  qb7J1f-8fSQ-1Gx4-M74k-H5bB-ghrd-K98rON

Display Only Specific Fields

Code:

pvs -o pv_name,pv_size

Motivation:

There are situations where only particular attributes of physical volumes are of interest, for example, when generating a succinct report or during tasks such as performance benchmarking or capacity planning. Displaying specific fields allows the output to be more focused and manageable, lessening visual clutter.

Explanation:

  • -o: Specifies which fields or columns should be displayed. In this context, pv_name and pv_size indicate the name and size of the physical volume, respectively. This selectiveness provides precise information tailored for specific needs or analyses.

Example Output:

  PV         PSize
  /dev/sda1  100.00g
  /dev/sdb1  500.00g

Append Field to Default Display

Code:

pvs -o +lv_size

Motivation:

Appending a field such as lv_size to the default display is essential for monitoring specific attributes without losing sight of the broader context. It enables administrators to enhance their view with additional yet relevant details, facilitating tasks like volume expansion planning or validation of logical volume distribution.

Explanation:

  • -o +lv_size: This syntax appends the field lv_size to the default list of displayed fields, showing the logical volume size associated with each physical volume.

Example Output:

  PV         VG     Fmt  Attr PSize  PFree  LVSize
  /dev/sda1  vg0    lvm2 a--  100.00g 0     100.00g
  /dev/sdb1  vg1    lvm2 a--  500.00g 100g  400.00g

Suppress Heading Line

Code:

pvs --noheadings

Motivation:

Suppressing the heading line is particularly useful when scripting or programmatically processing the pvs command output. By not including the headings, scripts can directly parse the data without having to skip or handle the extra header row, streamlining automated monitoring or logging workflows.

Explanation:

  • --noheadings: When this option is used, it produces output without column headers, providing a clean list of entries only. It’s suitable for environments where minimalism is preferred or necessary for post-processing.

Example Output:

  /dev/sda1 vg0  lvm2 a--  100.00g 0   
  /dev/sdb1 vg1  lvm2 a--  500.00g 100.00g

Use Separator to Separate Fields

Code:

pvs --separator :

Motivation:

The ability to specify a custom separator is vital when integrating the pvs command into systems that rely on specific data parsing methods, such as CSV files or other structured formats. Adjusting the separator ensures compatibility and consistency with existing data processing pipelines and utilities.

Explanation:

  • --separator :: This option allows the user to define a special character (in this case, :) that will separate fields in the output. It’s helpful when default whitespace separators are insufficient, such as in complex data management systems.

Example Output:

  PV:/dev/sda1  VG:vg0    Fmt:lvm2  Attr:a--  PSize:100.00g  PFree:0   
  PV:/dev/sdb1  VG:vg1    Fmt:lvm2  Attr:a--  PSize:500.00g  PFree:100.00g

Conclusion:

The pvs command is a powerful tool within the Linux environment for those managing logical volumes. By providing diverse options like verbosity, field filtering, customized separators, and more, it equips administrators to efficiently survey and manage the physical storage landscape. Whether you’re performing high-level audits or engaging in detailed configuration reviews, mastering pvs is crucial for any systems professional dealing with Linux storage management.

Tags :

Related Posts

Understanding the `git commit-graph` Command (with examples)

Understanding the `git commit-graph` Command (with examples)

The git commit-graph command is an advanced feature within Git that offers performance enhancements by storing a graph structure of commit history metadata.

Read More
Utilizing the 'md5' Command for File Integrity Verification (with examples)

Utilizing the 'md5' Command for File Integrity Verification (with examples)

The ‘md5’ command is a widely-used tool for generating MD5 (Message-Digest Algorithm 5) cryptographic checksums.

Read More
How to Use the 'blkid' Command (with Examples)

How to Use the 'blkid' Command (with Examples)

The blkid command is a utility in Unix-like operating systems used for listing and identifying block devices.

Read More