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 devicewriting to/tmp df -h /tmpshows tmpfs at 100% usagecc1(C compiler) fails during build:cannot create temporary file- Package manager fails during installation extracting to
/tmp sshdfails to create authentication sockets- Python fails with
OSError: [Errno 28] No space left on device
Common Causes
- Large files written to
/tmpby applications instead of dedicated directories systemd-tmpfilescleanup not running or misconfigured/tmpmounted 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
/tmpfor layer extraction
Step-by-Step Fix
- 1.Check tmpfs usage:
- 2.```bash
- 3.df -h /tmp
- 4.df -h /dev/shm
- 5.# Find large files in /tmp
- 6.sudo find /tmp -type f -size +100M -exec ls -lh {} \;
- 7.
` - 8.Identify which processes are using /tmp space:
- 9.```bash
- 10.sudo lsof +D /tmp | awk '{print $1, $2, $7}' | sort -k3 -n -r | head -20
- 11.sudo du -sh /tmp/*/ 2>/dev/null | sort -h | tail -10
- 12.
` - 13.Clean up orphaned temporary files:
- 14.```bash
- 15.# Remove files older than 10 days
- 16.sudo find /tmp -type f -atime +10 -delete
- 17.sudo find /tmp -type d -empty -delete
- 18.# Force-run systemd tmpfiles cleanup
- 19.sudo systemd-tmpfiles --clean
- 20.
` - 21.Resize tmpfs on the fly (temporary fix):
- 22.```bash
- 23.sudo mount -o remount,size=4G /tmp
- 24.# Verify
- 25.df -h /tmp
- 26.
` - 27.Make tmpfs size change persistent in fstab:
- 28.```bash
- 29.sudo nano /etc/fstab
- 30.# Add or modify:
- 31.tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,size=4G 0 0
- 32.
` - 33.Configure automatic tmpfiles cleanup:
- 34.```bash
- 35.sudo nano /etc/tmpfiles.d/tmp.conf
- 36.
` - 37.Add:
- 38.
` - 39.# Clear /tmp files not accessed in 7 days
- 40.q /tmp 1777 root root 7d
- 41.# Clear /var/tmp files not accessed in 30 days
- 42.q /var/tmp 1777 root root 30d
- 43.
`
Prevention
- Configure
systemd-tmpfiles-clean.timerto run daily:sudo systemctl enable --now systemd-tmpfiles-clean.timer - Monitor tmpfs usage in addition to physical disk monitoring
- Use
TMPDIRenvironment 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
/tmpand redirect to dedicated partitions