Home / Alt manpages / pvs(8)

  • pvs(8)
  • Admin command
  • linux

Read LVM Physical Volumes Reliably with pvs

pvs prints the physical volumes LVM can see, and picking the right columns turns a wall of text into something you can script against. 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: a Linux host with lvm2 installed, and access to the block devices and LVM metadata.
  • Start without sudo. Most reporting commands are ordinary, read-only operations, but device permissions, container restrictions, or the host's LVM configuration can make elevated access necessary. Add sudo only if the command reports it cannot inspect the devices.

1. Check the tool and its version

Confirm which implementation you are using first. The exact fields and reporting behaviour 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 meant 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. 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 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.

  • Rerun with --readonly and check the exit status.
  • Check 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 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.

Warning

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 talking to 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

  • Version identified: pvs --version confirmed the installed LVM tools.
  • Empty versus failed: you can tell an empty successful report from a command failure.
  • Fields named explicitly: your report uses --options rather than relying on column position.
  • Units chosen deliberately: you picked units on purpose, and used --nosuffix only when appropriate.
  • Program-friendly output understood: you can use JSON for program input and know device filters can hide PVs.
  • No destructive shortcuts: you have not used a destructive LVM command merely to test visibility.