Home Linux How To Mount A Temporary Partition In RAM In Linux

How To Mount A Temporary Partition In RAM In Linux

By sk
9.9K views

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:

# mount

Sample output from my CentOS 8 server:

[...]
tmpfs on /mnt type tmpfs (rw,relatime,seclabel,size=102400k)

Create and Mount Temporary Partitions In RAM In Linux

Yes, it is mounted!

Let us examine the /mnt directory space using "df" command:

# df -h /mnt/

Sample output:

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           100M     0  100M   0% /mnt

Mount A Temporary Partition In RAM In Linux

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.

Related read:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More