How to use the command pvs (with examples)

How to use the command pvs (with examples)

The pvs command is used to display information about physical volumes in a Linux system. Physical volumes are disk partitions or whole disks that are used as the building blocks for creating logical volume management (LVM) volumes.

Use case 1: Display information about physical volumes

Code:

pvs

Motivation: This use case is helpful when you want to gather information about the physical volumes in your system, such as name, space usage, and allocation policy.

Explanation: The pvs command without any options or arguments displays information about all physical volumes in the system. It shows details like Physical Volume (PV) name, Volume Group (VG), total size, free size, and physical extents.

Example output:

  PV         VG    Fmt  Attr PSize    PFree   
  /dev/sda1  vg01  lvm2 a--  100.00g   20.00g  
  /dev/sdb1  vg02  lvm2 a--  200.00g   80.00g

Use case 2: Display non-physical volumes

Code:

pvs -a

Motivation: Sometimes you might want to display all volumes, including those used for special purposes like snapshots or metadata.

Explanation: By adding the -a option to the pvs command, you can display all volumes, including non-physical volumes.

Example output:

  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda1  vg01   lvm2 a--  100.00g   20.00g  
  /dev/sdb1  vg02   lvm2 a--  200.00g   80.00g
  /dev/sdc1         lvm2 ----  100.00g -------

Use case 3: Change default display to show more details

Code:

pvs -v

Motivation: You may need more detailed information about the physical volumes, such as physical extent size and allocation policy.

Explanation: The -v option modifies the default display of the pvs command to show additional information. It includes the physical extent size and allocation policy for each physical volume.

Example output:

  PV         VG    Fmt  Attr PSize    PFree    PE Size Alloc 
  /dev/sda1  vg01  lvm2 a--  100.00g   20.00g   4.00m  cont 
  /dev/sdb1  vg02  lvm2 a--  200.00g   80.00g   4.00m  cont 

Use case 4: Display only specific fields

Code:

pvs -o pv_name,pv_size

Motivation: Sometimes you only need specific information about the physical volumes, such as the name and size.

Explanation: The -o option allows you to specify the fields to display. You can provide comma-separated field names as arguments to the -o option. In this case, we are specifying the pv_name and pv_size fields.

Example output:

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

Use case 5: Append field to default display

Code:

pvs -o +pv_uuid

Motivation: You may want to add additional information, such as the unique identifier of each physical volume.

Explanation: The -o option with the + prefix allows you to append a field to the default set of fields displayed by pvs. In this example, we are adding the pv_uuid field to the default display.

Example output:

  PV         VG    Fmt  Attr PSize    PFree    PV UUID                  
  /dev/sda1  vg01  lvm2 a--  100.00g   20.00g   AbCdEf-GhIjKl            
  /dev/sdb1  vg02  lvm2 a--  200.00g   80.00g   MnOpQr-StUvWx            

Use case 6: Suppress heading line

Code:

pvs --noheadings

Motivation: In some cases, you may not want the heading line to be displayed, especially when scripting or processing the command’s output.

Explanation: The --noheadings option suppresses the heading line in the output of the pvs command.

Example output:

   /dev/sda1  vg01  lvm2 a--  100.00g   20.00g  
   /dev/sdb1  vg02  lvm2 a--  200.00g   80.00g  

Use case 7: Use separator to separate fields

Code:

pvs --separator ,

Motivation: You may want to use a custom separator character, such as a comma, to separate the fields when parsing the output of the pvs command.

Explanation: The --separator option allows you to specify a custom separator character for the output. In this example, we use a comma as the separator.

Example output:

  PV,         VG,    Fmt,  Attr, PSize,    PFree   
  /dev/sda1,  vg01,  lvm2, a--,  100.00g,   20.00g  
  /dev/sdb1,  vg02,  lvm2, a--,  200.00g,   80.00g

Conclusion:

The pvs command provides a convenient way to display information about physical volumes in a Linux system. By using different options, you can customize the output to suit your needs, including showing additional details, selecting specific fields, and modifying the display format.

Tags :

Related Posts

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

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

The sdiff command is used to compare the differences between two files and optionally merge them.

Read More
How to use the command "ppmspread" (with examples)

How to use the command "ppmspread" (with examples)

The “ppmspread” command is used to displace the pixels in a PPM image by a randomized amount.

Read More