Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After seeing the comment by Anonymous on the question How is the /tmp directory cleaned up?, I found that it would be a great idea to implement on my system, since I have 16GB of RAM and I never used all of it.

My temporary files never get written to the disk. They get written to a RAM disk. I did put tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0 in /etc/fstab.

My question is:

Can I set a maximum value for RAM Usage for /tmp? And in that case, what would happen if the maximum amount got exceeded, would it write into the hard-disk drive?

I have read this solution which states:

mkdir -p /tmp/ram
sudo mount -t tmpfs -o size=512M tmpfs /tmp/ram/

But in my understanding, this won't be a permanent solution. If I need it to be permanent, it has to be added to the /etc/fstab configuration file.

If this is the correct solution, how can I transform that mount command into a line in /etc/fstab?

share|improve this question
this is also a good idea if you have and SSD as you will not 'consume' it with not useful writings ... – Postadelmaga Apr 2 '14 at 10:47
up vote 46 down vote accepted

You are absolutely right. The according fstab entry would look like this:

tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0

Please note:

As tmpfs gets filled up, it will behave as any physical harddrive by giving an "not enough space" error. While rebooting (and thus emptying the cache) will fix this, you may run into trouble when a single operation consumes more space to begin with than there's space on tmpfs. In this case your computer will start to swap from ram to disk, which will make your system crawl to a halt, given you've got a swap partition to begin with, of course.

Considering this, a size of 512MB might be far too less nowadays, since much more ram is in existence in modern machines and it has become much cheaper. Since you've already got 16GB of ram, using the default value of half your ram for tmpfs should more than suffice for almost all scenarios. To use the default value, simply leave out the size=512M entry in your /etc/fstab file.

Another note:

You can quite as easily mount other system folders into ramdisk as well, such as



/var/log/apt (use only defaults,noatime without mode= or nosuid)

But beware: the same rules apply as above, running out of space might cause major trouble. E.g. imagine running out of space for /var/log/apt will render you unable to install any programs! Furthermore, loading /var/log folders into ramdisk will delete all your log files upon reboot, so you won't be able to debug your system if anything unexpected happens. So use these settings at your own risk!

Editorial note: I removed the /run in tmpfs mount option since this folder and its subfolders are already mounted in tmpfs by default.

share|improve this answer
If i'm not wrong, /var/tmp/ is for keeping files after reboot. Thats the main difference between this and /tmp/ , so YOU should not move /var/tmp to ram. – user285767 May 27 '14 at 13:20
If Ubuntu runs out of 4GB tmpfs, will it use my 20GB SWAP partition? – loostro Jun 24 '14 at 16:30
Yes, I'll need to add this, too. As soon as tmpfs exeeeds its limits, it'll extend to swap partition (give there is one). – FuzzyQ Jun 24 '14 at 19:10
Does allocating half your RAM to this mean that half your RAM is reserved for the RAMDISK, or is it only a cap to what the RAMDISK may consume, and whatever is not in use is free RAM that gets assigned to whatever program needs RAM?? – matt Jan 19 '15 at 15:01
@matt It's only a cap. – FuzzyQ Jan 19 '15 at 16:04

Your Answer


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.