🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

lvm Command

Advanced Disk & Storage man(8)

Logical Volume Manager for flexible disk management

📅 Updated: Mar 16, 2026
SYNTAX
pvcreate DEVICE\nvgcreate VG_NAME PV...\nlvcreate -L SIZE -n LV_NAME VG_NAME\nlvextend -L +SIZE /dev/VG/LV

What Does lvm Do?

The LVM (Logical Volume Manager) suite provides flexible, dynamic disk management for Linux systems. LVM adds an abstraction layer between physical disks and filesystems, allowing you to resize volumes on the fly, span multiple disks, create snapshots, and manage storage without unmounting or rebooting.

LVM uses three layers: Physical Volumes (PVs) — partitions or disks initialized for LVM; Volume Groups (VGs) — pools of storage combining one or more PVs; and Logical Volumes (LVs) — the actual volumes you format and mount, carved from a VG. This layered approach means you can add disks, extend volumes, and reorganize storage dynamically.

LVM is the default partitioning scheme on most enterprise Linux installations (RHEL, Ubuntu Server, AlmaLinux). It is essential for servers that need to grow storage without downtime, create consistent backups using snapshots, or implement thin provisioning for efficient storage usage.

The main commands are: pvcreate/pvs (physical volume management), vgcreate/vgs (volume group management), lvcreate/lvs (logical volume management), and lvextend/lvreduce (resizing).

Options & Flags

OptionDescriptionExample
pvcreate Initialize a disk/partition for LVM sudo pvcreate /dev/sdb1
vgcreate Create a volume group from physical volumes sudo vgcreate data_vg /dev/sdb1 /dev/sdc1
lvcreate -L SIZE -n NAME VG Create a logical volume sudo lvcreate -L 50G -n data_lv data_vg
lvextend -L +SIZE Extend a logical volume sudo lvextend -L +20G /dev/data_vg/data_lv
lvreduce -L SIZE Shrink a logical volume sudo lvreduce -L 30G /dev/data_vg/data_lv
pvs / vgs / lvs List PVs, VGs, or LVs with summary sudo pvs && sudo vgs && sudo lvs
vgextend Add a disk to an existing volume group sudo vgextend data_vg /dev/sdd1
lvcreate --snapshot Create a snapshot of a logical volume sudo lvcreate --snapshot -L 5G -n snap1 /dev/data_vg/data_lv
lvcreate --thin Create a thin-provisioned volume sudo lvcreate -T data_vg/thinpool -L 100G
pvmove Move data between physical volumes sudo pvmove /dev/sdb1 /dev/sdd1

Practical Examples

#1 Create LVM from scratch

Complete LVM setup: initialize PV, create VG, create 50GB LV, format with ext4, and mount.
$ sudo pvcreate /dev/sdb1 && sudo vgcreate data_vg /dev/sdb1 && sudo lvcreate -L 50G -n data_lv data_vg && sudo mkfs.ext4 /dev/data_vg/data_lv && sudo mount /dev/data_vg/data_lv /data

#2 Extend a volume online

Add 20GB to a mounted ext4 volume — no downtime required. Use xfs_growfs for XFS.
$ sudo lvextend -L +20G /dev/data_vg/data_lv && sudo resize2fs /dev/data_vg/data_lv

#3 Add a new disk to volume group

Add a new disk, extend the VG, use all free space to extend the LV, and grow the filesystem.
$ sudo pvcreate /dev/sdc1 && sudo vgextend data_vg /dev/sdc1 && sudo lvextend -l +100%FREE /dev/data_vg/data_lv && sudo resize2fs /dev/data_vg/data_lv

#4 View LVM status

Quick overview of all physical volumes, volume groups, and logical volumes.
$ sudo pvs && echo "---" && sudo vgs && echo "---" && sudo lvs

#5 Create LVM snapshot

Create a 5GB snapshot of data_lv. The snapshot captures the point-in-time state for backup or testing.
$ sudo lvcreate --snapshot -L 5G -n data_snap /dev/data_vg/data_lv

#6 Use all available space

Create LV using all remaining free space in the volume group. Use -l for percentage, -L for fixed size.
$ sudo lvcreate -l 100%FREE -n data_lv data_vg

#7 Remove LVM completely

Remove in reverse order: unmount, remove LV, remove VG, remove PV. WARNING: destroys all data.
$ sudo umount /data && sudo lvremove /dev/data_vg/data_lv && sudo vgremove data_vg && sudo pvremove /dev/sdb1

#8 Migrate data between disks

Move all data from sdb1 to sdc1 live. After completion, remove old disk from VG: vgreduce data_vg /dev/sdb1.
$ sudo pvmove /dev/sdb1 /dev/sdc1

Tips & Best Practices

Always leave free space in VG: Keep 5-10% of VG space free for snapshots and emergency extensions. Use lvs -o +lv_size,vg_free to check available space.
Shrinking is dangerous: Shrinking LVs requires unmounting and is risky (data loss if done incorrectly). Always backup first. Shrink filesystem FIRST (resize2fs), then shrink LV (lvreduce). XFS cannot be shrunk.
Growing is always safe: Extending LVs is safe and can be done online (mounted). lvextend + resize2fs (ext4) or xfs_growfs (XFS) with zero downtime.
LVM thin provisioning: Thin pools allocate space on demand: create a 100GB thin pool, create 500GB of thin LVs — actual disk used is only what data is written. Perfect for development VMs.

Frequently Asked Questions

How do I extend a disk/partition in Linux?
With LVM: sudo lvextend -L +20G /dev/vg/lv && sudo resize2fs /dev/vg/lv (ext4) or sudo xfs_growfs /mountpoint (XFS). Can be done while mounted — no downtime.
What is the difference between LVM and regular partitions?
Regular partitions have fixed sizes and are hard to resize. LVM allows dynamic resizing, spanning multiple disks, snapshots, and thin provisioning. LVM is recommended for all servers.
How do I add a disk to LVM?
sudo pvcreate /dev/sdX && sudo vgextend VG_NAME /dev/sdX && sudo lvextend -l +100%FREE /dev/VG/LV && sudo resize2fs /dev/VG/LV. The additional space is available immediately.
Can I use LVM with SSDs?
Yes. LVM works with any block device. For SSDs, enable TRIM: add issue_discounts=1 to lvm.conf and mount with discard option or use periodic fstrim.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →