Mount /tmp to RAM and systemd

/tmp is a system section that is rather active. Temporary downloads get directed there. Package manager (system updater) works through it. Building packages, if not specifically directed elsewhere, also works through the same section.

Why mount /tmp to RAM?

If your hardware uses SSD instead of HDD, you may want to reduce disk activity as SSD is sensitive to it and supposedly gets worn out easily. Reduced number of disk writes can be achieved by mounting /tmp to RAM. There are instructions on the net how to do it.

However, systems built around systemd may already direct /tmp to RAM out of the box. I don’t know if all systemd distros do this, but Manjaro does. More specifically, systemd treats /tmp as tmpfs, which means /tmp is directed both to RAM and swap.

Why not mount /tmp to RAM?

Allowing /tmp to operate in RAM is desirable, if the system disk is an SSD instead of HDD. But when you use HDD, which is more likely, and you compile source into packages every once in a while with relatively limited RAM, then it’s more desirable to have /tmp operate on the disk rather than in RAM. When you compile code into packages and RAM runs out of space, you will get an error.

Find out if /tmp is treated as tmpfs

In terminal, type:

df -h

The result may be like this:

/dev/sda6           15G    6,3G  8,3G  44% / dev                3,9G       0  3,9G   0% /dev run                3,9G    9,0M  3,9G   1% /run tmpfs              3,9G    272K  3,9G   1% /dev/shm tmpfs              3,9G       0  3,9G   0% /sys/fs/cgroup tmpfs              3,9G     20K  3,9G   1% /tmp

Find /tmp in the last column and see if it says tmpfs in front of it in the first column. If yes, and you use HDD and have limited RAM, consider changing the situation.

Pointing /tmp to HDD

In distros with systemd, the solution is:

systemctl mask tmp.mount

After this, df -h should result in something like this:

/dev/sda6           15G    6,3G  8,3G  44% / dev                3,9G       0  3,9G   0% /dev run                3,9G    9,0M  3,9G   1% /run tmpfs              3,9G    272K  3,9G   1% /dev/shm tmpfs              3,9G       0  3,9G   0% /sys/fs/cgroup

Plainly, /tmp section should vanish. May take a reboot for full completion of the change.

Non-systemd

In other distros it’s more likely that /tmp was not pointed to RAM in the first place. If it was, it should be possible to change this by editing and reloading /etc/fstab.

4 Replies to “Mount /tmp to RAM and systemd”

  1. You mean df -h? Depends on what distro you have. If your distro does not come pre-configured to mount /tmp to RAM, then df -h should exactly not show the /tmp directory.

    My post is about Manjaro, which comes with systemd and is pre-configured to mount /tmp to RAM. In that case df -h displays the /tmp directory as tmpfs.

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *