How-To Guides5 min read

How to Track Down Disk Space with du and ncdu and Grow an LVM Volume Online

Find what filled a Linux filesystem using du, ncdu, and lsof +aL1, then extend an LVM logical volume and resize ext4 or XFS online across Ubuntu, Debian, Fedora, and RHEL.

To resolve a full Linux filesystem safely, check df -hT and df -hi, scan only the target filesystem with ncdu -x -rr or du -xhd 1, and inspect deleted-but-open files with lsof -nP +aL1 /mountpoint. If expansion is needed and free extents exist in sudo vgs, dry-run with sudo lvresize -t -L +10G -r vg/lv before running lvresize --resizefs.

Key takeaways

  • Never add disk space before checking for deleted-but-open log files or inode exhaustion.
  • Always test LVM resize operations with --test (-t) and keep a snapshot or backup ready before committing.
  • Check filesystem type with lsblk -f because ext4 and XFS use different resize tools when invoked manually.

Quick facts

  • Passing -x (--one-file-system) to du or ncdu prevents crossing into /proc, /sys, or mounted network shares.
  • lsof +aL1 /mountpoint finds unlinked files still held open by running processes when df and du disagree.
  • Running ncdu with -rr disables both file deletion and shell spawning for safe read-only production triage.
  • XFS filesystems can be expanded online with xfs_growfs on a mounted path, but XFS cannot be shrunk after creation.
  • On ext4 inside LVM, leaving at least 256 MiB unallocated in the volume group keeps e2scrub metadata snapshots working.

A disk-full alert at 03:00 rarely means you need to immediately throw bigger disks at a server. In real infrastructure operations, half of those pages come from runaway container logs, rotated-but-unlinked file descriptors, or exhausted inodes. Expanding an LVM volume before auditing what ate the capacity only buys you another outage a week later.

This workflow covers Ubuntu and Debian (apt) alongside Fedora, RHEL, AlmaLinux, and Rocky Linux (dnf).

Linux Disk Investigation and Online LVM Volume Expansion Stack
Linux Disk Investigation and Online LVM Volume Expansion Stack

Diagram: Original SVG schematic by Ajay Kumar Chaturvedi.

Prerequisites and Safety Checks

Confirm your tools and safety net before inspecting or resizing volumes:

  • sudo privileges to inspect root-owned directories, lsof, and LVM metadata.
  • Install ncdu and lvm2 if missing: on Ubuntu/Debian run sudo apt update && sudo apt install -y ncdu lvm2, or on Fedora/RHEL run sudo dnf install -y ncdu lvm2.
  • Verify whether you actually have unallocated space in an LVM Volume Group (sudo vgs) or whether you need to attach and pvresize an underlying disk first.
Backup and Destructive Warning: Always create a verified backup or cloud volume snapshot before modifying LVM partitions or resizing filesystems. Extending ext4 and XFS online is well supported, yet power loss or mistyped sizes remain risky. Remember that XFS filesystems cannot be shrunk once extended.

Step-by-Step Procedure

Step 1: Check Block Space, Inode Usage, and Filesystem Type

Target OS: Ubuntu, Debian, Fedora, RHEL, Arch.

Start by checking both space and inodes (df -hi) alongside filesystem types (df -hT):

BASH
df -hT
df -hi

A filesystem showing 40 percent block usage (Use%) and 100 percent inode usage (IUse%) cannot create new files until millions of tiny files (like stale mail queues or session caches) are cleared; adding disk blocks without checking df -hi wastes time. Note the Type column (ext4, xfs, or btrfs) and mount point path before touching anything.

Step 2: Pinpoint Heavy Directories Safely with du and ncdu

Target OS: Ubuntu, Debian, Fedora, RHEL, Arch.

Never scan / without crossing protections, or you will crawl /proc, /sys, and remote NFS shares. Always pass -x (--one-file-system), verified in the `du(1)` manual:

BASH
sudo du -xhd 1 /var | sort -h

When you want interactive drill-down without typing a dozen du commands, launch ncdu in double read-only mode (-rr), which according to the `ncdu(1)` manual disables both interactive file deletion (d) and shell spawning (b):

BASH
sudo ncdu -x -rr /var

I would skip scanning massive shared file trees directly over slow SSH links with interactive ncdu. Instead, export the scan with -0 or -1 and inspect locally, or stick to targeted du -xhd 1 depth scans.

Step 3: Check for Deleted-But-Open Files When df and du Disagree

Target OS: Ubuntu, Debian, Fedora, RHEL, Arch.

If df -hT insists /var is at 98 percent while ncdu -x only accounts for half the disk, a process is holding an open file descriptor to a deleted file. Deleting a directory entry via rm only drops the link count; the kernel holds the blocks until the process closes that descriptor.

Per the `lsof(8)` manual page, combine +a (logical AND) with +L1 (link count less than 1) and the mount path so lsof does not OR unrelated filesystems together:

BASH
sudo lsof -nP +aL1 /var

Look at SIZE/OFF and COMMAND (for example a log file rotated improperly without signaling the daemon). Gracefully reload or restart the responsible service via systemctl restart <service> rather than sending kill -9, so the daemon flushes buffers and releases the unlinked inode cleanly.

Step 4: Inspect Physical Volumes, Volume Groups, and Free Extents

Target OS: Ubuntu, Debian, Fedora, RHEL, Arch.

If real data genuinely outgrew the logical volume, inspect the full block stack first (lsblk(8)):

BASH
lsblk -f
sudo pvs
sudo vgs
sudo lvs -o +lv_path

Look at VFree in sudo vgs to confirm free space exists in the volume group. If you added capacity to the underlying virtual disk or partition in a cloud console, expand the Physical Volume online first (sudo pvresize /dev/<disk_or_part>).

As the ArchWiki Ext4 guide notes, if your logical volume uses ext4 and relies on e2scrub metadata checks, leave at least 256 MiB unallocated in the volume group instead of consuming 100 percent with -l +100%FREE.

Step 5: Dry-Run and Extend the Logical Volume and Filesystem Online

Target OS: Ubuntu, Debian, Fedora, RHEL, Arch.

Both the `lvresize(8)` manual and ArchWiki's LVM guide document --test (-t) for dry-running metadata changes and -r (--resizefs) to resize supported filesystems (ext4 and XFS) together with the logical volume via fsadm.

First run a dry-run test (-t) adding 10G to your volume:

BASH
sudo lvresize -t -L +10G -r /dev/<vg_name>/<lv_name>

Once the test output confirms the target LV and size look right, execute the live resize:

BASH
sudo lvresize -L +10G --resizefs /dev/<vg_name>/<lv_name>

If you prefer explicit control or are on Btrfs (which fsadm does not handle identically across older lvm2 releases), extend the LV first without -r, then grow the filesystem manually using the tool verified for your filesystem:

BASH
# 1. Extend LV only
sudo lvextend -L +10G /dev/<vg_name>/<lv_name>

# 2a. For ext4 (works online; takes device path)
sudo resize2fs /dev/<vg_name>/<lv_name>

# 2b. For XFS (must be mounted; dry-run with -n, then grow mountpoint)
sudo xfs_growfs -n /mountpoint
sudo xfs_growfs /mountpoint

Note that the `resize2fs(8)` manual takes the block device path for ext4, whereas the `xfs_growfs(8)` manual expects the mounted mount point directory (or mounted block device) and cannot operate on an unmounted XFS volume.

Verification and Expected Result

Confirm the logical volume size, remaining VFree capacity, and mounted filesystem total:

BASH
sudo vgs
sudo lvs /dev/<vg_name>/<lv_name>
df -hT /mountpoint

Expected result: lvs shows the expanded LSize, df -hT reports the additional usable space immediately with zero downtime, and vgs still retains a small reserve if using e2scrub.

Troubleshooting

  • `Insufficient free space` from `lvresize`: Check sudo vgs (VFree). Either add a new disk (sudo pvcreate /dev/sdX && sudo vgextend <vg_name> /dev/sdX) or enlarge the partition first (growpart / parted) followed by sudo pvresize.
  • `fsadm: Filesystem has unsupported type`: Extend the LV without -r, then run sudo btrfs filesystem resize max /mountpoint for Btrfs, or check ArchWiki XFS / ArchWiki LVM for stacked dm-crypt / LUKS layers (cryptsetup resize must run before resize2fs).
  • Disk usage still hits 100 percent minutes after expanding: Re-run sudo lsof -nP +aL1 /mountpoint or sudo journalctl --disk-usage to locate the writer saturating disk blocks before the extra extents fill too.

Sources