2

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?

1 Answer 1

4

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:

sudo touch /etc/tmpfiles.d/scratch-tmp.conf

And then include this content in it:

# Type  Path         Mode User Group Age Argument
  e     /scratch/tmp -    -    -     20m

The e type defines that this is a "marked" directory that already exists, but should be cleaned. An age setting of 20m 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.

1
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat.
    – Thomas Ward
    Jan 27 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.