How to Use tmpfs on RHEL / CentOS 7.0

May 19, 2015 | By in FILE SYSTEM, LINUX HOWTO
| Reply More

Today we will talk about tmpfs CentOS 7 a file system that will keep all files and folders in the virtual memory of the operating system as opposed to actually writing them to the disk. This means that all the content in tmpfs is temporary in the sense that it’s not permanently written to the disk and in case the tmpfs is unmounted, the system is rebooted or the power is cut all content will be lost. From a technical point of view tmpfs puts everything in the kernel internal cache and then grows or shrinks to accommodate the files it contains ans is able to swap unneeded pages out of swap space.

By default CentOS uses tmpfs for various things as you can see from the output of the df –h command:

# df –h


/dev - directory contains the special device files for all the devices.
/dev/shm – contains shared memory allocation
/run - used for system logs
/sys/fs/cgroup - used for cgroups, a kernel feature to limit, police and account the resource usage of certain processes

One use of tmpfs is to obviously use it as a /tmp folder, you can do this in 2 ways:

Using systemctl to enable tmpfs in /tmp

You can use the systemctl command to enable tmpfs in the /tmp folder, first use the following command to check if this feature is not already enabled:

# systemctl is-enabled tmp.mount

Will show the current status of settings you can use the following command to enable it:

# systemctl enable tmp.mount


This will have the system controlling the /tmp folder and mount a tmpfs in it.

Manually mounting a /tmp/fs

You can also manually add a tmpfs in /tmp by adding the following line to /etc/fstab:

tmpfs /tmp tmpfs size=512m 0 0

And then running the mount command like this:

# mount –a


This should make the tmpfs show in df –h, also it will automatically mount it the next time you reboot.

Creating a tmpfs on the fly

If for some reason you wish to create a tmpfs in a folder on the fly you can always use the following command:

# mount -t tmpfs -o size=1G tmpfs /mnt/mytmpfs

Of course you can specify any size you wish in the size option and any mount point you wish, just remember it must be a valid directory.


Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.