Skip to main content
Welcome to our in-depth guide on configuring and managing LVM (Logical Volume Manager) storage in Linux. LVM provides dynamic volume resizing, flexible disk pooling, and snapshot capabilities, making it a powerful tool for system administrators.

What You’ll Learn

  • Installing LVM utilities
  • Key LVM components: PV, VG, LV, PE
  • Creating Physical Volumes (PV)
  • Building and extending Volume Groups (VG)
  • Allocating and resizing Logical Volumes (LV)
  • Formatting and resizing filesystems
  • Common commands and handy tips

Prerequisites

We’ve attached three new 5 GiB virtual disks to our CentOS VM. If you haven’t installed the LVM tools yet, run:
Most LVM operations require root privileges. Prepend sudo or switch to the root user before proceeding.

LVM Abbreviations


1. Creating Physical Volumes (PV)

Physical Volumes are the foundation of LVM. You can use entire disks or partitions.
  1. Scan for available disks and existing PVs:
    Sample output:
  2. Initialize /dev/sdc and /dev/sdd as new PVs:
  3. Verify all PVs:
PFree indicates unallocated space ready for LVs.

2. Building a Volume Group (VG)

Volume Groups aggregate one or more PVs into a single storage pool.
  1. Create a VG named my_volume:
  2. To extend the VG later, initialize another PV:
  3. Add it to my_volume:
  4. List all VGs:

Removing a PV from a VG

  1. Detach /dev/sde:
  2. Wipe its metadata:

3. Allocating Logical Volumes (LV)

Logical Volumes are like partitions within a VG.
  1. Create a 2 GiB LV called partition1:
  2. Create a 6 GiB LV called partition2:
  3. View all LVs:
  4. Check remaining VG space:

4. Resizing Logical Volumes

LVM data is allocated in Physical Extents (PE). You can grow or shrink LVs by adjusting their extents.

Grow to Fill Free Space

Expand partition1 to consume all free extents:

Shrink Back

Reduce partition1 back to 2 GiB:
Shrinking a filesystem without shrinking the filesystem itself first can lead to data loss. Always unmount, run a filesystem check, and resize the filesystem before reducing an LV.

5. Formatting the Filesystem

Before storing data, format your LV. For example, to use XFS:

6. Resizing with an Existing Filesystem

To grow both the LV and its filesystem in one command:
Note: Not all filesystems support online shrinking. Check your filesystem’s documentation.

7. Handy Tips & Resources

  • Browse the full LVM manual:
  • Use tab-completion to explore subcommands:
  • Always back up critical data before performing volume operations.

Watch Video