• Set up RamFS or TmpFS on Linux

    In the most modern Linux systems, you will find memory-based file systems to make access to disk storage much faster by allocating some RAM space on a disk mount point. But this means that this disk area will be ephemeral and won’t exist anymore after a system reboot. You should never use it for storing persistent data, but rather using it as cache mechanism that needs speed.

    As of today, the two main memory-based file systems are tmpfs and ramfs. Both have their pros and cons, depending on your needs.
    Right now, tmpfs is more and more used in replacement of ramfs.

    Main differences between ramfs and tmpfs are:

    RamFS(older)

    + Can be monitored as cached in memory with free
    + Is not using swap
    – Can’t be limited in size

    TmpFS (newer)

    + Can be monitored with df
    + Can be limited in size
    – Can use swap

    Setup tmpfs

    First create the directory you will use

    # mkdir -p /mnt/tmpfs

    Then mount it as tmpfs (I’m using here 16M)

    # mount -t tmpfs -o size=16m tmpfs /mnt/tmpfs

    You can check that it’s mounted correctly (here I’m already using 21% of the tmpfs)

    # df -k
    Filesystem     1K-blocks      Used Available Use% Mounted on
    tmpfs              16384      3384     13000  21% /mnt/tmpfs
    

    You can also make it automatically mounted by adding this line in your fstab configuration file:

    tmpfs /mnt/tmpfs  tmpfs   nodev,nosuid,noexec,nodiratime,uid=50,gid=50,size=16M   0 0

    Setup ramfs

    First create the directory you will use

    # mkdir -p /mnt/ramfs

    Then mount it as ramfs (I’m using here 16M)

    # mount -t ramfs -o size=16m ramfs /mnt/ramfs

    You can check that it’s mounted correctly

    # mount
    ramfs on /mnt/ramfs type ramfs (rw,size=16m)
    

    You can also make it automatically mounted by adding this line in your fstab configuration file:

    ramfs /mnt/ramfs  ramfs   nodev,nosuid,noexec,nodiratime,uid=50,gid=50,size=16M   0 0