Logical Volume Management (LVM) is a powerful tool in Linux that allows for flexible and efficient disk management. Understanding how to effectively utilize LVM commands is crucial for system administrators. This article focuses on two key commands, `pvs` and `lvdisplay`, demonstrating how to effectively display physical volumes (PVs) and their relationship with logical volumes (LVs). We'll explore various options and scenarios, providing a comprehensive guide for navigating LVM's intricacies.
1. The `pvs` Command: Unveiling Physical Volumes
The `pvs` command is your primary tool for inspecting physical volumes within your LVM setup. Its default output provides a summary of PVs, including their size, free space, and the volume group (VG) they belong to. However, its power is significantly enhanced with the use of options.
1.1. `pvs -o+devices` : Detailed PV Information
The `-o+devices` option is particularly valuable. It adds the device name to the output, explicitly showing the underlying block device associated with each PV. This is crucial for identifying which physical hard drives or partitions are contributing to your LVM setup. For instance:
[root@server ~]# pvs -o+devices
PV VG Fmt Size Attr PSize PV Name
/dev/sda2 vg0 lvm2 20.00g -w 20.00g /dev/sda2
/dev/sdb1 vg1 lvm2 10.00g -w 10.00g /dev/sdb1
This output clearly indicates that `/dev/sda2` (20GB) and `/dev/sdb1` (10GB) are the physical volumes contributing to volume groups `vg0` and `vg1` respectively. The `PSize` column shows the physical size of the PV.
1.2. Displaying Free Space with `pvs`
The `pvs` command, even without additional options, displays free space within each PV. This is crucial for planning future volume group extensions or creating new PVs. However, understanding *where* that free space resides requires the `-o+devices` option as shown above.
1.3. `pvs` Command Examples in Linux
Let's explore some additional examples:
* `pvs -a`: Displays all PVs, including those that are not currently in use.
* `pvs -v`: Provides a more verbose output, including detailed information about each PV's attributes.
* `pvs --separator=","`: Changes the output separator to a comma, useful for parsing the output with scripting tools.
2. The `lvdisplay` Command: Examining Logical Volumes
While `pvs` focuses on physical volumes, `lvdisplay` provides detailed information about logical volumes (LVs). This command is essential for understanding how space is allocated within your volume groups and how it's utilized by your file systems.
2.1. Basic `lvdisplay` Usage
A simple `lvdisplay` command displays information about all LVs in all VGs:
```bash
[root@server ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lv_root
LV Name lv_root
VG Name vg0
LV UUID ...
LV Write Access read/write
current url:https://prsrxh.e743z.com/bag/lvm-display-pvs-of-lv-48911