Grimoire-
Command
.es

GNU+Linux command memo

Mount /tmp in a tmpfs

Monter /tmp dans un tmpfs, un système de fichier en mémoire RAM. Accélère le système, économise le disque.

Add this line in /etc/fstab :

tmpfs /tmp tmpfs defaults    0    0
$ su -c 'echo "tmpfs /tmp tmpfs defaults    0   0" >> /etc/fstab'
$ sudo rm -rf /tmp/*
$ sudo reboot

By default, the allocated size is half of the installed RAM. tmpfs will dynamically use only what’s needed. But /dev/shm is already mounted in a tmpfs with this default setting, so mounting a second tmpfs might result in deadlock in case of intensive /tmp usage, as the OOM killer of the kernel can’t free tmpfs spaces.

The maximum size limit of a tmpfs can be set by the size mount option (defaults,size=512M for instance), and adjusted on the fly via : # mount -o remount,size=1G /tmp

Some programs may have an intensive usage of temporary files and could fail because of missing free space in /tmp. Examples : temporary mysql tables, big imagemagick conversions, consultation of big documents (such as PDF) in Firefox, installation of big Python packages via pip.

/var/cache should contain cached files that can be deleted without loss of data (FHS), so it can be monted it tmpfs. apt needs its directories to run : mkdir -p /var/cache/apt/archives/partial, but then it loads its index 14x faster on my setup according to the tests made for Local database speed.

/var/spool/cups/tmp is not specified in the FHS, so it might be mounted in RAM (or even simply redirected to /tmp).

/var/tmp should not be mounted in RAM as it is designated in the FHS as "to be preserved between reboots".
Firefox can be configured to store its cache in /tmp, via about:config, while creating the string key browser.cache.disk.parent_directory with the /tmp value.