tmpfs

From LinuxReviews
Jump to navigationJump to search

tmpfs is the standard partition type and filesystem for a Linux RAM-drive. It can be created on each boot using a configuration line in /etc/fstab and it can also be created run-time using the mount command. tmpfs RAM drives can be made larger than the amount physical RAM on the machine as long as there is enough swap space available. Contents on tmpfs filesystems smaller than the amount of physical RAM will also be swapped if the amount of free memory is too low. tmpfs RAM drives should ideally be limited to a percentage of system RAM which does not cause any swapping.

HOWTO create a Linux RAM drive[edit]

Creating a tmpfs is a simple matter of mounting one to any existing directory by using the mount command as root. You need tell mount that you want the -type tmpfs and specify the -option size= with a value. Your fine mount command will also need a filesystem type and in this case it's also tmpfs. It also needs to end with a existing directory like /mnt/ramdrive. Thus; this fine example will make a 2 GB ramdrive in the location /tmp/ramdisk:

mount -t tmpfs -o size=2048m tmpfs /mnt/ramdrive

Do be aware that it will fail miserably if you are not root. You can use sudo to run it as root. The above command will also fail if you never created a /mnt/ramdisk folder.

Running a command as root on every boot is not desired or required if you want to always have a RAM drive available. Placing this line in /etc/fstab will accomplish the same as the above mount command:

tmpfs /mnt/ramdrive tmpfs nodev,nosuid,noexec,nodiratime,size=2048M 0 0

Why is it called "tmpfs"?[edit]

The name ramfs may, at first glance, appear to be more logical. And perhaps it is, there is a Linux filesystem called ramfs. It is older than tmpfs and it has a few disadvantages: ramfs does not support a file system size limit. You can create a ramfs and copy files into it until you run out of memory. It also lacks basic features like showing how much of the file system is used with tools like df. It has therefore been abandoned and everyone uses the new and trendy tmpfs instead.

The name tmpfs does make sense for a RAM drive since it's temporary - pull the power cord and it's gone (unless you have a battery).