tmpfs is a temporary filesystem that resides in memory and/or swap partition(s). Mounting directories as tmpfs can be an effective way of speeding up accesses to their files, or to ensure that their contents are automatically cleared upon reboot.
Arch uses a tmpfs
/run directory, with
/var/lock simply existing as symlinks for compatibility. It is also used for
/tmp by the default systemd setup and does not require an entry in fstab unless a specific configuration is needed.
Generally, tasks and programs that run frequent read/write operations can benefit from using a tmpfs directory. Some applications can even receive a substantial gain by offloading some (or all) of their data onto the shared memory. For example, relocating the Firefox profile into RAM shows a significant improvement in performance.
By default, a tmpfs partition has its maximum size set to half of the available RAM, however it is possible to overrule this value.
To explicitly set a maximum size, in this example to override the default
/tmp mount, use the
size mount option:
tmpfs /tmp tmpfs rw,nodev,nosuid,size=2G 0 0
To specify a more secure mounting, specify the following mount option:
tmpfs /www/cache tmpfs rw,size=1G,nr_inodes=5k,noexec,nodev,nosuid,uid=user,gid=group,mode=1700 0 0
See the Security#File systems for more information.man page and
Reboot for the changes to take effect. Note that although it may be tempting to simply run
mount -a to make the changes effective immediately, this will make any files currently residing in these directories inaccessible (this is especially problematic for running programs with lockfiles, for example). However, if all of them are empty, it should be safe to run
mount -a instead of rebooting (or mount them individually).
After applying changes, verify that they took effect by looking at
/proc/mounts and using
$ findmnt /tmp
TARGET SOURCE FSTYPE OPTIONS /tmp tmpfs tmpfs rw,nosuid,nodev,relatime
The tmpfs can also be temporarily resized without the need to reboot, for example when a large compile job needs to run soon. In this case, run:
# mount -o remount,size=4G /tmp
Disable automatic mount
/tmp is automatically mounted as a tmpfs, if it is not already a dedicated mountpoint (either tmpfs or on-disk) in
/etc/fstab. To disable the automatic mount, mask the
tmp.mount systemd unit.
Files will no longer be stored in a tmpfs, but on the block device instead. The
/tmp contents will now be preserved between reboots (they are still cleaned up after 10 days though), which might not be the desired behavior. To regain the previous behavior and clean the
/tmp directory automatically when restarting, consider using :
# see tmpfiles.d(5) # always enable /tmp directory cleaning D! /tmp 1777 root root 0 # remove files in /var/tmp older than 10 days D /var/tmp 1777 root root 10d # namespace mountpoints (PrivateTmp=yes) are excluded from removal x /tmp/systemd-private-* x /var/tmp/systemd-private-* X /tmp/systemd-private-*/tmp X /var/tmp/systemd-private-*/tmp
/tmp is using tmpfs, change the current directory to
/tmp, then create a file and create a symlink to that file in the same
/tmp directory. Permission denied errors are to be expected when attempting to read the symlink due to
/tmp having the sticky bit set.
This behavior can be controlled via
/proc/sys/fs/protected_symlinks or simply via sysctl:
sysctl -w fs.protected_symlinks=0. See Sysctl#Configuration to make this permanent.