OSError: [Errno 28] No space left on device

Loading

The error OSError: [Errno 28] No space left on device occurs when Python tries to write to disk but the storage is full. This can happen when saving files, writing logs, downloading large datasets, or handling temporary files.


1. Common Causes and Fixes

Cause 1: Disk is Completely Full

Your system or partition has no free space left.

Solution: Check disk usage using:

df -h

This will show how much space is available. If your / or /home partition is at 100% usage, you need to free up space.

How to free up space:

  • Delete unnecessary files: rm -rf /path/to/unwanted/files
  • Clear system logs: sudo journalctl --vacuum-size=500M # Reduce logs to 500MB
  • Remove cached files: sudo apt-get clean # On Ubuntu/Debian sudo yum clean all # On RHEL/CentOS

Cause 2: Large Temporary Files Are Filling Up Storage

Temporary files (e.g., logs, cached files, downloads) may consume all space.

Solution: Clear temporary files:

rm -rf /tmp/*

For Python, manually delete large temp files:

import tempfile
tempfile.tempdir = None # Reset temp directory

Cause 3: Running Out of Inodes

Even if you have free space, your system might have no inodes left (small storage units for files).

Solution: Check inode usage:

df -i

If inodes are 100% full, delete unnecessary small files:

find /var/log -type f -delete

Cause 4: Disk Quota Exceeded

If you’re on a shared server or cloud VM, your user may have a quota limit.

Solution: Check quota:

quota -s

If you’re over the limit, request more space or delete files.


Cause 5: A Process is Consuming Too Much Disk Space

A running process might be writing large logs or using up all available storage.

Solution: Find large files in real-time:

du -ah / | sort -rh | head -10  # Shows the top 10 largest files

If a file is growing uncontrollably, stop the process:

ps aux --sort=-%mem | head  # Find large processes
kill -9 <PID> # Replace <PID> with process ID

Cause 6: Docker Containers or Virtual Machines Are Taking Space

If you use Docker, old containers and images can consume space.

Solution: Clean up Docker:

docker system prune -a

2. Summary of Fixes

IssueFix
Disk fullDelete unnecessary files (rm -rf /path)
Temporary files taking spaceClear /tmp/ (rm -rf /tmp/*)
No inodes leftCheck with df -i, delete small files
Disk quota exceededCheck with quota -s, free up space
Large processes consuming storageFind with `du -ah /
Docker consuming spaceRun docker system prune -a

Leave a Reply

Your email address will not be published. Required fields are marked *