3

To have /tmp on tmpfs, I know I can use an entry in /etc/fstab, but I do not understand the role of /etc/default/tmpfs mentioned sometimes, and in what case I need to create or modify it.

Recently, I often see suggested to use systemd tmp.mount confuguration. For example, on Debian:

$ sudo cp /usr/share/systemd/tmp.mount /etc/systemd/system/
$ sudo systemctl enable tmp.mount

Which of the two methods is more appropriate for everyday use? In what situations one is better than the other? When do I need to deal with /etc/default/tmpfs?

2 Answers 2

8

On some systems, /tmp is a tmpfs by default, and this is the configuration provided by systemd’s “API File Systems”. Fedora-based systems follow this pattern to various extents; Fedora itself ships /usr/lib/systemd/system/tmp.mount and enables it, but RHEL 8 ships it without enabling it. On such systems, masking and unmasking the unit is the appropriate way of disabling or enabling a tmpfs /tmp, as documented in the API File Systems documentation.

Other systems such as Debian don’t ship tmp.mount in a directly-usable location; this is why you need to copy it to /etc/systemd/system if you want to use it. This has the unfortunate side-effect of creating a full override of tmp.mount in /etc, which means that if the systemd package ships a different version of tmp.mount in /lib/systemd/system in the future, it will be ignored. On such systems I would recommend using /etc/fstab instead.

In both setups, /etc/fstab is still the recommended way of customising /tmp mounts, e.g. to change their size; man systemd.mount says

In general, configuring mount points through /etc/fstab is the preferred approach to manage mounts for humans.

and the API File Systems documentation concurs.

Using mount units is recommended for tooling, i.e. for automated configuration:

For tooling, writing mount units should be preferred over editing /etc/fstab.

(This means that tools which want to automatically set up a mount shouldn’t try to edit /etc/fstab, which is error-prone, but should instead install a mount unit, which can be done atomically and can also be overridden by a system administrator using systemd features.)

/etc/default/tmpfs is used by Debian’s sysvinit, so it’s irrelevant with systemd.

0
0

I always disable /tmp being a /tmpfs because it takes away from valuable RAM especially on systems like Raspberry Pi.
Thus, I use systemctl mask tmp.mount to disable it on systemd.
Also, I don't want my /tmp to be cleared with every boot nor do I want to think about storing semi-temporary files in /var/tmp.
Temporary to me means "not system critical" but it doesn't mean "unnecessary between boots".
Thus, I use /tmp for everything with a short lifetime and do housekeeping on it.
So if you work mostly as a single user on your system, I recommend to keep /tmp on the root partition and not separate it at all.
This also allows to temporarily save large files in /tmp like compressed archives, downloads etc. without running out of memory or reserving a large portion of disk space just for /tmp.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .