Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ?

share|improve this question
    
tmpfs considered harmful. Food for thought. –  sr_ Nov 15 '12 at 8:05
5  
@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 '12 at 10:29
    
@Marco sure, I was just throwing in something I thought related. –  sr_ Nov 15 '12 at 11:14

1 Answer 1

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.

share|improve this answer
    
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 '12 at 0:27
1  
@Massimo My opinion is that the best practise is not to bind mount. It adds unnecessary complexity. –  Chris Down Nov 15 '12 at 0:28
3  
@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. –  Patrick Nov 15 '12 at 1:52
    
@ChrisDown what is bad about bind mount? Also having a single tmpfs might make things simpler right? –  CMCDragonkai Jun 5 at 6:42
    
@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 at 7:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.