LVM (Logical Volume Manager)
LVM (Logical Volume Manager) is a Linux volume management system for flexible physical disk administration. It abstracts storage through a three-layer structure: Physical Volumes (PV), Volume Groups (VG), and Logical Volumes (LV). You can combine multiple physical disks into a single large storage pool, expand volumes without stopping services, and take consistent backups using snapshots.
Syntax
# -----------------------------------------------
# PV (Physical Volume) operations
# -----------------------------------------------
# pvcreate {device-path}
# → Initializes the specified device as a PV
# → You can specify a partition or an entire disk
# Example: sudo pvcreate /dev/sdb
# pvdisplay [{pv-path}]
# → Displays detailed PV information (size, UUID, associated VG, etc.)
# pvs
# → Displays a compact list of PVs
# -----------------------------------------------
# VG (Volume Group) operations
# -----------------------------------------------
# vgcreate {vg-name} {pv-path} [{pv-path} ...]
# → Creates a VG by combining the specified PVs
# Example: sudo vgcreate kof_vg /dev/sdb
# vgdisplay [{vg-name}]
# → Displays detailed VG information (free space, PE size, etc.)
# vgs
# → Displays a compact list of VGs
# vgextend {vg-name} {pv-path}
# → Adds a new PV to an existing VG to increase its capacity
# Example: sudo vgextend kof_vg /dev/sdc
# -----------------------------------------------
# LV (Logical Volume) operations
# -----------------------------------------------
# lvcreate -L {size} -n {lv-name} {vg-name}
# → Creates an LV of the specified size
# → Size is specified in G (gigabytes), M (megabytes), or T (terabytes)
# Example: sudo lvcreate -L 10G -n kyo_lv kof_vg
# lvcreate -l {pe-count|100%FREE} -n {lv-name} {vg-name}
# → Creates an LV using a specific number of PEs (Physical Extents) or all free space in the VG
# Example: sudo lvcreate -l 100%FREE -n iori_lv kof_vg
# lvdisplay [{lv-path}]
# → Displays detailed LV information (path, size, snapshot info, etc.)
# lvs
# → Displays a compact list of LVs
# lvextend -L +{size} {lv-path}
# → Expands the LV by the specified amount (filesystem resize must be done separately)
# Example: sudo lvextend -L +5G /dev/kof_vg/kyo_lv
# lvreduce -L -{size} {lv-path}
# → Shrinks the LV (the filesystem must be shrunk beforehand)
# Example: sudo lvreduce -L -2G /dev/kof_vg/iori_lv
# lvrename {vg-name} {old-lv-name} {new-lv-name}
# → Renames an LV
# Example: sudo lvrename kof_vg iori_lv andy_lv
# -----------------------------------------------
# Snapshots
# -----------------------------------------------
# lvcreate -s -L {snapshot-size} -n {snapshot-name} {source-lv-path}
# → Creates a snapshot LV (a readable/writable copy) of the specified LV
# → The snapshot size is the storage area for delta data; set it based on the expected change volume of the source LV
# Example: sudo lvcreate -s -L 2G -n kyo_snap /dev/kof_vg/kyo_lv
# -----------------------------------------------
# Filesystem expansion
# -----------------------------------------------
# resize2fs {device-path}
# → Expands an ext2/ext3/ext4 filesystem to match the new LV size
# → Run this after lvextend
# Example: sudo resize2fs /dev/kof_vg/kyo_lv
# xfs_growfs {mount-point}
# → Expands an XFS filesystem while it is mounted
# → XFS supports online growth but does not support shrinking
# Example: sudo xfs_growfs /mnt/kyo_data
Command reference
| Command | Description |
|---|---|
pvcreate {device} | Initializes a device as a PV (Physical Volume). This is the starting point of LVM management. |
pvdisplay | Displays detailed PV information, including size, associated VG, and free PE count. |
pvs | Displays a compact list of PVs. Useful for scripting and quick checks. |
vgcreate {vg-name} {pv} | Creates a VG (Volume Group) from one or more PVs. Multiple PVs can be specified at once. |
vgdisplay | Displays detailed VG information, including total capacity, free space, and PE size. |
vgs | Displays a compact list of VGs. |
vgextend {vg-name} {pv} | Adds a new PV to an existing VG to increase its capacity. Can be run while services are running. |
lvcreate -L {size} -n {lv-name} {vg-name} | Creates an LV (Logical Volume) of the specified size. After creation, create a filesystem on it and mount it. |
lvcreate -l 100%FREE -n {lv-name} {vg-name} | Creates an LV using all free space in the VG. |
lvdisplay | Displays detailed LV information, including path, size, and snapshot details. |
lvs | Displays a compact list of LVs. |
lvextend -L +{size} {lv-path} | Expands an LV. After expanding, use resize2fs or xfs_growfs to expand the filesystem as well. |
lvreduce -L -{size} {lv-path} | Shrinks an LV. The filesystem must be shrunk beforehand. Be careful to avoid data loss from accidental use. |
lvrename {vg-name} {old-name} {new-name} | Renames an LV. Remember to update the mount entry in /etc/fstab accordingly. |
lvcreate -s -L {size} -n {name} {lv-path} | Creates a snapshot LV. Useful as a consistent data copy before taking a backup. |
resize2fs {device-path} | Expands an ext4 filesystem to match the LV size. Can be run without unmounting. |
xfs_growfs {mount-point} | Expands an XFS filesystem while it is mounted. Shrinking is not supported. |
Examples
Initial LVM setup (adding a new disk and mounting it)
# -----------------------------------------------
# Set up /dev/sdb under LVM management
# Building it as a data volume for the kof_vg group
# -----------------------------------------------
# 1. Initialize /dev/sdb as a PV (Physical Volume)
sudo pvcreate /dev/sdb
# 2. Create VG (Volume Group) kof_vg from the PV
# To combine multiple PVs, list them separated by spaces
sudo vgcreate kof_vg /dev/sdb
# 3. Create a 10 GB LV (Logical Volume) named kyo_lv from kof_vg
sudo lvcreate -L 10G -n kyo_lv kof_vg
# 4. Create an ext4 filesystem on the LV
# The device path follows the format /dev/{vg-name}/{lv-name}
sudo mkfs.ext4 /dev/kof_vg/kyo_lv
# 5. Create a mount point and mount the LV
sudo mkdir -p /mnt/kyo_data
sudo mount /dev/kof_vg/kyo_lv /mnt/kyo_data
# 6. Add an entry to /etc/fstab so it mounts automatically after reboot
# Using a UUID makes the entry resilient to device name changes
sudo blkid /dev/kof_vg/kyo_lv
# → Displays: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4"
# Add the following line to /etc/fstab:
# UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/kyo_data ext4 defaults 0 2
# Verify that the LV was created successfully
sudo lvs
Running these commands produces the following output:
$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert kyo_lv kof_vg -wi-ao---- 10.00g
Expanding an LV (adding capacity to an existing volume)
# ----------------------------------------------- # Expand kyo_lv from 10 GB to 15 GB # Verify that the VG has sufficient free space beforehand # ----------------------------------------------- # Check the VG's free space (look at the "Free PE / Size" field) sudo vgdisplay kof_vg # Expand the LV by 5 GB (the + prefix means "add to current size") sudo lvextend -L +5G /dev/kof_vg/kyo_lv # For ext4: expand the filesystem to match the LV's new size # Use the -p option to display progress sudo resize2fs /dev/kof_vg/kyo_lv # For XFS, run this instead (online resize is supported): # sudo xfs_growfs /mnt/kyo_data # Confirm the expansion df -h /mnt/kyo_data
Run the following command:
$ df -h /mnt/kyo_data Filesystem Size Used Avail Use% Mounted on /dev/mapper/kof_vg-kyo_lv 15G 1.2G 13G 9% /mnt/kyo_data
Creating a snapshot and using it for backups
# ----------------------------------------------- # Create a snapshot of kyo_lv and use it for a backup # A snapshot stores the delta data from the point of creation # If the delta exceeds 2 GB the snapshot is invalidated, # so set the size with enough headroom # ----------------------------------------------- # Create a 2 GB snapshot of kyo_lv named kyo_snap sudo lvcreate -s -L 2G -n kyo_snap /dev/kof_vg/kyo_lv # Mount the snapshot read-only and inspect / back up its contents sudo mkdir -p /mnt/kyo_snap sudo mount -o ro /dev/kof_vg/kyo_snap /mnt/kyo_snap # Back up with rsync (consistency is guaranteed because it's a snapshot) sudo rsync -av /mnt/kyo_snap/ /backup/kyo_data/ # After the backup, unmount and remove the snapshot sudo umount /mnt/kyo_snap sudo lvremove /dev/kof_vg/kyo_snap # Check snapshot usage (the snapshot is invalidated when Data% reaches 100%) sudo lvs -o lv_name,lv_size,data_percent
Run the following command:
$ sudo lvs -o lv_name,lv_size,data_percent LV LSize Data% kyo_lv 15.00g kyo_snap 2.00g 3.45
Adding a new disk to a VG to increase its capacity
# ----------------------------------------------- # Add a new disk /dev/sdc to the existing kof_vg # The VG capacity can be expanded while services remain running # ----------------------------------------------- # Initialize /dev/sdc as a PV sudo pvcreate /dev/sdc # Add /dev/sdc to kof_vg sudo vgextend kof_vg /dev/sdc # Verify that the VG capacity has increased sudo vgs # Allocate the newly added free space as iori_lv # Reserve 8 GB for the iori team's data volume sudo lvcreate -L 8G -n iori_lv kof_vg sudo mkfs.ext4 /dev/kof_vg/iori_lv sudo mkdir -p /mnt/iori_data sudo mount /dev/kof_vg/iori_lv /mnt/iori_data
Run the following command:
$ sudo vgs VG #PV #LV #SN Attr VSize VFree kof_vg 2 2 0 wz--n- <39.99g <16.99g
Overview
LVM is a Linux mechanism that enables flexible storage management beyond the constraints of individual physical disks. It uses a three-layer structure: PVs (Physical Volumes) register disks with LVM, VGs (Volume Groups) pool those PVs into a unified storage resource, and LVs (Logical Volumes) are carved out of the VG at any desired size. This abstraction lets you dynamically expand or shrink volumes without worrying about physical disk boundaries. To expand a volume, use lvextend to resize the LV, then use resize2fs for ext4 or xfs_growfs for XFS to expand the filesystem. The snapshot feature lets you back up database or web application data in a consistent state even while writes are in progress. For information on disk partition layouts, see Disk Partition Management (fdisk / parted). For details on creating filesystems and mounting, see Creating and Mounting Filesystems (mkfs / mount).
If you find any errors or copyright issues, please contact us.