Error Medic

How to Fix "No space left on device": Complete Linux LVM Extend Guide

Fix "No space left on device" errors by extending your Linux LVM partition. Step-by-step guide to lvm disk extend, logical volumes, and safe filesystem growth.

Last updated:
Last verified:
1,687 words
Key Takeaways
  • Root Cause 1: Application logs or database data have completely exhausted the allocated logical volume space.
  • Root Cause 2: Improper initial LVM provisioning left unallocated free space in the Volume Group while the root partition starves.
  • Quick Fix: Use the `lvextend -r` command to simultaneously grow the logical volume and resize the filesystem without downtime.
Fix Approaches Compared
MethodWhen to UseTimeRisk
lvextend with -r flagWhen Volume Group has free space (works for ext4 & XFS)1-2 minsVery Low
lvextend + resize2fsExtending standard ext4 Linux LVM partitions manually2-5 minsLow
lvextend + xfs_growfsExtending XFS-based partitions (CentOS/RHEL defaults)2-5 minsLow
pvcreate + vgextendWhen current Volume Group has 0 free space and a new disk is added10-15 minsMedium

Understanding the "No space left on device" Error

One of the most common and critical alerts a DevOps or SRE engineer receives is the dreaded No space left on device (ENOSPC) error. This often cascades into massive system failures: databases like MySQL or PostgreSQL crash, web servers return 500 Internal Server Errors, and system logging daemons halt completely. When this happens on a modern Linux system, the solution usually involves a linux lvm extend operation.

Logical Volume Manager (LVM) abstracts physical storage devices, allowing administrators to pool disk space and allocate it dynamically. This abstraction means that when a partition fills up, you do not need to endure painful downtime or migrate data to a larger disk. Instead, you can extend lvm partition sizes on the fly. In this comprehensive guide, we will walk through the exact steps for a safe linux lvm extend partition procedure, diagnosing the underlying issues, and safely growing your filesystem.

Prerequisites for LVM Disk Extend

Before executing a linux lvm resize, you need to understand the three layers of the LVM storage architecture:

  1. Physical Volumes (PV): The raw disks or disk partitions (e.g., /dev/sda1, /dev/sdb).
  2. Volume Groups (VG): The storage pools made up of one or more Physical Volumes (e.g., ubuntu-vg, centos_root).
  3. Logical Volumes (LV): The virtual partitions carved out of the Volume Group that hold your filesystems (e.g., /dev/mapper/ubuntu--vg-root).

To successfully perform an lvm extend logical volume command, there must be unallocated space within your Volume Group. If the Volume Group is full, you must first add a new Physical Volume to it.

Step 1: Diagnose the Current Storage State

When confronted with an outage, your first step is verifying exactly which partition is full and identifying the filesystem type.

Run df -Th to check disk space and filesystem types:

$ df -Th
Filesystem                        Type      Size  Used Avail Use% Mounted on
udev                              devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                             tmpfs     798M  1.2M  797M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4       20G   20G     0 100% /

Here, the root partition / is 100% full and uses the ext4 filesystem. Next, determine if the Volume Group has any free space remaining for the linux extend lvm partition operation.

Run the vgs command:

$ sudo vgs
  VG        #PV #LV #SN Attr   VSize   VFree 
  ubuntu-vg   1   1   0 wz--n- <50.00g <30.00g

In this output, VSize is 50GB, and VFree is 30GB. This is ideal; we have 30GB of unallocated space in the Volume Group, meaning we can proceed immediately with the lvm disk extend without needing to add physical disks.

Step 2: Extend the Logical Volume

Now that we know space is available, we will extend the logical volume. The utility used for this is lvextend. There are several ways to specify how much space to add:

  • Add a specific amount: lvextend -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv (Adds 10 Gigabytes)
  • Set to a specific total size: lvextend -L 40G /dev/mapper/ubuntu--vg-ubuntu--lv (Sets the total size to 40 Gigabytes)
  • Use all remaining free space: lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

The Pro-Tip for Zero Downtime: Modern versions of lvextend include the -r or --resizefs flag. This flag tells LVM to automatically invoke the correct filesystem resizing tool (resize2fs for ext4, xfs_growfs for XFS) immediately after the volume is expanded.

$ sudo lvextend -l +100%FREE -r /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 20.00 GiB (5120 extents) to <50.00 GiB (12799 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 13106176 (4k) blocks long.

Step 3: Manual Filesystem Resizing (If you forgot the -r flag)

If you executed the lvm extend logical volume command without the -r flag, the underlying block device is larger, but the filesystem sitting on top of it still thinks it's the old size. You will still see No space left on device. You must resize the filesystem manually.

For Ext3/Ext4 Filesystems: Use the resize2fs command. It safely resizes ext filesystems online.

$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

For XFS Filesystems (Common in RHEL/CentOS/AlmaLinux): XFS filesystems require the xfs_growfs command. Unlike resize2fs which takes the device path, xfs_growfs requires the mount point.

$ sudo xfs_growfs /

Troubleshooting Common Errors

While the linux lvm extend process is generally robust, engineers occasionally run into edge cases.

Error: "resize2fs: Bad magic number in super-block while trying to open..."

Symptom: You successfully run lvextend, but when you run resize2fs, it throws a bad magic number error. Root Cause: You are attempting to run an ext4 resizing tool on an XFS filesystem. resize2fs cannot parse XFS superblocks. Fix: Verify your filesystem type with df -Th. If it is XFS, run xfs_growfs /mount/point instead.

Error: "Insufficient free space: X extents needed, but only Y available"

Symptom: The lvextend command fails before doing anything. Root Cause: You requested more space than the Volume Group currently has available. Fix: Run vgs to check exactly how much VFree space exists. If it is 0, you must provision a new disk at the hypervisor or hardware level, format it as a Physical Volume (pvcreate /dev/sdc), and add it to the Volume Group (vgextend ubuntu-vg /dev/sdc). Once the VG has capacity, you can retry the lvm disk extend.

Error: "New size given (X extents) not larger than existing size (X extents)"

Symptom: lvextend complains that the new size is not larger than the existing one. Root Cause: You likely used a lowercase -l flag when you meant uppercase -L, or you forgot the + sign. For example, lvextend -L 10G sets the absolute size to 10G. If the disk is already 20G, it refuses to shrink it. Fix: Always use the + sign when you mean "add this much space" (e.g., lvextend -L +10G).

Advanced: Adding a New Disk to Extend an LVM Partition

If step 1 revealed that your Volume Group is entirely full, simply extending the logical volume won't work. You must expand the underlying storage pool first.

  1. Add the new disk in VMWare, AWS (EBS volume), or physically install it.
  2. Rescan the SCSI bus if necessary to detect the new disk without rebooting.
  3. Identify the new disk using lsblk (let's assume it's /dev/sdb).
  4. Initialize the disk for LVM: sudo pvcreate /dev/sdb
  5. Add the new physical volume to your existing volume group: sudo vgextend ubuntu-vg /dev/sdb
  6. Verify the volume group now has free space: sudo vgs
  7. Finally, execute the linux lvm extend partition command: sudo lvextend -l +100%FREE -r /dev/mapper/ubuntu--vg-root

By following these procedures, you can rapidly resolve ENOSPC incidents, safely perform a linux lvm resize, and restore application availability with zero system downtime.

Frequently Asked Questions

bash
# 1. Diagnose current disk usage and filesystem type
df -Th

# 2. Check Volume Groups for unallocated free space (VFree)
vgs

# 3. Check Logical Volumes mapping
lvs

# --- THE QUICK FIX (Extends LV to max free space AND resizes filesystem) ---
sudo lvextend -l +100%FREE -r /dev/mapper/ubuntu--vg-ubuntu--lv

# --- MANUAL FIX FOR EXT4 (Two-step process) ---
# Add 10GB to the Logical Volume
sudo lvextend -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv
# Grow the ext4 filesystem to fill the block device
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

# --- MANUAL FIX FOR XFS (Two-step process) ---
# Add 20GB to the Logical Volume
sudo lvextend -L +20G /dev/mapper/centos--vg-root
# Grow the XFS filesystem (Note: requires mount point, not device path)
sudo xfs_growfs /

# --- ADDING A NEW DISK (If Volume Group is completely full) ---
# 1. Create Physical Volume on the new disk
sudo pvcreate /dev/sdb
# 2. Add Physical Volume to existing Volume Group
sudo vgextend ubuntu-vg /dev/sdb
# 3. Extend the Logical Volume and filesystem
sudo lvextend -l +100%FREE -r /dev/mapper/ubuntu--vg-root
E

Error Medic Editorial

Our SRE and DevOps engineering team shares field-tested troubleshooting guides, infrastructure automation strategies, and Linux deep-dives based on decades of production environment experience.

Sources

Explore More Linux Sysadmin Guides