LinuxCommandLibrary

lvm

Manage logical volumes

TLDR

Start the Logical Volume Manager interactive shell

$ sudo lvm
copy

Initialize a drive or partition to be used as a physical volume
$ sudo lvm pvcreate [/dev/sdXY]
copy

Display information about physical volumes
$ sudo lvm pvdisplay
copy

Create a volume group called vg1 from the physical volume on /dev/sdXY
$ sudo lvm vgcreate [vg1] [/dev/sdXY]
copy

Display information about volume groups
$ sudo lvm vgdisplay
copy

Create a logical volume with size 10G from volume group vg1
$ sudo lvm lvcreate [[-L|--size]] [10G] [vg1]
copy

Display information about logical volumes
$ sudo lvm lvdisplay
copy

Display help for a specific command
$ lvm help [command]
copy

SYNOPSIS

The `lvm` command acts as a front-end for the entire LVM suite, dispatching to various subcommands:
lvm [--commandoptions] [--options] [--arg] [...] command [command_options] [command_args]
Or for an interactive shell:
lvm
Or to list all available commands:
lvm help

PARAMETERS

--help | -h
    Displays help information for the lvm command itself or a specific subcommand if provided.

--version | -V
    Displays the LVM version and basic build information.

--debug | -d
    Enables verbose debugging output, useful for troubleshooting LVM operations.

--yes | -y
    Assumes 'yes' to all confirmation prompts, proceeding with operations without user interaction. Use with caution.

--nolocking
    Disables LVM's internal locking mechanism. Use with extreme caution as it can lead to data corruption if multiple LVM processes run concurrently.

--config
    Uses the specified configuration file or applies configuration values directly from the command line, overriding default settings.

--readonly | -r
    Executes the command in a read-only mode, preventing any modifications to LVM metadata or data. Useful for inspection.

--quiet | -q
    Suppresses output messages, making the command suitable for scripting where only errors or specific outputs are desired.

DESCRIPTION

LVM (Logical Volume Manager) is a powerful storage management solution for Linux and other Unix-like systems. It provides an abstraction layer over physical storage devices, allowing for flexible and dynamic management of disk space. Instead of directly working with physical partitions, LVM introduces concepts of Physical Volumes (PVs), Volume Groups (VGs), and Logical Volumes (LVs). PVs are physical disk partitions or entire disks initialized for LVM. VGs are collections of one or more PVs, pooling their storage capacity. LVs are virtual partitions created from the aggregated space of a VG.

This layered approach enables features like online resizing of LVs, creating snapshots, striping data across multiple disks, and mirroring for redundancy, all without unmounting or reformatting file systems in many cases. LVM simplifies tasks such as adding new disks, migrating data, and adapting storage to changing needs, offering greater flexibility than traditional disk partitioning.

CAVEATS

LVM operations, especially those involving resizing, creating, or deleting volumes, carry inherent risks of data loss if not performed correctly. Incorrect usage, power failures during operations, or corrupted metadata can lead to unrecoverable data. Always ensure proper backups before performing significant LVM changes.

LVM also introduces a layer of complexity; understanding the hierarchy of PVs, VGs, and LVs is crucial. While flexible, managing LVM can be more challenging than simple disk partitioning, especially for beginners. The system must have the appropriate kernel modules loaded (e.g., device-mapper) for LVM to function properly.

LVM OBJECT HIERARCHY

LVM organizes storage into a three-tier hierarchy:
Physical Volumes (PVs): Raw disk partitions or entire disks that are initialized for LVM use. They serve as the foundational building blocks.
Volume Groups (VGs): Collections of one or more PVs. A VG pools the storage capacity of its PVs, creating a large, unified storage pool.
Logical Volumes (LVs): Virtual partitions created from the free space within a VG. LVs are analogous to traditional disk partitions, but they offer advanced features like online resizing, snapshots, and mirroring.

OPERATING MODES

The lvm command can be executed in several modes:
Command-line mode: The most common usage, where subcommands are executed directly (e.g., `lvm vgcreate my_vg /dev/sdb1`).
Interactive shell mode: By running `lvm` without arguments, it enters an interactive shell, allowing multiple LVM commands to be run sequentially within the same context.
Scripted mode: LVM commands are frequently used within shell scripts for automated storage provisioning and management, often utilizing the --yes or --config options.

HISTORY

LVM originated in the HP-UX operating system, later adopted and implemented for Linux by Joe Thornber and Heinz Mauelshagen as part of the device-mapper framework. The first stable version of LVM for Linux (LVM1) was released around 1999-2000. LVM2, a significant rewrite with improved performance, scalability, and new features (like snapshots and thin provisioning), became the standard in the mid-2000s and is what is predominantly used today. Its development has been driven by the increasing need for flexible storage management in servers and virtualized environments, where static partitions prove insufficient.

SEE ALSO

Copied to clipboard