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

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

The ’lvs’ command is used to display information about logical volumes. Logical volumes are a way of dividing physical disk space into multiple virtual disks, making it easier to manage and allocate storage. The ’lvs’ command provides various options to customize the display of logical volume information.

Use case 1: Display information about logical volumes

Code:

lvs

Motivation: The motivation for using this command is to get a brief overview of the logical volumes present on the system. This can be useful to check if the logical volumes are properly configured and to get an overall picture of the storage allocation.

Explanation: This is the basic usage of the ’lvs’ command without any additional options. It displays information about all the logical volumes present on the system.

Example Output:

LV          VG        Attr       LSize    Origin Snap%  Move Log Copy%  Convert
root        cl        -wi-ao----   40.00g                                 
swap        cl        -wi-ao----    2.00g                                 

Use case 2: Display all logical volumes

Code:

lvs -a

Motivation: This command is helpful if you want to show all logical volumes, including those that are currently not active or hidden. This can be useful when troubleshooting or when you need a comprehensive list of all logical volumes.

Explanation: The ‘-a’ option is used to display all logical volumes, including hidden and inactive volumes.

Example Output:

LV              VG       Attr       LSize    Origin  Snap%  Move Log     Copy%
root            cl       -wi-ao----   40.00g
swap            cl       -wi-ao----    2.00g
hidden_volume   cl       vwi-a-----   10.00g root    0.00

Use case 3: Change default display to show more details

Code:

lvs -v

Motivation: When you require more detailed information about the logical volumes, using the ‘-v’ option can provide additional details such as the origin of the volume and its related parameters.

Explanation: The ‘-v’ option stands for “verbose” and it changes the default display to show more detailed information about the logical volumes, including the volume name, volume group, attributes, size, origin (if any), snapshot percentage, move parameters, log settings, and copy percentage.

Example Output:

  LV       VG    #PV #LV #SN Attr   VSize VOrigin  VSnap%  Move Log  Copy%
  root     cl    1   1   0 -wi-ao 40.00g                           
  swap     cl    1   1   0 -wi-ao  2.00g      

Use case 4: Display only specific fields

Code:

lvs -o field_name_1,field_name_2

Motivation: Sometimes you may only be interested in specific fields of the logical volume information. In such cases, using the ‘-o’ option with the desired field names can help to narrow down the output and provide only the required information.

Explanation: The ‘-o’ option is used to specify the fields to be displayed. It allows you to customize the output by selecting specific fields according to your needs. Separate multiple field names with commas.

Example Output:

LV      Attr
root    -wi-ao----
swap    -wi-ao----

Use case 5: Append field to default display

Code:

lvs -o +field_name

Motivation: If you want to add an additional field to the default display, this option helps to append the desired field to the existing output.

Explanation: The ‘-o’ option with the ‘+field_name’ argument allows you to append an additional field to the default display. This is useful when you want to include an extra field without removing any existing fields.

Example Output:

LV      Attr  Size
root    -wi-ao---- 40.00g
swap    -wi-ao---- 2.00g

Use case 6: Suppress heading line

Code:

lvs --noheadings

Motivation: In some cases, you may want to remove the heading line from the output of the ’lvs’ command. This can be useful if you are scripting and want to process the output without the column headings.

Explanation: The ‘–noheadings’ option is used to suppress the heading line that displays the names of the columns in the output. This results in only the data being displayed without any column names.

Example Output:

root    cl  -wi-ao---- 40.00g
swap    cl  -wi-ao---- 2.00g

Use case 7: Use a separator to separate fields

Code:

lvs --separator =

Motivation: By default, the fields in the output of the ’lvs’ command are separated by spaces. However, there may be cases where you want to use a different separator character between fields. This option allows you to specify a custom separator.

Explanation: The ‘–separator’ option is used to specify the separator character to be used between fields in the output. In this case, ‘=’ is provided as the separator character.

Example Output:

LV======Attr========LSize===Origin===Snap%===Move===Log===Copy%===Convert
root====-wi-ao----===40.00g============================
swap====-wi-ao----===2.00g============================

Conclusion:

The ’lvs’ command is a powerful tool for displaying information about logical volumes on a Linux system. By using the various options provided with the command, you can customize the output to suit your specific needs. Whether you want a brief overview of the logical volumes, need more detailed information, or want to filter the displayed fields, the ’lvs’ command offers flexibility and control over the information displayed.

Tags :

Related Posts

How to use the command `elm` (with examples)

How to use the command `elm` (with examples)

Elm is a functional programming language that compiles to JavaScript and is used for web development.

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

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

The “dirname” command is a useful tool for calculating the parent directory of a given file or directory path.

Read More
How to use the command 'hg clone' (with examples)

How to use the command 'hg clone' (with examples)

Mercurial is a distributed version control system that provides a command-line tool called ‘hg clone’, which is used to create a copy of an existing repository in a new directory.

Read More