zaro

What is VG and LV?

Published in Logical Volume Management 3 mins read

VG and LV are core concepts in Linux Logical Volume Management (LVM), used for flexible disk space management. They represent fundamental components in creating and managing logical volumes.

According to the reference, a Volume Group (VG) is a collection of one or more physical devices, each called a Physical Volume (PV). A Logical Volume (LV) is a virtual block device that can be used by the system or applications.

To better understand this, let's break down the relationship:

Term Definition Analogy
Physical Volume (PV) A physical storage device, like a hard drive or SSD, that has been initialized for use with LVM. Individual bricks.
Volume Group (VG) A container that groups together one or more PVs. It acts as a pool of storage. A wall built from those bricks.
Logical Volume (LV) A virtual partition created within a VG. This is the "disk" that the operating system sees. A shelf within the wall; you can organize your books (data) on this shelf.

Key Concepts Explained:

  • Physical Volume (PV): Before you can use a physical storage device in LVM, you must mark it as a PV. This is usually done with the pvcreate command.

  • Volume Group (VG): Once you have PVs, you can combine them into a VG. The VG represents the total amount of storage available. This is done using the vgcreate command.

  • Logical Volume (LV): From the VG, you can create LVs. Each LV behaves like a partition, allowing you to format it with a filesystem (like ext4 or XFS) and mount it. LVs are created with the lvcreate command.

Practical Insights:

  • Resizing Flexibility: One of the biggest advantages of LVM is the ability to resize LVs easily. You can add space to an LV from the VG if needed, or even shrink it (although shrinking requires caution to avoid data loss).

  • Snapshots: LVM allows you to create snapshots of LVs. A snapshot is a read-only copy of the LV at a specific point in time, useful for backups or testing.

  • Striping and Mirroring: LVM supports striping (spreading data across multiple PVs for performance) and mirroring (creating redundant copies of data for fault tolerance).

Example Scenario:

Imagine you have two physical hard drives /dev/sda and /dev/sdb.

  1. You create PVs from them:

    pvcreate /dev/sda
    pvcreate /dev/sdb
  2. You combine them into a VG named "myvg":

    vgcreate myvg /dev/sda /dev/sdb
  3. Now, you can create an LV named "mylv" of 100GB within "myvg":

    lvcreate -L 100G -n mylv myvg
  4. Finally, you format and mount the LV:

    mkfs.ext4 /dev/myvg/mylv
    mount /dev/myvg/mylv /mnt/mydisk

You now have a 100GB filesystem residing on an LV, which is part of a VG composed of two physical disks.