Home / Alt manpages / pvs(8)

  • pvs(8)
  • Admin command
  • linux

Read LVM Physical Volumes Reliably with pvs

By the end, you will be able to inspect LVM physical volumes, select the columns you actually need, and produce output that is safe to feed to another command. The examples use the installed LVM 2.03.16(2) tools from the lvm2 package. Allow about ten minutes if LVM is already installed and you only need to read metadata.

Prerequisites: run these commands on a Linux host with lvm2 installed. You need access to the block devices and LVM metadata. Most reporting commands are ordinary, read-only operations, but device permissions, container restrictions, or the host's LVM configuration can make elevated access necessary. Start without sudo; add it only if the command reports that it cannot inspect the devices.

1. Check the tool and its version

First confirm which implementation you are using. The exact fields and reporting behaviour discussed here come from LVM tools 2.03.16(2), released with the local manpage dated 18 May 2022.

pvs --version

On this machine, the useful part of the result is:

LVM version:     2.03.16(2) (2022-05-18)
Library version: 1.02.185 (2022-05-18)

The command may print a warning about running as a non-root user. That warning is about what the current process can access, not proof that pvs changes anything.

2. Get the normal physical-volume report

Run pvs with no positional arguments to report the physical volumes visible to LVM.

pvs

The usual table has columns such as the physical-volume name, volume group, format, attributes, size and free space. The exact default columns are controlled by LVM's reporting configuration, so scripts should not parse this display by position. On a host with no visible PVs, a successful run can produce no rows at all. Check the exit status separately if an empty report matters:

if pvs --readonly; then
    echo "pvs completed"
else
    echo "pvs could not inspect the configured devices" >&2
fi

Checkpoint

You should now know whether the host has visible PVs, or whether the report is empty because there are none, because the devices are filtered, or because permissions prevented discovery.

3. Ask for stable, useful columns

Use --options, or -o, with a comma-separated list of fields. This example asks for the device name and the two capacity values most often needed when checking space:

pvs --readonly \
    --options pv_name,pv_size,pv_free \
    --units g

The output units deserve attention. Lower-case g means a human-readable value based on powers of 1024, while upper-case G uses powers of 1000. The manpage also supports bytes, sectors, kilobytes, megabytes, terabytes, petabytes and exabytes. For a machine-readable numeric report, choose a unit and suppress its suffix:

pvs --readonly \
    --options pv_name,pv_size,pv_free \
    --units b --nosuffix

--nosuffix is intended for use with --units, except the human-readable unit modes. Do not silently compare values from two reports if one uses binary units and the other uses SI units.

To see the fields supported by this installed version, ask the command itself:

pvs --options help

This prints the available reporting fields. Names such as pv_name, pv_size, pv_free and pv_attr are fields, not guaranteed column positions in the default display.

4. Make output safe for a shell pipeline

For a simple line-oriented report, remove headings and choose a separator that cannot be mistaken for whitespace. This is useful for a small administrative script, although JSON is usually a better boundary between programs.

pvs --readonly \
    --noheadings \
    --separator '|' \
    --options pv_name,pv_size,pv_free \
    --units b --nosuffix

--noheadings removes the heading line. The separator applies between columns, but it does not turn the command into a general-purpose CSV writer. Treat the fields as LVM report data, and do not assume that every future field value is free of your chosen separator.

For an interface consumed by a program, request JSON instead:

pvs --readonly \
    --reportformat json \
    --options pv_name,pv_size,pv_free

On this host, with no visible physical volumes, that command succeeds and returns an empty report array:

{
    "report": [
        {
            "pv": []
        }
    ]
}

5. Investigate an unexpected empty report

An empty result is not the same as a failed command. First rerun with --readonly and check the exit status. Then check whether LVM has been told to restrict device visibility. The --devices option can limit a command to named devices, and a devices file under /etc/lvm/devices/ can also affect what LVM sees.

For a diagnostic comparison, ask LVM to inspect an explicitly named device that you have already confirmed is the intended storage device:

sudo pvs --readonly --devices /dev/EXAMPLE \
    --options pv_name,pv_size,pv_free

Replace /dev/EXAMPLE with a real device path. This command only reports metadata. Do not substitute a guessed disk, and do not use pvcreate, pvremove, vgcreate or any other state-changing command as a test. Those commands can overwrite metadata or make storage unavailable.

If you need to inspect on-disk metadata without taking normal LVM locks, --readonly is the relevant mode in this version. It avoids communication with the device-mapper kernel driver, so it cannot tell you whether logical volumes are currently in use. That makes it useful for a cautious metadata view, not a complete live-storage health check.

Done means

  • pvs --version identified the installed LVM tools.
  • You can distinguish an empty successful report from a command failure.
  • Your report names fields explicitly with --options.
  • You chose units deliberately, and used --nosuffix only when appropriate.
  • You can use JSON for program input and understand that device filters can hide PVs.
  • You have not used a destructive LVM command merely to test visibility.