Have you ever wanted a temporary working space with read/write access for testing purposes? Good! I know a simple workaround to mount a temporary partition in RAM in Linux. You can use it like an use and throw partition. Meaning - the partition and all the data in it will be gone once you rebooted the system. Because it is created in tmpfs (i.e. RAM,) isn't? So you don't even bother to manually delete the partition(s).
What is tmpfs?
As the name says, tmpfs is a temporary filesystem that is created in memory or swap partition(s). In Linux and Unix systems, some directories like "/tmp" and "/var/run" are mounted on this filesystem. Anything saved in these folders will be automatically cleared upon reboot. We can also use tmpfs filesystem for programs or tasks that requires a lot of read/write operations to improve their performance. For example, we already have shown you that relocating your browsers' profile into tmpfs will significantly improve their speed and responsiveness.
Mount A Temporary Partition In RAM In Linux
To mount a temporary partition in memory in Linux, simply run the following command as root or sudo user:
# mount -t tmpfs tmpfs /mnt -o size=100m
The above command will create a temporary partition with size 100 MB in tmpfs and mount it under /mnt directory.
You can verify if this temporary partition is mounted or not using "mount" command:
Sample output from my CentOS 8 server:
[...] tmpfs on /mnt type tmpfs (rw,relatime,seclabel,size=102400k)
Yes, it is mounted!
Let us examine the /mnt directory space using "df" command:
# df -h /mnt/
Filesystem Size Used Avail Use% Mounted on tmpfs 100M 0 100M 0% /mnt
As you can see, the size of the temporary partition is 100M.
Now you can use this partition space for any purpose. Save some files and/or directories in it and reboot the system to see if they are still available. Once you reboot the system, the partition including its contents will be gone!
Since it is temporary partition, you shouldn't save any important data in it. This partition space is purely for testing purposes.
- How To Write Log Files In RAM Using Log2ram In Linux
- The mktemp Command Tutorial With Examples For Beginners
- How To Improve Application Startup Time In Linux
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!