22.3 pvs, vgs, lvs: Displaying LVM Metadata
Right, let’s talk about how you actually see what LVM is doing under the hood. You’ve created these physical volumes, volume groups, and logical volumes, but they’re just abstract concepts until you ask LVM to show them to you. That’s where the holy trinity of pvs, vgs, and lvs comes in. Think of them as your x-ray vision into the LVM layer cake.
These aren’t just random commands; they’re your primary diagnostics, your status board, and your “what on earth did I just do?” verification tool. And here’s the first pro-tip: they all share a common DNA. They’re part of the same family and understand a lot of the same command-line flags, which makes learning them a breeze once you get one.
The Basic, No-Frills View
Run them with no arguments, and you’ll get a polite summary. It’s like asking a busy sysadmin “how’s it going?” – you get the highlights, not the life story.
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 my_vg lvm2 a-- 100.00g 50.00g
/dev/sdc1 my_vg lvm2 a-- 100.00g 100.00g
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
my_vg 2 1 0 wz--n- 200.00g 150.00g
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
my_lv my_vg -wi-a----- 50.00g
This tells you the basics: what physical volumes (pvs) you have and which volume group they’re in, the overall status of your volume groups (vgs), and a list of your logical volumes (lvs). Notice that lvs doesn’t show you where on the disk your LV lives; it’s abstracted that away, which is the whole point.
Making the Commands Spill the Beans
The default view is polite, but you’re not here to be polite. You’re here to get answers. This is where the --options flag (or -o for us lazy typists) comes in. This is the superpower. You can ask for any piece of metadata LVM tracks. Forget memorizing column outputs; just ask for what you want.
Want to see which physical volumes are used by a specific logical volume? lvs can tell you that, but not by default.
$ sudo lvs -o name,vg_name,devices
LV VG Devices
my_lv my_vg /dev/sdb1(0)
Ah, so my_lv is entirely on /dev/sdb1 right now. Good to know. Maybe you’re worried about a disk failing and want to see if any of your LVs are mirrored? Ask for the layout.
$ sudo lvs -o name,segtype,stripes
LV SType #Str
my_lv linear 1
linear means it’s just laid out contiguously. If it said raid1, you’d know it’s mirrored. The stripes count would be relevant if it were a striped volume.
When Things Go Sideways: Decoding the Attributes
The Attr column is the most concise and often most terrifying piece of information. It’s a series of flags that tell you the volume’s state. Let’s decrypt them, because you’ll need to.
For an LV (lvs), -wi-a----- is what you want to see.
- The
ameans it’s active. - The
imeans it’s inherited, which is fine. - The
wmeans it’s writable. - If you see an
oinstead of a-in the first position, that means it’s open (in use by the system). Also fine.
If you see something like -wi-------, that’s also mostly fine. But if you see -wi-ao---- or -wi-a----, that’s… less fine. It might indicate a problem. The real scary one is if the a is missing. That means the volume is not active and won’t be available to the system.
Best Practices and Pitfalls
First, always use sudo. These commands read from the LVM metadata, which often requires root privileges. You might get away with pvs and vgs sometimes, but lvs will frequently complain without elevated rights.
Second, the default views lie by omission. They show you what the LVM designers thought was most common, not what you need for your specific problem. Get comfortable with -o and --options. Use lvs --help to see a list of all available fields—it’s long, and it’s your best friend.
Third, the tools are refreshingly consistent. The flags you learn for lvs work for pvs and vgs. -o for options, --nameprefixes to get output that’s easier to parse in scripts, --separator to change the column delimiter. This isn’t an accident; it’s good design.
Finally, a word on scripting: if you’re piping this output into another command, use --noheadings and --rows. The default output is formatted for human eyes, not awk or cut. For machine parsing, --nameprefixes is a godsend as it prints each field with a name tag.
$ sudo vgs --noheadings --nameprefixes -o vg_name,vg_size
LVM2_VG_NAME='my_vg' LVM2_VG_SIZE='200.00g'
See? Now you can reliably grab LVM2_VG_SIZE without worrying about column positions shifting. You’re welcome.