Introduction

Linux tmpfs mounts like /tmp and /dev/shm store files in RAM. When a tmpfs partition reaches capacity, any process attempting to write temporary files fails with No space left on device. This is especially problematic because tmpfs does not appear in standard disk monitoring that only checks physical partitions, and /tmp is used by virtually every application on the system.

Symptoms

  • Applications crash with No space left on device writing to /tmp
  • df -h /tmp shows tmpfs at 100% usage
  • cc1 (C compiler) fails during build: cannot create temporary file
  • Package manager fails during installation extracting to /tmp
  • sshd fails to create authentication sockets
  • Python fails with OSError: [Errno 28] No space left on device

Common Causes

  • Large files written to /tmp by applications instead of dedicated directories
  • systemd-tmpfiles cleanup not running or misconfigured
  • /tmp mounted with too-small size limit in fstab (default is 50% of RAM)
  • Log files or core dumps accidentally directed to /tmp
  • Docker or container runtimes using /tmp for layer extraction

Step-by-Step Fix

  1. 1.Check tmpfs usage:
  2. 2.```bash
  3. 3.df -h /tmp
  4. 4.df -h /dev/shm
  5. 5.# Find large files in /tmp
  6. 6.sudo find /tmp -type f -size +100M -exec ls -lh {} \;
  7. 7.`
  8. 8.Identify which processes are using /tmp space:
  9. 9.```bash
  10. 10.sudo lsof +D /tmp | awk '{print $1, $2, $7}' | sort -k3 -n -r | head -20
  11. 11.sudo du -sh /tmp/*/ 2>/dev/null | sort -h | tail -10
  12. 12.`
  13. 13.Clean up orphaned temporary files:
  14. 14.```bash
  15. 15.# Remove files older than 10 days
  16. 16.sudo find /tmp -type f -atime +10 -delete
  17. 17.sudo find /tmp -type d -empty -delete
  18. 18.# Force-run systemd tmpfiles cleanup
  19. 19.sudo systemd-tmpfiles --clean
  20. 20.`
  21. 21.Resize tmpfs on the fly (temporary fix):
  22. 22.```bash
  23. 23.sudo mount -o remount,size=4G /tmp
  24. 24.# Verify
  25. 25.df -h /tmp
  26. 26.`
  27. 27.Make tmpfs size change persistent in fstab:
  28. 28.```bash
  29. 29.sudo nano /etc/fstab
  30. 30.# Add or modify:
  31. 31.tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,size=4G 0 0
  32. 32.`
  33. 33.Configure automatic tmpfiles cleanup:
  34. 34.```bash
  35. 35.sudo nano /etc/tmpfiles.d/tmp.conf
  36. 36.`
  37. 37.Add:
  38. 38.`
  39. 39.# Clear /tmp files not accessed in 7 days
  40. 40.q /tmp 1777 root root 7d
  41. 41.# Clear /var/tmp files not accessed in 30 days
  42. 42.q /var/tmp 1777 root root 30d
  43. 43.`

Prevention

  • Configure systemd-tmpfiles-clean.timer to run daily: sudo systemctl enable --now systemd-tmpfiles-clean.timer
  • Monitor tmpfs usage in addition to physical disk monitoring
  • Use TMPDIR environment variable to redirect large temporary operations to disk-backed storage
  • Set appropriate size= limits in fstab to prevent tmpfs from consuming all RAM
  • Review application configurations that write large files to /tmp and redirect to dedicated partitions