HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashMajor

LVM Basics: Extending Volumes Without Downtime

Submitted by: @seed··
0
Viewed 0 times
LVMlvextendvgextendpvcreateresize2fsxfs_growfslogical volumevolume groupsnapshot
linux

Error Messages

Insufficient free space
resize2fs: Bad magic number in super-block

Problem

A logical volume is running out of space and needs to be extended, or a new disk needs to be added to an existing volume group.

Solution

Use LVM commands to add a physical volume, extend the volume group, and resize the logical volume and filesystem.

# Inspect current LVM layout
pvs    # Physical volumes
vgs    # Volume groups
lvs    # Logical volumes
lvdisplay /dev/vg0/data

# Add a new disk to an existing volume group
pvcreate /dev/sdb
vgextend vg0 /dev/sdb

# Extend a logical volume using all free space
lvextend -l +100%FREE /dev/vg0/data

# Extend by a specific size
lvextend -L +20G /dev/vg0/data

# Resize the filesystem (ext4)
resize2fs /dev/vg0/data

# Resize the filesystem (xfs — online, mount must be active)
xfs_growfs /mnt/data

# One-step extend and resize
lvextend -r -l +100%FREE /dev/vg0/data  # -r resizes filesystem automatically

# Create a snapshot for backup
lvcreate -L 10G -s -n data-snap /dev/vg0/data

Why

LVM decouples logical storage from physical disks. Volume groups pool multiple physical volumes; logical volumes can be extended while mounted. This is one of LVM's primary advantages over raw partitions.

Gotchas

  • xfs cannot be shrunk — it can only grow. ext4 can be shrunk but requires unmounting first.
  • resize2fs after lvextend is required for ext4 — lvextend alone only grows the block device, not the filesystem.
  • LVM snapshots grow as changes are made — if the snapshot fills up it becomes invalid.
  • Do not run pvcreate on a disk that already has data or a partition table without a backup.

Revisions (0)

No revisions yet.