/tmp not emptying not unmounting

Leap 15
KDE 5

Directory /tmp is not emptying or unmounting. Contains files from months past, including over 100 PDF files left over from Okular. Have also noticed an error message flashing by about /tmp not unmounting during computer restart or shutdown.

drwxrwxrwt   1 root root 6688 Aug 16 10:49 tmp

Hi
As designed… see the output from;


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

When there are messages about /tmp and (un)mounting, you should at least look if it is mounted (that is not a “must”) and how it is mounted:

mount | grep '/tmp'

And no, on openSUSE /tmp is not cleaned at boot by default.
These are my notes on this:

For cleaning /tmp and /var/tmp at boot:

When there is not already a file /etc/tmpfiles.d/tmp.conf create it as a copy

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

Then change the lines

# 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 -

into

# Clear tmp directories separately, to make them easier to override
# My policy: empty /tmp en /var/tmp on boot.
D! /tmp 1777 root root 1d
D! /var/tmp 1777 root root 1d

See

man 5 tmpfiles.d

================================
For making /tmp a tmpfs:
Add an entry into /etc/fstab

tmpfs             /tmp    tmpfs   size=25%,uid=root,gid=root,mode=1777 0 0

See

man 8 mount

specialy the section: Mount options for tmpfs.

Before mounting this file system for the first time (either by command, or by reboot) you should clean the present /tmp directory as good as possible. Existing contents will still occupy disk space when you mount a file system over it.

Why would “as designed” be to allow a temporary directory to fill with files forever until it ultimately consumes all drive space?

Hi
Then I must say you would have something funky going on or applications not cleaning up (a bug report)…?

On my machines here I see less than 200MB of /tmp space usage, end of the day openSUSE leaves these sorts of thing for the user/administrator to configure…

Hi,

To put it in other words, whoever is responsible for dumping files/directories in /tmp should be the one responsible to remove/clean it up. (clean your own…)
otherwise, yeah a bug report is needed…

A few things.

Yes, in original Unix, it was “normal” to clean /tmp on boot. I assume that in many Linux distributions this is still the default. It seems that in the past openSUSE (or it’s forerunners) users have complaint that they lost data they put in /tmp over a (unexpected?) shutdown/boot. As a result the default was changed to what it is now.

As a good system manager, you should watch the filling grade of your file systems and, independent if /tmp is on a separate file system or not, watch /tmp. When /tmp keeps on growing beyond a reasonable size, you should do something about it (as others above already suggested), like:

  • Find out which user(s) is using /tmp as a permanent storage, either on purpose or, unknowingly, by incident and talk to them.
  • Find applications that use /tmp as long time storage over sessions and see if you can configure them to behave better (or even complain to their makers).
  • Change the default of cleaning at boot or using a tmpfs to let it vanish at shutdown (both described above).
  • As actions on shutdown/boot will not help much on systems that are running for days/weeks/months without boot, a cron job to e.g. remove all files not in use and not touched for two days might be something to consider.

May I suggest that, the following systemd services and man page be checked:


 > systemctl list-unit-files | grep -i 'tmp'
tmp.mount                                                        generated
systemd-tmpfiles-clean.service                                   static
systemd-tmpfiles-setup-dev.service                               static
systemd-tmpfiles-setup.service                                   static
systemd-update-utmp-runlevel.service                             static
systemd-update-utmp.service                                      static
systemd-tmpfiles-clean.timer                                     static
 > systemctl status systemd-tmpfiles-clean.service systemd-tmpfiles-clean.timer
● systemd-tmpfiles-clean.service - Cleanup of Temporary Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.service; static; vendor preset: disabled)
   Active: inactive (dead) since Fri 2018-08-17 09:29:32 CEST; 40min ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 12688 ExecStart=/usr/bin/systemd-tmpfiles --clean (code=exited, status=0/SUCCESS)
 Main PID: 12688 (code=exited, status=0/SUCCESS)

● systemd-tmpfiles-clean.timer - Daily Cleanup of Temporary Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.timer; static; vendor preset: disabled)
   Active: active (waiting) since Fri 2018-08-17 09:12:20 CEST; 57min ago
  Trigger: Sat 2018-08-18 09:29:31 CEST; 23h left
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
 > man systemd-tmpfiles
 > 

Best solution. /tmp is temporary, as it should be.

Also, ignore my statement that I was seeing an unmounting error about /tmp. The error is not about /tmp, it’s actually about /var not unmounting. So many problems to keep track of …

Hi
In your use case, which is how it should be :slight_smile: FHS on /tmp it’s recommended to be cleaned out, but like the standard says system admin is not in scope and openSUSE likes to follow upstream as much as possible…

Take a look at the man (5) page for ‘tmpfiles.d’ – I have a file in ‘/etc/tmpfiles.d/’ named “zypp-var-tmp.conf” which does only one thing:

R! /var/tmp/zypp.*

Code reading of “/usr/lib/tmpfiles.d/tmp.conf” and “/usr/lib/tmpfiles.d/var.conf” will also give some enlightenment WRT what the systemd “tmp files cleanup” is doing for the openSUSE case …

I admit that, I deal with a current SDDM issue by means of a (user == root) “run at boot time” ‘/etc/cron.d/’ cron job:


#
# No e-Mail
MAILTO=""
#
@reboot root /usr/bin/find /tmp/ -daystart -type s -atime +0 -iname 'sddm-auth*' -ls -exec /usr/bin/unlink '{}' \;
#