How to Fix “Insufficient Free Space: X Extents Needed But Only Y Available” in LVM Extension on CentOS


2 views

When attempting to extend an LVM logical volume with lvextend -L+40G, the operation fails because:

Insufficient free space: 10240 extents needed, but only 10239 available

The root cause lies in how LVM calculates space using Physical Extents (PEs). Each PE in this system is 4MB (as shown by vgdisplay), and the command requests exactly one more PE than currently available.

Key outputs from the system:

# vgdisplay
VG Size               79.50 GiB
PE Size               4.00 MiB
Total PE              20353
Alloc PE / Size       20353 / 79.50 GiB
Free PE / Size       0 / 0

# pvdisplay
/dev/sda3:
PV Size               40.00 GiB
PE Size               4.00 MiB
Total PE              10239
Free PE               0

Option 1: Use Exact Available Space

Instead of requesting 40GB (which requires 10240 PEs), use the available 10239 PEs (39.996GB):

lvextend -l +10239 /dev/vg_webserver/lv_root

Or using GB units:

lvextend -L+39.996G /dev/vg_webserver/lv_root

Option 2: Reduce Swap Allocation

If you have swap space you can reduce:

# Reduce swap by 4MB (1 PE)
lvreduce -L-4M /dev/vg_webserver/lv_swap
swapoff /dev/vg_webserver/lv_swap
mkswap /dev/vg_webserver/lv_swap
swapon /dev/vg_webserver/lv_swap

# Now extend root
lvextend -L+40G /dev/vg_webserver/lv_root

Option 3: Use All Available Space

This extends the LV to use all available space in the VG:

lvextend -l +100%FREE /dev/vg_webserver/lv_root

After extending the LV, don't forget to resize the filesystem:

# For ext4:
resize2fs /dev/vg_webserver/lv_root

# For xfs:
xfs_growfs /

When creating new LVs, consider:

# Leave 1-2% free space for metadata:
lvcreate -L 39G -n lv_data vg_webserver

# Or use flexible sizing:
lvcreate -l 80%FREE -n lv_data vg_webserver

The error message "Insufficient free space: 10240 extents needed, but only 10239 available" occurs when attempting to extend a Logical Volume (LV) in LVM (Logical Volume Manager). This happens because the system cannot allocate the requested number of Physical Extents (PEs) from the Volume Group (VG).

From the provided outputs, we can see:

# vgdisplay
VG Size               79.50 GiB
PE Size               4.00 MiB
Total PE              20353
Alloc PE / Size       20353 / 79.50 GiB
Free PE / Size       0 / 0

The key issue is that while we have two physical volumes (/dev/sda2 and /dev/sda3) in our volume group, all physical extents are already allocated.

Option 1: Reduce the Requested Extension Size

Instead of requesting +40G, try a slightly smaller amount that fits within the available extents:

# lvextend -L+39.99G /dev/vg_webserver/lv_root

Option 2: Use All Remaining Space

To use all available space without specifying an exact amount:

# lvextend -l +100%FREE /dev/vg_webserver/lv_root

Option 3: Check for Unused Space in Other LVs

If you have other logical volumes in the same VG that have unused space, consider reducing them first:

# lvreduce -L-1G /dev/vg_webserver/lv_swap
# lvextend -L+1G /dev/vg_webserver/lv_root

If you need the full 40G extension, you'll need to:

  1. Add a new virtual disk to your VM
  2. Create a new partition on it
  3. Add it to your volume group:
# pvcreate /dev/sdb1
# vgextend vg_webserver /dev/sdb1
# lvextend -L+40G /dev/vg_webserver/lv_root

Remember to resize your filesystem after extending the LV. For ext4:

# resize2fs /dev/vg_webserver/lv_root

For xfs:

# xfs_growfs /dev/vg_webserver/lv_root

After successful extension, verify with:

# vgdisplay
# lvdisplay
# df -h