How to Resize LVM Partition: Extending /dev/mapper/centos-root When Space is Low


3 views

From your df -h output, I can see /dev/mapper/centos-root is at 93% capacity with only 1.4GB remaining. The fdisk -l output reveals this is actually an LVM logical volume, not a separate physical disk.

# Key observations from your system:
/dev/vda: 85.9GB physical disk  
  ├─ /dev/vda1: 500MB boot partition
  ├─ /dev/vda2: ~20GB LVM physical volume
  ├─ /dev/vda3: ~5GB LVM physical volume

First, verify if your volume group has unallocated space:

# Check volume group free space
vgdisplay centos | grep Free
# Or alternatively:
vgs

If this shows available space, we can extend the logical volume directly. If not, we'll need to first extend the physical volume.

Case 1: When Volume Group Has Free Space

# Extend the logical volume (add 5GB in this example)
lvextend -L +5G /dev/mapper/centos-root

# Resize the filesystem (for xfs/ext4)
xfs_growfs /  # For XFS filesystem
# OR
resize2fs /dev/mapper/centos-root  # For ext4

Case 2: When Physical Volume Needs Extension

If vgs shows no free space, we'll need to:

# Check available space on /dev/vda
fdisk -l /dev/vda

# Create new partition (using remaining space)
fdisk /dev/vda
# Within fdisk: n → p → [enter] → [enter] → t → [partition number] → 8e → w

# Reload partition table
partprobe

# Initialize new partition as physical volume
pvcreate /dev/vda4

# Extend volume group
vgextend centos /dev/vda4

# Now you can extend the logical volume as in Case 1

Always verify changes at each step:

# Check filesystem after resize
df -h

# Verify logical volume size
lvs

# Check for filesystem errors (recommended before resizing)
e2fsck -f /dev/mapper/centos-root

For more flexible management, consider converting to thin provisioning:

# Convert existing volume to thin pool
lvconvert --type thin-pool --poolmetadata centos/meta centos/root
  • Always backup critical data before resizing
  • XFS filesystems can only be grown, not shrunk
  • For production systems, consider downtime requirements
  • Monitor filesystem health after resizing

From the df -h and fdisk -l output, we can see your system has:

1. A small root partition (/dev/mapper/centos-root) at 93% capacity
2. A larger physical disk (/dev/vda) with unused space in its LVM partitions
3. Existing LVM configuration (shown by the '8e' partition type)

Here's how to safely extend your root partition:

1. Check Available Physical Volume Space

# Check current PVs
pvdisplay

# Check VG free space
vgdisplay centos | grep Free

2. Extend the Physical Volume

# Assuming /dev/vda3 has free space
pvresize /dev/vda3

# Verify new PV size
pvdisplay

3. Extend the Logical Volume

# Extend LV using all available space
lvextend -l +100%FREE /dev/mapper/centos-root

# For specific size (e.g., +10G)
# lvextend -L +10G /dev/mapper/centos-root

4. Resize the Filesystem

# For xfs (common in CentOS 7+)
xfs_growfs /

# For ext4 (older systems)
# resize2fs /dev/mapper/centos-root
# Check new size
df -h | grep centos-root

For frequent use, create a resize script:

#!/bin/bash
# Auto-resize LVM script
PV="/dev/vda3"
VG="centos"
LV="root"

pvresize $PV
lvextend -l +100%FREE /dev/mapper/$VG-$LV
xfs_growfs /

Problem: No free space in Volume Group
Fix: Create new partition on /dev/vda and add to VG:

fdisk /dev/vda
# Create new partition with type 8e
partprobe
pvcreate /dev/vda4
vgextend centos /dev/vda4