Read Logical Volume State Safely with lvs
You will finish with a repeatable way to inspect LVM logical volumes, select useful columns, filter a report, and hand machine-readable output to another tool. The examples use lvs from lvm2 2.03.16(2), installed here as package version 2.03.16-3ubuntu3.2.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need the lvm2 tools and a shell. Most checks are ordinary read-only commands. If the host restricts access to device-mapper or LVM metadata, run the same inspection with sudo only when your operational policy permits it. This guide does not create, resize, activate or remove a logical volume.
1. Check the installed command
Start by confirming which binary is being used and which LVM release supplies it:
$ command -v lvs
/usr/sbin/lvs
$ lvs --version
LVM version: 2.03.16(2) (2022-05-18)
The exact path and build details can differ. The useful checkpoint is that lvs runs and reports the version you are about to document or script against. Its output format and available fields are version-specific, so do not copy a report definition from an unrelated host without checking it.
2. Read the default report
Run lvs with no positional argument to report logical volumes visible to the host:
$ lvs
LV VG Attr LSize
root vg0 -wi-ao---- 40.00g
The rows and values are host-specific. A normal report contains columns such as the LV name, volume group, attributes and size. An empty report can be correct if the host has no visible logical volumes. A warning about permissions, locking or device-mapper is different: it means the command could not perform the full inspection.
Checkpoint: if the command reports an access failure, first establish whether you are allowed to inspect the host as root:
$ sudo lvs
$ printf 'exit status: %s\n' "$?"
exit status: 0
sudo is elevated and may be logged by your system. Do not use it to hide a missing volume or a broken LVM configuration. Read the diagnostic first, and ask the administrator if the machine is shared or managed by another service.
3. Choose stable columns and units
Use -o to name an ordered, comma-separated list of fields. This makes a report easier to review than relying on the default columns:
$ lvs -o lv_full_name,lv_attr,lv_size,lv_path --units g --nosuffix
LV Attr LSize Path
vg0/root -wi-ao---- 40 /dev/vg0/root
lv_full_name keeps the volume group attached to the LV name. lv_attr gives the compact state string, while lv_size and lv_path make the report useful for an operator or a script. The displayed rows are examples, not guaranteed output from your machine.
Lowercase units use powers of 1024 for output. Uppercase units use decimal multiples, so choose deliberately when comparing values with another system. --nosuffix removes the unit suffix and is useful when a parser expects a number, but keep the unit choice documented beside the parser.
Ask the installed command for the complete field list instead of guessing a field name:
$ lvs -o help
Logical Volume Fields
---------------------
lv_name - Name. LVs created for internal use are enclosed in brackets.
lv_full_name - Full name of LV including its VG, namely VG/LV.
Field descriptions and the available list can change between LVM releases. This check is especially useful before deploying a report to several distributions.
4. Filter and sort without changing storage
Use --select to report only objects matching an LVM selection expression. For example, this asks for logical volumes larger than 10 GiB:
$ lvs --select 'lv_size > 10g' -o lv_full_name,lv_size,lv_attr --units g
LV LSize Attr
vg0/root 40.00g -wi-ao----
The result depends on the actual metadata. The selection expression is evaluated by LVM, not by the shell, so quote it. Without quotes, characters used by the expression can be expanded or interpreted before lvs sees them. Use lvs --select help when you need the syntax or a field's selectable form.
Sort explicitly when the order matters. This example puts the largest values first:
$ lvs -O -lv_size -o lv_full_name,lv_size --units g
The leading minus reverses the named sort field. Sorting does not mutate metadata. It only changes the order of the report, so it is safe to use in an inspection script.
5. Produce JSON for a script
For a consumer that should not parse aligned columns, request JSON and keep the field list narrow:
$ lvs --reportformat json \
-o lv_full_name,lv_attr,lv_size,lv_path \
--units g --nosuffix > lvs-report.json
$ test -s lvs-report.json && echo 'report written'
report written
The JSON report contains an LVM report object and an LV array. An empty array is possible when no logical volumes match. Treat warnings on standard error and the exit status as part of the result; do not assume that a file exists merely because redirection created it. For a one-off inspection, omit the redirection and read the report directly.
Use --noheadings for a simple text list, or --separator with a separator that cannot occur in your chosen fields. Those formats are convenient for small shell pipelines, but JSON is usually easier to validate when names or values may contain unexpected whitespace.
6. Understand the attribute string before acting
The attribute column is compact and positional. The first character describes the volume type, the second permissions, and later positions cover allocation policy, fixed minor state, LV state, device-open state, target type, zeroing, health and activation skipping. Do not reduce the whole value to a single test such as "starts with a dash".
For example, an attribute containing p in the health position indicates that one or more physical volumes used by the LV is missing. RAID health characters can indicate a refresh is needed or that mismatches exist. Thin-pool health characters can report failed, out-of-data-space or metadata-read-only conditions. The exact position definitions are documented in the installed lvs manual; use that table when an alert depends on a particular character.
Internal LVs are normally hidden. Add --all when diagnosing a mirror, RAID or pool and you need to see components that are not independently mountable:
$ lvs --all -o lv_full_name,lv_attr,lv_size,lv_role
This reveals more rows; it does not activate or repair anything. Historical LVs need a separate --history request and only appear when LVM history recording was enabled before removal.
7. Use read-only metadata mode for a special case
--readonly is intended for reading on-disk metadata without taking locks, including peeking into metadata used by a running virtual machine image. It does not ask the device-mapper kernel driver whether volumes are in use. That makes it useful for a carefully defined inspection, but it is not a general replacement for normal host checks.
Do not point it at an image or production storage path casually. Confirm the input devices, ownership and maintenance procedure first. If you need to inspect a guest image, preserve the original and follow the virtualisation platform's snapshot or copy procedure. lvs is a reporting command, but the wrong device visibility or locking choice can still produce an incomplete picture.
8. Recover from misleading output
If a known LV is absent, check the volume group and device visibility rather than immediately changing metadata. A devices file, system ID, shared volume group, missing physical volume or locking failure can make a valid LV invisible to one host. Compare the warning text, run lvs --version, and ask the storage owner before using options such as --foreign or --shared.
Avoid --nolocking on a live system. The manual warns that concurrent commands can produce incorrect results. It is not a troubleshooting shortcut. Likewise, --ignorelockingfailure permits read-only metadata operations after locking failures, but it does not make the result complete or safe for an automated decision.
No undo command is needed for the examples in this guide: they report state only and write, activate, resize or remove no LVM object. Delete the generated JSON report with your normal file-clean-up process when it is no longer needed, especially if its contents reveal storage layout.
Done means
- You confirmed the installed lvs version and checked the command's access warnings.
- You can produce a focused report with explicit fields, units and ordering.
- You can filter with a quoted selection expression without changing storage.
- You know when to use JSON, headings or separators for the next consumer.
- You can recognise that
--allexposes internal components and that--historydepends on prior history recording. - You have not used a reporting command as a substitute for investigating missing devices, locks or damaged metadata.