Move /tmp to RAM

mountramtmpfs

I am trying to move /tmp to RAM and obey good practice:

  • /var/tmp should NOT be placed in tmpfs, as it must survive reboots

  • not mount /tmp as a stand-alone tmpfs, but rely on /dev/shm or /run/shm

However, things have changed between 2.6 and 3.2 kernels :

Changes to the configuration and defaults of tmpfs filesystems

On 3.2 kernel, use RAMTMP=yes in /etc/default/tmpfs.

My question is: how can I achieve this goal with older kernels ?

My choice is nor to modify /etc/fstab neither this :

mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp

Is there something like RAMTMP for 2.6 kernels ?

Best Answer

You don't have to do all that, you can just mount /tmp as tmpfs by using a line like the following in /etc/fstab:

tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0

You can also do it live (but bear in mind stuff that is currently in /tmp on your current filesystem will not be able to be accessed except through the inode and currently open file descriptors, so you should really do this by modifying /etc/fstab and rebooting):

mount -o mode=1777,nosuid,nodev -t tmpfs tmpfs /tmp

Note that a tmpfs can swap. If you want a truly RAM-only filesystem, use ramfs.

Related Question