Exploring LVM: Learn About Common PV, LV, and VG Attributes

|
Published:
|
|
Exploring LVM: Learn About Common PV, LV, and VG Attributes

LVM (Logical Volume Management) is a powerful tool for managing storage in Linux. It gives you the flexibility to easily resize, merge, and create storage volumes as needed. To effectively use LVM, it’s important to understand the key attributes of its components: Physical Volumes (PV), Logical Volumes (LV), and Volume Groups (VG). This guide will explore these attributes to enable you to efficiently manage your storage.

Exploring LVM: Learn About Common PV, LV, and VG Attributes (LVM Attributes)

What is LVM and Why Use it?

LVM is a method of managing disk storage in a way that abstracts the physical disks (or partitions) into logical volumes, offering flexibility over traditional partitioning. Instead of dealing with individual drives as separate entities, LVM lets you:

  • Move data between drives: Shift data seamlessly between different drives within the pool.
  • Combine drives: Group multiple drives together into a single, larger pool of storage.
  • Resize storage: Easily expand or shrink the size of your storage space without complex repartitioning.

There are three core components of LVM:

  • Physical Volumes (PVs): These are your individual hard drives or partitions.
  • Volume Groups (VGs): You combine one or more PVs to create a VG, essentially pooling their storage capacity.
  • Logical Volumes (LVs): These are the actual storage spaces you use (like where your files are stored). You create LVs within a VG, and they can span multiple drives.

Why use LVM? LVM offers:

  • Flexibility: Easily resize your storage as your needs change.
  • Efficiency: Combine multiple drives for a larger storage pool.
  • Simplified management: Makes it easier to add, remove, and replace drives.

In essence, LVM provides a more powerful and flexible way to manage your storage compared to traditional methods.

Understanding Physical Volume (PV) Attributes

When you run the pvs command, there are multiple headers displaying various information about the Physical Volumes from the command output.

sudo pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/vda3  ubuntu-vg lvm2 a--  <23.00g    0
  • PV: This indicates the device name of the physical volume.
  • VG: This shows the name of the Volume Group that this PV belongs to.
  • Fmt: This specifies the format of the PV, which is LVM2 in this case.
  • Attr: This is the attribute field showing the PV attributes which provides information about the PV's status
  • PSize: This represents the total size of the PV. The < symbol indicates that the actual size may be slightly less than the displayed size.
  • PFree: As per the output here, this indicates that the entire PV is currently being used by the Volume Group. There is no free space available within this PV.

The Attr field is made up of three bits showing the possible status of the physical volume.

  1. Bit 1 can show three possible states of a Physical Volume:
    • (d)uplicate: This flag indicates whether the physical volume is duplicated or part of a redundant setup. In most LVM configurations, this flag will not be set unless the PV is part of a clustered environment or has been configured for mirroring or other redundant storage.
    • (a)llocatable: Allocatable indicates whether the PV is used to store data. A PV is allocatable if it is already used to create a VG. This attribute will show a or YES (if using pvdisplay command) .If the PV is not a member of a VG yet, it cannot not be used and hence, this will attribute will show as - or "NO" (when using pvdisplay command).
    • (u)sed: "u" (Used) usually implies "a": If a PV is being used by the Volume Group (i.e., has space allocated to LVs), it's generally also considered active.
  2. Bit 2 shows whether the Physical Volume is e(x)ported or not (-). If this flag is set (x), it basically means that the Volume Group created on the Physical Volume has been exported. Exporting a PV makes it unavailable for use in the current system.
  3. Bit 3 shows whether the Physical Volume is available and visible to the LVM (-) or it is (m)issing and not visible to the LVM. A "missing" PV typically means that the physical device backing the PV is unavailable, such as when the disk has been removed or is offline. In this state, the PV is no longer accessible, and you would need to resolve the issue (e.g., reconnecting the device or replacing a failed disk).

Understanding Volume Group (VG) Attributes

A Volume Group (VG) is a pool of storage created by combining multiple Physical Volumes (PVs). It provides the storage space from which Logical Volumes (LVs) are created.

You can use vgs or vgdisplay command get details about the volume groups.

sudo vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  myvg        2   0   0 wzx-n-   9.99g 9.99g
  ubuntu-vg   1   1   0 wz--n- <23.00g    0 
  • VG gives the name of the volume group.
  • #PV shows how many physical volumes are part of the VG.
  • #LV tells you how many logical volumes exist in the VG.
  • #SN indicates how many snapshots exist in the VG.
  • Attr shows various attributes of the Volume Group, using flags that indicate certain properties or states.
  • VSize shows the total size of the VG.
  • VFree shows the available (unused) space within the VG.

There are 6 Volume Group attributes bits each displaying various state of the VG. These attribute bits include:

  1. Permissions:
    • Can either be (w)riteable, (r)ead-only.
    • w (Writeable): This is the normal state for most Volume Groups. It means you can create, resize, and delete Logical Volumes (LVs) within the VG, and you can write data to those LVs.
    • r (Read-only): This state prevents any modifications to the VG or its LVs. You can still read data from existing LVs, but you cannot create new LVs, resize existing ones, or write new data. This is useful for maintenance, backups, or preventing accidental changes.
  2. Resi(z)eable:
    • z (Resizeable): This indicates that the VG can be resized by adding or removing Physical Volumes (PVs). This is a key feature of LVM, allowing you to dynamically expand or shrink your storage pool as needed.
    • - (Not Resizeable): This is less common. It means the VG cannot be resized. This might be due to specific configurations or limitations, but it's generally not the default behavior.
  3. E(x)ported:
    • x (Exported): A VG in an exported state ensures that the VG and its disks are not being used, and cannot be used until the VG is imported. Putting a VG into an unusable, offline state can be useful when doing things like moving a VG's disks to another system. Exporting a VG provides some protection from its LVs being accidentally used, or being used by an automated system before it's ready.
    • - (Not Exported): This is the standard state for single-machine LVM setups. The VG is only accessible on the local machine.
  4. (p)artial:
    • p (Partial): This is a critical indicator of a problem. It signifies that one or more PVs that were originally part of the VG are no longer available to the system. This could be due to a drive failure, disconnection, or other hardware or software issues. This is the flag you're likely seeing in your current situation and is the cause of the "Couldn't find device" warnings.
    • - (Not Partial): This is the normal state. It means all PVs that belong to the VG are present and accessible.
  5. Allocation policy: This describes how LVM allocates Physical Extents (PEs) to Logical Extents (LEs) when creating or extending LVs.
    • (c)ontiguous: The policy requires that the physical location of any logical extent is adjacent to the physical location of the immediately preceding logical extent, with the exception of the first logical extent of a LV.
    • c(l)ing: This policy ensures that a new logical extent is allocated to the same physical volume (PV) as an existing logical extent that is part of the same LV, specifically one that was allocated earlier in the LV.
    • (n)ormal: The normal policy attempts to allocate physical extents (PEs) in a way that avoids using the same PV for parallel logical volumes (e.g., for striped or mirrored LVs) at the same offset.
    • (a)nywhere: LVM can allocate PEs from any available PV, regardless of their physical location.
  6. (c)lustered, (s)hared:
    • c (Clustered): This indicates that the VG is part of a clustered LVM setup, allowing multiple machines to access and manage the same storage.
    • s (Shared): This is similar to clustered, indicating the VG is shared amongst multiple systems. There can be subtle differences in how locking and metadata updates are handled between clustered and shared, but the general concept is the same.
    • - (Not Clustered/Shared): This is the standard state for single-machine LVM setups.

Understanding Logical Volume (LV) Attributes

A Logical Volume (LV) is a virtual storage device created from a Volume Group (VG). Logical volumes are the equivalent of partitions or file systems in a traditional disk partitioning scheme.

You can display information about Logical Volumes using lvs or lvdisplay commands.

sudo lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <23.00g

The headers displayed:

  • LV (Logical Volume): The name of the logical volume.
  • VG (Volume Group): The name of the volume group to which the logical volume belongs.
  • Attr (Attributes): Flags indicating the state and configuration of the LV (e.g., writable, active, allocated, snapshot).
  • LSize (Logical Size): The total size of the logical volume.
  • Pool: The name of the thin pool if the LV is part of a thin provisioning setup.
  • Origin: The original volume if the LV is a snapshot (empty if not a snapshot).
  • Data%: The percentage of the LV’s space that is used by data.
  • Meta%: The percentage of space used by metadata (for thin provisioning).
  • Move: Indicates if the LV is in the process of being moved (e.g., using pvmove).
  • Log: Indicates if the LV has a log (used in certain configurations like RAID).
  • Cpy%Sync: Shows the synchronization percentage for mirrored or RAID volumes.
  • Convert: Indicates if the LV is undergoing a conversion (e.g., from one type to another).

Here is summary of Logical Volume Attributes bits;

1. Volume Type:

  • (C): Cache
  • (m): Mirrored
  • (M): Mirrored without initial sync
  • (o): Origin (the source of a snapshot)
  • (O): Origin with merging snapshot
  • (g): Integrity (refers to integrity check functionality)
  • (r): RAID
  • (R): RAID without initial sync
  • (s): Snapshot
  • (S): Merging Snapshot
  • (p): pvmove (migration of data between physical volumes)
  • (v): Virtual volume
  • (i): Mirror or RAID image
  • (I): Mirror or RAID image out-of-sync
  • (l): Mirror log device
  • (c): Under conversion (e.g., between formats or states)
  • (V): Thin volume
  • (T): Thin pool
  • (t): Thin pool data
  • (D): Do pool (data) or Do pool metadata
  • (e): RAID or pool metadata
  • (m): Pool metadata spare

2. Permissions:

  • (w): Writable
  • (r): Read-only
  • (R): Read-only activation of non-read-only volume

3. Allocation Policy:

  • (a): Anywhere
  • (c): Contiguous
  • (i): Inherited
  • (l): Cling
  • (n): Normal

4. Fixed Minor:

  • (m): Fixed minor number assigned

5. State:

  • (a): Active
  • (h): Historical
  • (s): Suspended
  • (I): Invalid snapshot
  • (S): Invalid suspended snapshot
  • (m): Snapshot merge failed
  • (M): Suspended snapshot merge failed
  • (d): Mapped device present without tables
  • (i): Mapped device present with inactive table
  • (c): Thin-pool check needed
  • (C): Suspended thin-pool check needed
  • (X): Unknown

6. Device Open:

  • (o): Device is open/Mounted
  • (X): Unknown state

7. Target Type:

  • (C): Cache
  • (m): Mirror
  • (r): RAID
  • (s): Snapshot
  • (t): Thin volume
  • (u): Unknown
  • (v): Virtual

8. Zeroed Blocks:

  • (z): Newly-allocated data blocks are overwritten with zeros before use.

9. Volume Health:

  • Common:
    • (p): Partial (some physical volumes are missing)
    • (X): Unknown health status
  • RAID:
    • (r): Refresh needed (write errors occurred)
    • (m): Mismatches exist (inconsistencies in the RAID array)
    • (w): Write-mostly (RAID devices marked as write-mostly)
  • Reshaping:
    • (s): Reshaping (undergoing stripe changes or RAID algorithm modifications)
    • (R): Remove after reshape (images freed during reshaping)

10. Skip Activation:

  • (k): Skip activation (the volume is flagged to be skipped during activation)

Conclusion

Understanding the attributes of Physical Volumes (PVs), Logical Volumes (LVs), and Volume Groups (VGs) is essential for anyone working with LVM in Linux. These attributes tell you a lot about your storage – its health, how it's configured, and how it's being used.

By learning to read these attributes, you can:

  • Manage your storage effectively: Resize volumes, handle storage issues, and optimize performance.
  • Make informed decisions: Choose the best way to allocate and manage your storage.
  • Troubleshoot with confidence: Quickly identify and resolve storage-related problems.

The best way to learn is by doing. Experiment with LVM commands in a safe test environment to get hands-on experience. This will help you understand how these attributes work in real-world situations.

With this knowledge, you'll be a storage management pro! Happy learning and experimenting!

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment