When a program needs a place to store files temporarily on a Linux server, a RAM file system keeps disk storage free for other tasks.
Using a RAM file system for directories containing files you don't want has two benefits: It's blazing fast and it prevents your server from filling up with trash.
There are plenty of directories where a RAM file system makes sense, such as a printer spool directory, or
We call this a RAM file system, but in reality it is just a fake device that you can address as if it were a real file system, without actually formatting it. You just need to connect a mount point to RAM, where the files will live as long as necessary.
The Linux kernel provides two options for creating a RAM file system: ramfs and tmpfs. When you learn ramfs, you will understand why tmpfs is better.
With the command mount -t ramfs none /tmp, everything that will be written to the /tmp directory is really written in RAM. The ramfs file system doesn't really know how to restrict the quantity of RAM available to your temporary file system.
To make your /tmp directory available in a specified quantity of RAM, use mount -t tmpfs -o size=1g none /tmp. This allocates one gigabyte of RAM to the /tmp directory. Choosing tmpfs allows the administrator to check on file space available with df -h, and will prevent you from writing more than one gigabyte to /tmp.
The RAM file system can also be made available automatically after a server reboot. In /etc/fstab, use a line such as this one:
none /tmp ramfs size=1g 0 0
In /etc/fstab, the first column typically indicates the name of the device that needs to be mounted. As there is no real device involved here, put none in this column. The next two columns indicate the directory on which to mount it and the file system type to be mounted: /tmp and ramfs in this example. You'll specify the size that you want to allocate to the RAM file system in the options field; in this case, we're allocating one gigabyte. Since the file system does not exist on the disk, fill out the last two columns with zeros.
This was first published in March 2014