Last Updated on 1 month by Sachin G

Linux tmpfs uses RAM to store a temporary filesystem.it is typically created on RAM. Since RAM is volatile and faster than static storage and can improve performance if the process involves temporary files. Temporary filesystems (tmpfs) allow users to create and manage volatile storage in RAM. it is an excellent method for handling temporary files and directories, enhancing performance and responsiveness.

In this post, I will share the steps to create and mount on a Linux system. The primary function of a RAM disk is to store application caching folders, log files, or temporary data. It reduces the need for the hard drive, speeding up the process.

Create and Mount tmpfs

Step 1: Check Support

First confirm before creating, that your Linux kernel supports tmpfs. Most modern Linux kernels support by default.

Step 2: Create and Mount tmpfs

The filesystem is automatically created when mounting via a command such as the following From below. we will see how to mount tmpfs in a Linux system machine.

Create a mount folder to use your tempfs RAM disk.

 mkdir /ramdisk 

Use the mount command to create a RAM disk and mount. The below command will mount temporarily, we can use also /etc/fstab for permanent mounting.

Syntax:

 mount -t [TYPE] -o size=[SIZE] [FSTYPE] [MOUNTPOINT]

Mount tmpfs example :

mount -t tmpfs -o size=256M tmpfs /ramdisk 

[TYPE] RAM disk type.
[SIZE] is the size to use for the file system.
[FSTYPE] Type of RAM disk to use.

Example

mount -t tmpfs -o size=256M tmpfs /ramdisk

If you have to make it available after reboot then you can edit the /etc/fstab files and add below the following line:

 tmpfs /ramdisk      tmpfs   size=256M,mode=0777     0   0

In the example [TYPE] of the ramdisk, the size of the Ramdisk will be used for the ramdisk. type of ram disk like ext4, ext3, ext4 ,xfs, tmpfs .

Mounted Partition showing tmpfs

You can see in the above screenshot that /dev/shm is automatically created. It is a temporary storage filesystem that uses RAM, known as tmpfs. The latest kernel versions automatically build it as shared memory. It is a writable directory with special sticky bit permissions for security reasons.

If you want to unmount then you can run below :

 umount /ramdisk

Step 3: Utilize tmpfs

With the attachment complete, we can now use it for temporary storage needs. Any files and directories created here will reside in RAM, providing quick access.

According to my view this approach offers an effective solution for managing temporary data efficiently in Linux systems. Whether you require a fast and volatile storage space for caches, logs, or other transient data, it provides a flexible and responsive option. Feel free to experiment with it and customize it to suit your specific requirements.