You’re seeing error messages about disk space being full, but when you run df -h, it shows you have plenty of space available. This frustrating mismatch typically happens when your system runs out of inodes (file slots) rather than actual storage space, or when deleted files are still being held open by running processes.
Step-by-Step Fixes
Step 1: Check Your Inode Usage
First, let’s see if you’ve run out of inodes. Open your terminal and run:
“`bash
df -i
“`
Look for any filesystem showing 100% or close to it in the IUse% column. If you see this, you have too many small files eating up your file allocation table. This is ideal for identifying the real culprit when df shows available space but your system acts full.
Step 2: Find and Clear Large Deleted Files Still in Use
Sometimes programs keep deleted files open, preventing space recovery. Run this command to find them:
“`bash
sudo lsof | grep deleted
“`
If you see large files listed, note which processes are holding them. You can restart those services or, in extreme cases, reboot your system. This method is best used in situations where you need immediate space recovery without hunting down individual files.
Step 3: Empty Your Trash and Package Cache
Clear out the obvious space wasters:
“`bash
rm -rf ~/.local/share/Trash/
sudo apt-get clean
sudo apt-get autoremove
“`
These commands remove deleted files sitting in trash, old package downloads, and unnecessary dependencies. Not recommended when you might need to reinstall packages offline later.
Step 4: Hunt Down Space Hogs in Hidden Locations
Check these common problem areas:
“`bash
sudo du -sh /var/log/
sudo du -sh /var/cache/*
sudo journalctl –disk-usage
“`
If journalctl shows massive usage, trim it down:
“`bash
sudo journalctl –vacuum-time=3d
“`
This keeps only the last 3 days of system logs. Adjust the timeframe based on your troubleshooting needs.
Step 5: Scan for Rogue Large Files
Find files larger than 1GB hiding anywhere:
“`bash
sudo find / -type f -size +1G -exec ls -lh {} ; 2>/dev/null
“`
Review the output carefully before deleting anything. System files can be large for good reasons.
Step 6: Check for Filesystem Corruption
If nothing else works, your filesystem might have issues. Boot from a Ubuntu live USB and run:
“`bash
sudo fsck /dev/sda1
“`
Replace /dev/sda1 with your actual partition. This is ideal for situations where other solutions haven’t revealed the problem.
Likely Causes
Cause #1: Inode Exhaustion
Your filesystem has a fixed number of inodes (file slots) set during formatting. Each file and directory uses one inode, regardless of size. Having millions of tiny files can exhaust inodes while barely using disk space.
To check: Run `df -i` and look for 100% usage. Common culprits include mail spool directories, PHP session files, or node_modules folders with thousands of tiny files.
To fix: Delete unnecessary small files. For development machines, clearing old node_modules directories often frees thousands of inodes. For servers, check /var/spool and /tmp for accumulation.
Cause #2: Deleted Files Still Open
When you delete a file in Linux, it only disappears when no process has it open. Database systems, log writers, and media servers commonly hold deleted files open, preventing space recovery.
To check: Use `sudo lsof | grep deleted` to see held files. Large database files and logs are typical offenders.
To fix: Restart the offending service. For MySQL: `sudo systemctl restart mysql`. For system logs: `sudo systemctl restart rsyslog`. A full reboot guarantees all held files release.
Cause #3: Reserved Root Space
Ubuntu reserves 5% of each partition for root-only use by default. On large drives, this can be gigabytes of “missing” space that df counts as used.
To check: Run `sudo tune2fs -l /dev/sda1 | grep Reserved` (adjust device name as needed).
To fix: Reduce the reservation to 1% with `sudo tune2fs -m 1 /dev/sda1`. This is best used in desktop environments where you don’t need emergency root space.
When to Call Expert Help
Seek professional assistance if you notice these warning signs:
- Multiple filesystems showing corruption errors
- System files mysteriously disappearing
- Disk space fluctuating wildly without explanation
- Important data at risk and no recent backups
Don’t risk data loss by experimenting with filesystem repairs on production systems. A Linux system administrator can safely diagnose complex storage issues and recover data if needed. Most hosting providers offer emergency support for server disk issues.
Copy-Paste Prompt for AI Help
If you need more specific guidance, paste this into ChatGPT or Claude:
“I’m running Ubuntu and getting ‘disk full’ errors, but df -h shows I have XX GB free space available. I’ve checked with df -i and inode usage is at XX%. The lsof command shows [describe any deleted files you found]. My main partition is /dev/sdXX and I’m running Ubuntu version XX. What specific commands should I run to diagnose and fix this issue without losing data?”
Replace the XX placeholders with your actual values before pasting. This gives AI assistants the context needed for targeted troubleshooting steps.