The /tmp that ate our deployment
Deployment failed with 'No space left on device' while df showed room. /tmp is not a disk — it is an 838MB tmpfs, and filling it breaks shells and cron too.
📜 Table of Contents
📖 Keep reading
The /tmp that ate our deployment
df -h / showed plenty free; /tmp was 100% of 838MB. /tmp is a tmpfs, a filesystem in memory.
Three commands
df -h /tmp
mount | grep ' /tmp '
du -sh /tmp/* 2>/dev/null | sort -rh | head -20
lsof +L1 | head -20
The last one finds deleted-but-open files whose space is not returned until the writer exits. Here du found hundreds of MB of pip-* and deploy-* leftovers.
Why it fails silently
Download, extract to /tmp, install, start. Space runs out during extraction, the script lacks set -e, and the final error says the service failed to start.
set -euo pipefail
avail_mb=$(df -Pm /tmp | awk 'NR==2{print $4}')
[ "$avail_mb" -lt 500 ] && { echo "not enough space in /tmp"; exit 1; }
Where deployment belongs
| Path | Use |
|---|---|
/opt/<app> or /srv/<app> |
Application code |
/var/lib/<app> |
Data needing backups |
/var/tmp |
Temporary files surviving reboot |
/tmp |
Disposable files only |
Point TMPDIR elsewhere if a script insists on /tmp; pip, tar and most build tools respect it.
Resizing carefully
mount -o remount,size=2G /tmp
tmpfs eats RAM, so 4GB of /tmp on a 2GB box invites the OOM killer. For services, PrivateTmp=true gives each unit an isolated, auto-cleaned /tmp.
Preventing a repeat
trap 'rm -rf "$TMPDIR"' EXITin the script.- Monitor tmpfs usage, not just
/. - Run
systemd-tmpfiles --cleanand confirm policy. - Containers often use memory-backed
/tmp— same trap, faster. - Never run a long-lived service from
/tmp.
FAQ
df says space, error says none. You are writing to another mount; check df -h /tmp and df -i.
Deleted files, no space back. lsof +L1 shows the holder; restart it.
Files gone after reboot? By design; nothing important belongs there.
Mount strategy and default sizes differ by distribution; check
/etc/fstabandtmp.mount. 838MB is from this environment.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.