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 ?

  • 2
    tmpfs considered harmful. Food for thought.
    – sr_
    Nov 15, 2012 at 8:05
  • 12
    @sr_ Sorry, I strongly disagree with the linked article. /tmp can and should be used for temporary files, that's the whole point of it. /tmp is not supposed to survive a reboot (use /var/tmp for that) and who composes an email half the size of RAM+swap (without saving it)?
    – Marco
    Nov 15, 2012 at 10:29
  • @Marco sure, I was just throwing in something I thought related.
    – sr_
    Nov 15, 2012 at 11:14
  • More context: fedoraproject.org/wiki/Features/tmp-on-tmpfs
    – Nemo
    Jul 19, 2017 at 21:13

3 Answers 3


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.

  • Chris, my point is "best practices". The developers put native support to mount /tmp over .../shm; I read it is better to re-use the same tmpfs.
    – Massimo
    Nov 15, 2012 at 0:27
  • 3
    @Massimo My opinion is that the best practise is not to bind mount. It adds unnecessary complexity.
    – Chris Down
    Nov 15, 2012 at 0:28
  • 5
    @Massimo Where are you finding this 'best practices'? The only reason I can see against mounting /tmp as tmpfs is because you now have 2 potential tmpfs filesystems that can fill up and use more memory (/tmp and /dev/shm). But if you're really concerned about filling up 2 tmpfs mounts, you can decrease the maximum size of the tmpfs mount.
    – phemmer
    Nov 15, 2012 at 1:52
  • @ChrisDown what is bad about bind mount? Also having a single tmpfs might make things simpler right? Jun 5, 2014 at 6:42
  • 2
    @CMCDragonkai Bind mounts are anything but simple internally, they come with quite a few unintuitive caveats that you probably don't intend (a particularly publicised one being the drama surrounding requiring remount for read-only mounts). Just use two tmpfs mounts instead.
    – Chris Down
    Jun 5, 2014 at 7:00

/etc/default/tmpfs is for sysvinit, for systemd (Debian default since jessie) you only need to do:

systemctl enable tmp.mount

and on Debian Stretch or later:

cp /usr/share/systemd/tmp.mount /etc/systemd/system/
systemctl enable tmp.mount

See changelog

Further details on RAMDISK/tmpfs can be found on the SSD Optimization Debian Wiki page.

  • Thanks! This is the right way to move /tmp to tmpfs in Jessie.
    – Yasiru G
    Jan 12, 2016 at 6:28
  • thank you so much! on gentoo i didn't understand why my /tmp is mounted tmpfs. the systemd script tmp.mount does it.
    – ufk
    Mar 11, 2016 at 9:42

I know this is rather old but in Debian-type distributions setting Set RAMTMP, RAMRUN and RAMLOCK in /etc/default/tmpfs (/etc/default/rcS or before wheezy) does the same job.

  • On Ubuntu 16.04.6 LTS: cat /etc/default/tmpfs results in cat: /etc/default/tmpfs: No such file or directory. Do you have a link for setting this up? The answer is almost short enough (and vague enough?) to be a comment. Oct 10, 2020 at 1:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .