Loading…

1. Problem overview

The error No space left on device (ENOSPC) means the filesystem cannot allocate something it needs, not that gigabytes are necessarily missing. On a Linux VPS or Linux dedicated server, four distinct conditions cause it:

  • Block exhaustion: data blocks are full (df -h shows Avail at 0).
  • Inode exhaustion: blocks are free, but no inodes remain to create new files.
  • Deleted-but-open files: a file was removed while a process still holds it open, so its blocks stay allocated.
  • Filesystem or mount issues: you checked the wrong filesystem, data hides beneath a mount point, or a container volume is full.

Note: When df reports far more used space than du can account for, suspect deleted-but-open files or data hidden under a mount point.

2. Check disk capacity

Read-only diagnostics:

df -hTdf -h /path/to/failing/directory

Read Avail and Use% for the filesystem that holds the failing path. ext4 reserves a share of blocks for root (5% by default), so Size minus Used is larger than Avail; trust Avail. On Btrfs, df can mislead, so also run sudo btrfs filesystem usage /.

Note: Applications often write to a separate partition such as /var or /tmp. A healthy root filesystem proves nothing about the one that is full.

3. Check inode availability

Read-only diagnostic:

df -i

IUse% at 100% means inode exhaustion, even when df -h shows free space. To find which directory holds the most files (slow on large trees):

sudo find /var -xdev -type f | cut -d/ -f1-4 | sort | uniq -c | sort -rn | head

Common sources are session files, mail queues and cache directories. XFS and Btrfs allocate inodes dynamically, so this failure is mostly seen on ext4.

Note: Inode exhaustion is a file-count problem. Deleting a few large files frees almost no inodes.

4. Find large files and directories

Read-only diagnostics:

sudo du -xhd1 /var | sort -hfindmnt

-x keeps du on one filesystem and -d1 limits depth to one level; repeat on the largest subdirectory. findmnt lists every mount source and target so you can confirm which device backs which path.

To reveal files hidden beneath a mount point, temporarily bind-mount the root filesystem. This changes the mount table, not your data; /mnt must be empty.

sudo mount --bind / /mntsudo du -xhd1 /mnt | sort -hsudo umount /mnt

Then check logs, the journal and containers:

sudo du -xhd1 /var/log | sort -hsudo journalctl --disk-usagedocker system df

Note: Large files sitting inside an empty-looking mount directory (for example /mnt/data) usually mean a volume failed to mount and an application wrote to the root disk instead.

Deleted-but-open files

See the next section.

5. Identify deleted-but-open files

Read-only diagnostic:

sudo lsof +L1

+L1 selects open files whose link count is below 1, meaning they were unlinked. Look for names ending in (deleted) and note the COMMAND, PID and SIZE/OFF columns. To limit output to one filesystem, use sudo lsof -a +L1 /var. If lsof is not installed, this works instead:

sudo find /proc/*/fd -ls 2>/dev/null | grep '(deleted)'

Link counts are unreliable for NFS files.

Note: The classic cause is a log removed with rm while nginx, MySQL or a Java application kept writing to it.

6. Safely resolve the issue

Precautions: Never delete files from /var, /var/lib, databases or application directories until you know which package or service owns them. Never remove an active log with rm. Take a backup or snapshot first, for example with Acronis Backup.

The commands below modify the server.

Package caches (Debian/Ubuntu, then RHEL-family):

sudo apt cleansudo dnf clean all

Journal (removes the oldest archived journal files until 500 MB remain):

sudo journalctl --vacuum-size=500M

Logs: preview a rotation with debug mode, then force it. logrotate runs the service's post-rotate action, so the service reopens its log safely. Delete only rotated archives (such as *.gz) you have confirmed.

sudo logrotate -d /etc/logrotate.d/nginxsudo logrotate -f /etc/logrotate.d/nginx

Inode clean-up: list first, delete after review, and only in directories your application documents as safe (cache or sessions).

sudo find /path/to/cache -type f -mtime +7 -print | headsudo find /path/to/cache -type f -mtime +7 -delete

Deleted-but-open files: restart the owning service so it closes the handle. This causes a brief interruption, so schedule it.

sudo systemctl restart nginx

Last resort for a process that cannot be restarted: sudo truncate -s 0 /proc/PID/fd/FD, using the PID and FD from the lsof output. This permanently discards the file's contents.

Containers: review docker system df before running sudo docker system prune, which removes stopped containers, unused networks and dangling images. Never delete inside /var/lib/docker by hand.

If legitimate data fills the disk, expand storage with a larger Linux VPS plan, or choose Managed VPS Hosting so ICSDC engineers handle housekeeping.

Note: Cleaning without fixing the cause (a missing logrotate rule, debug logging left on) brings the error back within days.

7. Verify storage recovery

df -hdf -isudo lsof +L1

Expected results: Avail has increased, Use% and IUse% have dropped, and lsof +L1 shows no large deleted entries. Retry the operation that failed and check the application log for new ENOSPC errors. To prevent recurrence, alert at 80% on both block and inode usage and confirm log rotation works with sudo logrotate -d /etc/logrotate.conf.

Note: Most monitoring tracks block usage only. Add an inode check, or this problem will surprise you again.