Tuesday, July 28, 2020

All about Logical Volume Management (LVM) (PV, VG,LV)

Logical Volume Management (LVM) Explained

Logical Volume Management (LVM) introduces a flexible layer of abstraction over physical storage devices in Linux. This abstraction allows for dynamic management of storage volumes, making it easier to resize, move, and manage disk space without necessarily stopping applications or unmounting file systems. LVM hides the underlying physical disk sizes from the software, providing greater agility in storage administration.

LVM Components

LVM is built upon three core components:

  • Physical Volume (PV):

    • A PV is a raw block device, which can be an entire hard disk (e.g., /dev/sdb) or a partition of a disk (e.g., /dev/sda2).

    • PVs are the foundational building blocks of LVM.

  • Volume Group (VG):

    • A VG is a collection of one or more Physical Volumes (PVs).

    • It acts as a container for Logical Volumes, pooling the storage capacity of its constituent PVs.

  • Logical Volume (LV):

    • An LV represents a portion of a Volume Group (VG).

    • It is the equivalent of a traditional disk partition but with the added flexibility of LVM.

    • A Logical Volume can only belong to one Volume Group.

    • It is on a Logical Volume that you create a file system (e.g., ext4, XFS) and mount it for use by the operating system and applications.

LVM Commands and Examples

Here are common LVM commands and their output examples, demonstrating how to inspect your LVM setup:

Physical Volumes (PVs)

  • pvs (or pvdisplay, pvscan): Displays information about Physical Volumes.

    PV          VG                 Fmt  Attr PSize    PFree
    /dev/sda2   osvg               lvm2 a--  <59.00g      0
    /dev/sdb    oracle_application lvm2 a--  <330.00g <25.00g
    
    • /dev/sda2 is a PV belonging to the osvg Volume Group, with no free space.

    • /dev/sdb is a PV belonging to the oracle_application Volume Group, with 25.00GB of free space.

Volume Groups (VGs)

  • vgs (or vgdisplay, vgscan): Displays information about Volume Groups.

    VG                 #PV #LV #SN Attr   VSize    VFree
    oracle_application   1   4   0 wz--n- <330.00g <25.00g
    osvg                 1   5   0 wz--n-  <59.00g      0
    
    • oracle_application VG has 1 PV, 4 LVs, a total size of <330.00GB, and <25.00GB free.

    • osvg VG has 1 PV, 5 LVs, a total size of <59.00GB, and 0GB free.

Logical Volumes (LVs)

  • lvs (or lvdisplay, lvscan): Displays information about Logical Volumes.

    LV          VG                 Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
    app         oracle_application -wi-ao----   5.00g
    gridinfra   oracle_application -wi-ao---- 100.00g
    oracle      oracle_application -wi-ao---- 100.00g
    orasoftware oracle_application -wi-ao---- 100.00g
    homelv      osvg               -wi-ao----   4.00g
    rootlv      osvg               -wi-ao----  19.00g
    swaplv      osvg               -wi-ao---- <16.00g
    tmplv       osvg               -wi-ao----  12.00g
    varlv       osvg               -wi-ao----   8.00g
    
    • This output shows various Logical Volumes, their corresponding Volume Groups, and their allocated sizes.

Basic LVM Creation Commands

Here are the fundamental commands for creating LVM components:

  • Create a Physical Volume (PV):

    pvcreate /dev/sdb
    # To create multiple PVs:
    pvcreate /dev/sdb /dev/sdc
    
  • Create a Volume Group (VG):

    vgcreate oracle_application /dev/sdb
    # To create a VG from multiple PVs:
    vgcreate oracle_application /dev/sdb /dev/sdc
    
  • Create a Logical Volume (LV):

    lvcreate -L 5G -n app oracle_application
    # This creates a 5GB Logical Volume named 'app' within the 'oracle_application' Volume Group.
    

No comments:

Post a Comment