A tmpfs mount gives a Linux system a fast temporary workspace whose files disappear when the mount is removed or the machine reboots. It fits build caches, short-lived runtime data, and scratch directories that need a size limit instead of a real disk filesystem.
The mount command creates the filesystem when it attaches the tmpfs type to a directory. The source name is usually tmpfs, while options such as size=, mode=, nodev, and nosuid control the space cap, root directory permissions, and security boundary for that mount.
A tmpfs uses virtual memory and can use swap unless swap is disabled for that mount and kernel support is available. Set a realistic size= value before allowing users or applications to write there, because a full tmpfs returns space errors to writers and an oversized shared tmpfs can pressure memory on the host.
Steps to create a Linux tmpfs mount:
- Create the mount point directory.
$ sudo mkdir -p /mnt/ram-cache
- Mount a sized tmpfs at the directory.
$ sudo mount -t tmpfs -o size=256M,mode=1777,nodev,nosuid tmpfs /mnt/ram-cache
size=256M caps this tmpfs at 256 MiB. mode=1777 gives temporary-directory permissions with the sticky bit, while nodev and nosuid reduce device-file and setuid risk.
- Confirm the active mount options.
$ findmnt --mountpoint /mnt/ram-cache --output TARGET,SOURCE,FSTYPE,OPTIONS TARGET SOURCE FSTYPE OPTIONS /mnt/ram-cache tmpfs tmpfs rw,nosuid,nodev,relatime,size=262144k
- Check the visible capacity.
$ df -hT /mnt/ram-cache Filesystem Type Size Used Avail Use% Mounted on tmpfs tmpfs 256M 0 256M 0% /mnt/ram-cache
df shows the tmpfs size limit, not preallocated RAM. The filesystem consumes memory and swap as files are written.
- Write a test file into the tmpfs.
$ printf 'tmpfs test\n' | tee /mnt/ram-cache/check.txt tmpfs test
- Read the test file from the tmpfs.
$ cat /mnt/ram-cache/check.txt tmpfs test
- Check tmpfs usage after the write.
$ df -hT /mnt/ram-cache Filesystem Type Size Used Avail Use% Mounted on tmpfs tmpfs 256M 4.0K 256M 1% /mnt/ram-cache
- Unmount the tmpfs when the temporary workspace is no longer needed.
$ sudo umount /mnt/ram-cache
Unmounting a tmpfs discards files that only exist inside that mount. Copy needed data to persistent storage before running umount.
Related: How to unmount a disk in Linux
- Confirm the directory is no longer a mount point.
$ mountpoint /mnt/ram-cache /mnt/ram-cache is not a mountpoint
- Confirm the tmpfs-only test file is gone.
$ cat /mnt/ram-cache/check.txt cat: /mnt/ram-cache/check.txt: No such file or directory
- Remove the empty mount point if it was only for this temporary workspace.
$ sudo rmdir /mnt/ram-cache
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.