linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/File system/lvm

kb/filesystem ── File system ── advanced

LVM: Logical Volume Manager

LVM is a layer between [[block-devices]] and the filesystem: it pools disks and carves out logical volumes of any size that you can grow, snapshot, and migrate live.

view as markdownaka: logical-volume, lvm2, pv, vg, lv

Why

Without LVM the partition /dev/sda1 is a fixed slice of a disk. To grow /home you have to move physical partitions. With LVM you add a disk to a pool and grow the logical volume on the fly, without unmounting.

You also get snapshots, migration between disks, RAID, and thin provisioning.

Hierarchy

PV (Physical Volume)  ← a regular partition or a whole disk
     ↓
VG (Volume Group)     ← a pool of one or more PVs
     ↓
LV (Logical Volume)   ← a virtual volume inside the VG, you put a filesystem on it

Building from scratch

bash
# 1. Prepare the physical volumes (on partitions or a whole disk)
sudo pvcreate /dev/sdb1 /dev/sdc1
sudo pvs                              # list PVs
sudo pvdisplay /dev/sdb1              # details
# 2. Create a volume group from them
sudo vgcreate vg-data /dev/sdb1 /dev/sdc1
sudo vgs                              # list VGs
sudo vgdisplay vg-data
# 3. Carve out logical volumes
sudo lvcreate -L 50G -n web vg-data        # a 50 GB volume "web"
sudo lvcreate -l 100%FREE -n logs vg-data  # all the remaining space
sudo lvs                              # list LVs
sudo lvdisplay /dev/vg-data/web
# 4. Create a filesystem and mount it
sudo mkfs.ext4 /dev/vg-data/web
sudo mount /dev/vg-data/web /var/www

The names for fstab are /dev/<vg>/<lv> or /dev/mapper/<vg>-<lv> (both point at the same device).

Growing online (the main feature)

bash
# 1. Add one more disk to the VG
sudo pvcreate /dev/sdd1
sudo vgextend vg-data /dev/sdd1
# 2. Grow the LV
sudo lvextend -L +100G /dev/vg-data/web        # +100 GB
sudo lvextend -l +100%FREE /dev/vg-data/logs   # all free space
# 3. Grow the filesystem on top (WITHOUT unmounting)
sudo resize2fs /dev/vg-data/web                # ext4
sudo xfs_growfs /var/www                        # xfs (by mount point!)
# ext4: all in one command
sudo lvextend -L +100G -r /dev/vg-data/web     # -r = run resize2fs automatically

Shrinking (dangerous!)

Only ext4 / btrfs support it (xfs cannot). The order is REVERSED: shrink the filesystem first, then the LV.

bash
sudo umount /var/www
sudo e2fsck -f /dev/vg-data/web
sudo resize2fs /dev/vg-data/web 30G
sudo lvreduce -L 30G /dev/vg-data/web
sudo mount /var/www

Get the order wrong and you lose data. Make a backup.

Snapshots

A COW snapshot is instant and uses space only for the changes:

bash
# Snapshot for a backup: 5 GB of space for changes, named snap-web
sudo lvcreate -L 5G -s -n snap-web /dev/vg-data/web
# Use it (for example, a backup with rsync from a frozen state):
sudo mkdir /mnt/snap
sudo mount -o ro /dev/vg-data/snap-web /mnt/snap
rsync -av /mnt/snap/ /backup/web/
# Remove the snapshot
sudo umount /mnt/snap
sudo lvremove /dev/vg-data/snap-web

IMPORTANT: the snapshot breaks if the changes exceed the allocated space. Monitor it: lvs, the Data% column.

Thin provisioning

Regular LVs take up their space right away. Thin LVs overcommit: you can create 5 volumes of 100 GB each with 200 GB of real space. They consume space as you write.

bash
sudo lvcreate -L 200G -T vg-data/thin-pool          # pool
sudo lvcreate -V 100G -T vg-data/thin-pool -n vm1   # a thin volume, 100G "virtually"

Dangerous if someone actually writes the data: dmesg starts complaining and the volumes start to stall. Monitoring the pool usage is mandatory.

Migrating between disks online

Replace an old disk with a new one without downtime:

bash
sudo pvcreate /dev/sde1
sudo vgextend vg-data /dev/sde1
sudo pvmove /dev/sdb1                  # move off sdb1 onto the free PVs
sudo vgreduce vg-data /dev/sdb1
sudo pvremove /dev/sdb1
# Now sdb1 can be pulled out

Useful overview

bash
sudo pvs && echo --- && sudo vgs && echo --- && sudo lvs
sudo lsblk                              # the tree shows the LVs
sudo lvs -o +devices                    # which PVs each LV sits on

§ команды

bash
sudo pvs && sudo vgs && sudo lvs

All three LVM levels in one command, an overview of the pool

bash
sudo lvextend -L +50G -r /dev/vg/data

Grow the volume by 50G and resize the filesystem right away (-r)

bash
sudo lvcreate -L 5G -s -n snap /dev/vg/data

Snapshot for a backup, a quick freeze of the state

bash
sudo pvmove /dev/sdb1

Move data off a disk online before you pull it out

bash
sudo lvs -o +devices

Which physical devices each LV sits on

§ см. также

  • block-devicesBlock devices: disks in LinuxA block device is read and written in fixed-size blocks (usually 512B or 4K). Disks, SSDs, and NVMe drives are all block devices in `/dev/`.
  • filesystemsFilesystems: ext4, xfs, btrfs, zfsext4 is the reliable default. xfs handles large files and parallel I/O. btrfs and zfs give you snapshots, checksums, and built-in RAID, but they are more complex.
  • ext4ext4: the Linux filesystem workhorseext4 is the default filesystem on most distributions: journaling, extents, a fixed inode count set at mkfs time. The main tunes are the data mode, noatime, and lazy init. Stable for 15+ years. Does not scale like XFS.
  • xfsXFS: extents and parallel I/OXFS is the RHEL 7+ default: allocation groups (parallel I/O), extent-based allocation, online grow. **It cannot shrink**, grow only. Ideal for big files, databases, and parallel workloads.
  • cmd-lsblk-blkidlsblk and blkid: block devices and UUIDslsblk shows the block device tree (disk -> partition -> LVM/crypt -> mountpoint). blkid prints UUID, LABEL, and filesystem type. Use them together to write a [[mount-and-fstab|/etc/fstab]] entry by UUID.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies