Step-by-step guide to create, mount, and benchmark a tmpfs RAM disk on Linux, including persistent configuration using /etc/fstab
How to Configure a tmpfs RAM Disk on Linux
This guide explains how to create and configure a RAM-based filesystem using tmpfs on Linux systems, including mounting, persistence, and performance testing.
Prerequisites
- Root or sudo access
- Available system memory
- Basic familiarity with Linux command line
1. (Optional) Install Monitoring Tools
Install htop to monitor memory usage:
dnf install htop -y
2. Create a Mount Point
Create a directory for the RAM disk:
sudo mkdir /mnt/ramdisk
Set permissions (optional, depending on use case):
sudo chmod 777 /mnt/ramdisk
3. Mount the RAM Disk
Mount a tmpfs filesystem with a defined size:
sudo mount -t tmpfs -o size=4G ramdisk /mnt/ramdisk
This creates a temporary RAM-backed filesystem limited to 4GB.
4. Configure Auto-Mount at Boot
Edit /etc/fstab
sudo nano /etc/fstab
Add Entry
tmpfs /mnt/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=4096M 0 0
Alternative example:
plextmp /tmp/ramdisk tmpfs defaults,size=12G,x-gvfs-show 0 0
Key options:
- size – Maximum RAM usage
- nodev – Disable device files
- nosuid – Ignore SUID bits
- noexec – Prevent execution of binaries
5. Apply Mount Without Reboot
systemctl daemon-reload
sudo mount -a
This applies the fstab configuration immediately.
6. Test RAM Disk Performance
Write Test
sudo dd if=/dev/zero of=/mnt/ramdisk/testfile bs=4k count=1000000
sudo dd if=/dev/zero of=/tmp/testfile bs=4k count=1000000
Read Test
sudo dd if=/mnt/ramdisk/testfile of=/dev/null bs=4k count=1000000
sudo dd if=/tmp/testfile of=/dev/null bs=4k count=1000000
These tests compare RAM disk performance with standard disk storage.
7. Clean Up Test Files
rm -f /mnt/ramdisk/testfile
rm -f /tmp/testfile
Best Practices
- Do not allocate more RAM than the system can safely provide
- Use RAM disks for temporary or high-speed workloads only
- Remember that data in tmpfs is lost on reboot
- Monitor memory usage to prevent system instability
Use Cases
- Temporary file storage
- High-speed caching
- Build environments
- Application scratch space
Summary
A tmpfs RAM disk provides extremely fast storage by using system memory. It is ideal for temporary workloads and performance-sensitive applications, but should be used carefully due to its volatile nature.