On Ubuntu Server 22.04, I have an SSD mounted on /scratch
. I replaced /tmp
with a symbolic link to /scratch/tmp
so that temporary files are stored on the SSD:
$ ls -l /tmp
lrwxrwxrwx 1 root root 12 Jan 13 16:22 /tmp -> /scratch/tmp
This seems to work fine with one snag: the contents of /tmp
are no longer deleted on a reboot, as I expect them to be. How can I make this happen?
Temp files are cleaned in Ubuntu by
systemd-tmpfiles
and the related service/lib/systemd/system/systemd-tmpfiles-clean.service
, and the configuration for said files can be configured inside/etc/tmpfiles.d/*.conf
(also see this answer).To include the directory you describe, create a config file:
And then include this content in it:
The
e
type defines that this is a "marked" directory that already exists, but should be cleaned. An age setting of20m
will clean all files more than 20 minutes old (see explanation below).If the type is
d
, the directory will be created if it doesn't exist, and cleaned up on reboot and each day.Be aware that the timer triggering the service (found at
/lib/systemd/system/systemd-tmpfiles-clean.timer
) is set to run 15 minutes after boot, so you won't see the actual effects at reboot until after 15 minutes uptime.Please see the manpage for
tmpfiles.d
for more information.