5

Background: On my system /tmp is a regular part of the / partition and I use it for a few important features of the system.

Current systemd Approach: On new systems systemd has started to take over mounting and in particular, mounting a tmpfs over /tmp at boot or even during updates. This is regulated in /usr/lib/systemd/system/tmp.mount:

/usr/lib/systemd/system/tmp.mount
#  SPDX-License-Identifier: LGPL-2.1+
#
#  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.

[Unit]
Description=Temporary Directory (/tmp)
Documentation=https://systemd.io/TEMPORARY_DIRECTORIES
Documentation=man:file-hierarchy(7)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
ConditionPathIsSymbolicLink=!/tmp
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
After=swap.target

[Mount]
What=tmpfs
Where=/tmp
Type=tmpfs
Options=mode=1777,strictatime,nosuid,nodev,size=50%,nr_inodes=400k

Problem: A few months ago during an update some running processes started writing error messages because important files in /tmp disappeared - when systemd is updated even in a running system tmpfs is force-mounted over the existing /tmp. It can also not be u(n)mounted ("filesystem busy"). This creates problems.

Partial Fix: I fixed it by commenting out the last 5 lines in the file given above. Also, I removed /usr/lib/systemd/system/local-fs.target.wants/tmp.mount. However, each time systemd is updated my customisation is lost - both files are no configuration files (though the wanted file should be a flag). They will be replaced without warning.

Question: How can I permanently disable the mounting of a temporary (or any) filesystem over /tmp? Perhaps there is a systemd option I am missing? I am looking for a solution surviving a systemd upgrade.

I did have a look at the manuals and linked documentation but nothing works. I also tried

chattr +i /usr/lib/systemd/system/tmp.mount

on my adjusted file but then systemd will not be updated at all which isn't an option of course.

2
  • @StephenKitt Thanks! My understanding was that systemctl disable tmp.mount removes the /usr/lib/systemd/system/local-fs.target.wants/tmp.mount. Which symlink is created in /etc? strace systemctl disable tmp.mount didn't reveal anything to me.
    – Ned64
    Commented Feb 28, 2021 at 18:44
  • I did try disabling the unit in the past but it was reset by an update (or perhaps just ignored, don't remember). That's why I ended up editing the /usr/lib/systemd/system/tmp.mount file. I tried again now and will tell you after the next reboot.
    – Ned64
    Commented Feb 28, 2021 at 18:50

1 Answer 1

6

I think that systemctl mask tmp.mount should do the trick for you: this will disable the unit, symlinking it to /dev/null in /etc, which will prevent its being re-enabled on upgrade. It will also prevent manually starting the unit:

# systemctl mask tmp.mount
Created symlink /etc/systemd/system/tmp.mount → /dev/null.
1
  • Excellent, thanks. I trust it to work now (not tested yet but saw the new link). Added the output for better searchability.
    – Ned64
    Commented Feb 28, 2021 at 18:57

You must log in to answer this question.

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