Last Updated on 2 months by Sachin G
This blog post provides a practical guide on utilizing tmpfs
Linux systems. tmpfs
is a temporary filesystem that resides in RAM, offering faster access compared to traditional disk storage. It’s particularly useful for handling temporary files, application caches, and log files, thereby enhancing system performance.
What is tmpfs in Linux?
tmpfs
is a type of RAM-based filesystem that uses volatile memory to store data temporarily . 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.
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. Linux administrators often prefer it over ramfs
Due to its better memory management and security.
Benefits of Using tmpfs
Here are several advantages of using tmpfs
as your in-memory filesystem in Linux:
- Blazing-fast read/write speeds
- Automatic cleanup on reboot
- Dynamic space allocation
- Better suited for ephemeral storage, Linux needs
- Supports permission handling and size limits
It’s also frequently used for volatile storage in Linux environments where performance matters more than persistence.
How to Create tmpfs in Linux
Step 1: Check Support
First, confirm before creating that your Linux kernel supports tmpfs. Most modern Linux kernels support it by default.
Step 2: Create and Mount tmpfs
The filesystem is automatically created when mounting via a command such as the following. We will see how to mount tmpfs in a Linux system. To create a tmpfs mount manually, use the Linux mount command. 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 .
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.
tmpfs vs ramfs in Linux
Want to tune tmpfs for caching or heavy workloads? Here are some quick tips:
- Don’t oversize the mount — leave RAM for the OS.
- Use
noatime
to reduce write metadata overhead. - Monitor
/proc/meminfo
to ensure you’re not running low on memory.
These tweaks help ensure optimal tmpfs performance tuning in Linux environments.
Distribution-Specific tmpfs Use Cases
Depending on your Linux distro, you may need to tweak things slightly. Here are distro-specific terms you may come across:
- Red Hat tmpfs setup is commonly used in
/run
or/var/tmp
. - Ubuntu tmpfs setup often defaults in
/tmp
. - Debian memory mount tmpfs might be configured during init.
- CentOS tmpfs tutorial paths are similar to RHEL.
- SUSE Linux tmpfs usage often integrates with YaST.
- Arch Linux mount tmpfs can be customized via
fstab
or systemd units.
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.
I’m Sachin Gupta — a freelance IT support specialist and founder of techtransit.org. I’m certified in Linux, Ansible, OpenShift (Red Hat), cPanel, and ITIL, with over 15 years of hands-on experience. I create beginner-friendly Linux tutorials, help with Ansible automation, and offer IT support on platforms like Upwork, Freelancer, and PeoplePerHour. Follow Tech Transit for practical tips, hosting guides, and real-world Linux expertise!