The wisdom of emptying /tmp at boot time

opensuse 13.1

While researching another topic, I came across a couple of suggestions in posts that emptying /tmp at boot time is a useful procedure, especially for reclaiming disk space. “Hmm,” I thought, “maybe so.”

I would implement it by adding “@reboot cd /tmp; rm -fr *” to the root crontab.

Is this a wise thing to do?
What are its counterindications?

I think it would be a better idea to use the systemd cleaning.

Take a peek at:

/usr/lib/tmpfiles.d/tmp.conf

If you make a copy of it in /etc/tmpfiles.d/ and edit that, it’ll override the defaults.

man tmpfiles.d will tell you all kind of fun things you can specify.

This is a not unnormal behaviour practised by many Unix/Linux system managers.

It is also not unusual to make /tmp a separate file system of type tmpfs (or similar), that is in RAM, which will have almost the same effect (deletion is on shutdown and not direct after boot, but who will see the difference?)

There is still the YaST way to configure this (YaST > System > /etc/sysconfig Editor and then System > Cron > CLEAR_TMP_DIRS AT_BOOTUP and other fine tuning parameters there also) but I am not sure that it still works since systemd.

I had it alwyas on and never experienced any negative effects (but end-users should be teached that /tmp is not for storing things themselves with a garantee it will be there after some time).

Of course, when you do not boot your system to often (say, once a year), the cleaning effect is not great.

Yeah you’re right hcvv, the tmpfiles thing doesn’t work with systemd any more - I noticed when I jumped to 13.1 myself, you now you need to use the tmp.conf method.

No need to clear the tmp files anymore.

Aside from it now being deployed as tmpfs, I think it was in the 12.3 notes(someone needs to check exactly when) the tmp directory was cleared automatically on shutdown anyway.

TSU

That’s plain wrong.

/tmp IS NOT and NEVER WAS setup as tmpfs on openSUSE.

And it is not cleaned by default either, at least not in 13.1:
See the shipped /usr/lib/tmpfiles.d/tmp.conf:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
# SUSE policy: we don't clean those directories
d /tmp 1777 root root -
d /var/tmp 1777 root root -

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-*
x /var/tmp/systemd-private-*
X /tmp/systemd-private-*/tmp
X /var/tmp/systemd-private-*/tmp

Not with openSUSE to date.

I copied tmp.conf to /etc/tmpfile.d/ and

changed
d /tmp 1777 root root -
to
d /tmp 1777 root root 1d

Which, AIUI, at boot time deletes all files and dirs older than 1 day in the /tmp/ directory. If I changed the number to 0 (zero), all files and dirs would be deleted.

… and not in 12.1 nor 12.3, either. I doubt it ever was cleaned by default.

BTW: /var/tmp also is not cleaned by default.

Along the same idea, I decided to put /tmp in memory. This is simply done by adding a line to /etc/fstab:


tmpfs          /tmp     tmpsfs size=100m     0 0

Every time you boot it will start empty. As an unexpected bonus, this make the entire system much faster!
This makes sense since lots of software write to /tmp as they start or during operations and now the same
is done purely in memory.

The main issue you will find is size. Many software which require huge temporary files such as autopano or
k3b, let you specify additional paths to circumvent this.

  • Itai

For me using 13.1 the /tmp files did fill up & yes the Yast /etc/sysconfig editor way no longer works.
Now I’m one of those odd people that turns off my PC now & again so I did this added these lines in /usr/lib/tmpfiles.d

D /tmp 1777 root root 1s
D /var/tmp 1777 root root 1s
d /tmp/.cache 1777 root root 1s

So that it looks like this:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
# SUSE policy: we don't clean those directories
D /tmp 1777 root root 1s
D /var/tmp 1777 root root 1s
d /tmp/.cache 1777 root root 1s

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-*
x /var/tmp/systemd-private-*
X /tmp/systemd-private-*/tmp
X /var/tmp/systemd-private-*/tmp

My /tmp files don’t fill up any more.
The only drawback is that I lose some vmware files the vmet & such but there’s no problem to restoring those.

As the man pages say, you should NOT change in /usr/lib/tmpfiles.d/tmp.conf. You should copy that file to /etc/tmpfiles.d/tmp.conf and do the changes there.

Configurations are in /etc (and it is always wise to make backups of all in there). /usr contains installed files that should not be changed. On a re-install (e.g. because of a security patch) it might be overwritten with the “correct” contents again. And an in depth security checking tool might sound the alarm.

Well, it was indeed cleaned by default on 12.3, when systemd-tmpfiles was introduced. At least I remember reading complaints about that after 12.3 was released, and the 12.3 release notes (openSUSE 12.3 Release Notes) would indicate that too:

**5.2. systemd: Cleaning Directories (/tmp and /var/tmp)
**By default, systemd cleans tmp directories daily as configured in /usr/lib/tmpfiles.d/tmp.conf. Users can change it by copying /usr/lib/tmpfiles.d/tmp.conf to /etc/tmpfiles.d/tmp.conf and modifying the copied file. It will override /usr/lib/tmpfiles.d/tmp.conf.

Note: systemd does not honor obsolete sysconfig variables in /etc/sysconfig/cron such as TMP_DIRS_TO_CLEAR.

Here’s what tmp.conf contains in 12.3:

# Clear tmp directories separately, to make them easier to override
d /tmp 1777 root root 10d
d /var/tmp 1777 root root 30d

So /tmp is cleaned after 10 days, and /var/tmp after 30 days.

The defaults got changed then again for 13.1.

BTW: /var/tmp also is not cleaned by default.

Yes. Except in 12.3 it was cleaned as well.

Two questions:

  1. Isn’t there a typo in the third field (tmps
    fs)? When yes, then does it work, or did you not copy/paste as you suggest with the CODE tags? 1. As the permission bits for /tmp should include the t-bit, shouldn’t you have added the mode=1777 option?

YaST > System > /etc/sysconfig editor now suggests that you can configure something usefull there, but it is ignored. Is this worth a bug report?

I do not know exacly how YaST handles this, but my idea is that it simply offers all parameters in all files in /etc/sysconfig. In that case the file /etc/sysconfig/cron should be adaptd/removed and YaST would follow automaticaly.

Something I do not quite understand is that I assume that /etc/sysconfig/cron is a configuration file belonging to one or more cron jobs. But cron wasn’t replaced by systemd, or am I wrong here? Is that cron job removed and did they forget to remove it’s config file?

While an entry in fstab works of course, you could also use the shipped tmp.mount systemd unit.
This would mount /tmp as a tmpfs:

systemctl start tmp.mount

I don’t know at the moment how you would enable this at boot though. “systemctl enable” does not work, maybe you would have to create a symlink manually. This should enable it, but I’m not sure whether this is the best way:

ln -s /usr/lib/systemd/system/tmp.mount /etc/systemd/system/multi-user.target.wants

If you do want to set the maximum size (default is half of your RAM), fstab is the only way though AFAIK.

This has been reported already:
https://bugzilla.novell.com/show_bug.cgi?id=860058
https://bugzilla.novell.com/show_bug.cgi?id=877241
https://bugzilla.novell.com/show_bug.cgi?id=721682
https://bugzilla.novell.com/show_bug.cgi?id=812421

And it is mentioned in the release notes.

I do not know exacly how YaST handles this, but my idea is that it simply offers all parameters in all files in /etc/sysconfig.

Yes.
In that case the file /etc/sysconfig/cron should be adaptd/removed and YaST would follow automaticaly.

Something I do not quite understand is that I assume that /etc/sysconfig/cron is a configuration file belonging to one or more cron jobs.

Yes, and some options apply to cron itself.

But cron wasn’t replaced by systemd, or am I wrong here?

Not yet, at least not as default.

Is that cron job removed and did they forget to remove it’s config file?

Yes.
You could of course just copy over the file in /etc/cron.daily from an earlier openSUSE version, then those variables would have effect again… :wink:

Thanks for the confirmation and the additional information.

On 2014-08-15 03:16, jimoe666 wrote:
>
> Miuku;2659209 Wrote:
>> I think it would be a better idea to use the systemd cleaning.

> I copied tmp.conf to /etc/tmpfile.d/ and
>
> Code:
> --------------------
> changed
> d /tmp 1777 root root -
> to
> d /tmp 1777 root root 1d
> --------------------
>
> Which, AIUI, at boot time deletes all files and dirs older than 1 day in
> the /tmp/ directory. If I changed the number to 0 (zero), all files and
> dirs would be deleted.

I’m unsure when it is done. Only at boot, or periodically? I think the
later.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-08-15 12:06, wolfi323 wrote:

> Yes.
> You could of course just copy over the file in /etc/cron.daily from an
> earlier openSUSE version, then those variables would have effect
> again… :wink:

That’s something I’m considering doing…


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)