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

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

The ‘vgs’ command is used to display information about volume groups in Linux. Volume groups are a way to manage and allocate storage space on a Linux system, allowing for the creation and management of logical volumes. The ‘vgs’ command provides a variety of options to customize the output and display additional details about volume groups.

Use case 1: Display information about volume groups

Code:

vgs

Motivation: This use case is useful when you want to quickly view information about all volume groups on the system.

Explanation: The ‘vgs’ command without any options or arguments simply displays information about volume groups. It provides details such as the volume group name, number of physical volumes, logical volumes, and size of the volume group.

Example output:

VG        #PV #LV #SN Attr   VSize   VFree
vg1         1   2   0 wz--n- 100.00g 20.00g
vg2         2   1   0 wz--n- 200.00g 50.00g

Use case 2: Display all volume groups

Code:

vgs -a

Motivation: This use case is useful when you want to display information about all volume groups, including those that are not active.

Explanation: The ‘-a’ option is used to display all volume groups, including inactive volume groups. By default, only active volume groups are displayed. This option can be helpful when troubleshooting or managing inactive volume groups.

Example output:

VG        #PV #LV #SN Attr   VSize   VFree
vg1         1   2   0 wz--n- 100.00g 20.00g
vg2         2   1   0 wz--n- 200.00g 50.00g
vg3         0   0   0 wz--n-   0       0

Use case 3: Change default display to show more details

Code:

vgs -v

Motivation: This use case is useful when you want to see additional details about the volume groups, such as the physical extent size and number of physical extents.

Explanation: The ‘-v’ option is used to change the default display and show more details about the volume groups. It includes attributes such as physical extent size, total number of physical extents, and number of free physical extents.

Example output:

VG        #PV #LV #SN Attr   VSize   VFree   PE Size PE Count
vg1         1   2   0 wz--n- 100.00g 20.00g 4.00m    25600
vg2         2   1   0 wz--n- 200.00g 50.00g 4.00m    51200

Use case 4: Display only specific fields

Code:

vgs -o VG,Attr,VSize

Motivation: This use case is useful when you only need specific information about the volume groups and want to customize the output.

Explanation: The ‘-o’ option is used to specify the fields that you want to display. You can specify multiple field names separated by commas. In this example, we are displaying the volume group name (VG), attributes (Attr), and the size of the volume group (VSize).

Example output:

VG        Attr   VSize
vg1       wz--n- 100.00g
vg2       wz--n- 200.00g

Use case 5: Append field to default display

Code:

vgs -o +VFree

Motivation: This use case is useful when you want to add an additional field to the default display without removing any existing fields.

Explanation: The ‘-o’ option, when used with the ‘+’ prefix, appends the specified field to the default display. In this example, we are adding the free space of the volume group (VFree) to the default display.

Example output:

VG        #PV #LV #SN Attr   VSize   VFree
vg1         1   2   0 wz--n- 100.00g 20.00g
vg2         2   1   0 wz--n- 200.00g 50.00g

Use case 6: Suppress heading line

Code:

vgs --noheadings

Motivation: This use case is useful when you want to display only the data without the header line, making it easier to parse the output programmatically.

Explanation: The ‘–noheadings’ option is used to suppress the heading line in the output. Only the data is displayed, without any column labels.

Example output:

vg1         1   2   0 wz--n- 100.00g 20.00g
vg2         2   1   0 wz--n- 200.00g 50.00g

Use case 7: Use separator to separate fields

Code:

vgs --separator =

Motivation: This use case is useful when you want to customize the separator used between fields in the output, allowing for easier parsing or formatting.

Explanation: The ‘–separator’ option is used to specify the separator character between fields. In this example, we are using the ‘=’ character as the separator.

Example output:

VG=       #PV=#LV=#SN=Attr=  VSize=   VFree=
vg1         1   2   0 wz--n- 100.00g 20.00g
vg2         2   1   0 wz--n- 200.00g 50.00g

Conclusion:

The ‘vgs’ command is a versatile tool for displaying information about volume groups in Linux. Whether you need a basic overview or detailed information, the various options provided by the ‘vgs’ command allow you to customize the output to suit your needs.

Tags :

Related Posts

How to use the command kpackagetool5 (with examples)

How to use the command kpackagetool5 (with examples)

KPackage Manager is a command-line tool used to install, list, and remove Plasma packages in the KDE Plasma 5 desktop environment.

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

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

Korn Shell (ksh) is a command-line interpreter that is compatible with Bash.

Read More
How to use the command 'git commit' (with examples)

How to use the command 'git commit' (with examples)

The ‘git commit’ command is used to create a new commit, which is a snapshot of the project’s current state.

Read More