12

I'd like to mount /tmp without fstab entry using tmp.mount

However on Ubuntu 20.04 LTS, it doesn't seem to work.

user@user-x1:~$ systemctl status tmp.mount 
Unit tmp.mount could not be found.
user@user-x1:~$ sudo systemctl enable tmp.mount 
Failed to enable unit: Unit file tmp.mount does not exist.
user@user-x1:~$ sudo systemctl cat tmp.mount 
No files found for tmp.mount.
user@user-x1:~$ cat /usr/share/systemd/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

[Install]
WantedBy=local-fs.target
user@user-x1:~$ 

What's happening? Why does systemd say unit could not be found even though bash auto tabbing fills up tmp.mount and what's the simplest way to enable this tmpfs without any config?

2 Answers 2

18

tmp.mount is not enabled by default. Just copy and enable it

sudo cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/ 
sudo systemctl enable tmp.mount
2
  • Thanks @ExploitFate!
    – x70766c
    Apr 28, 2020 at 9:56
  • 1
    Maybe symlink (ln -s) would be better than copy (cp). But it's just a detail :)
    – Messa
    Nov 8, 2021 at 11:29
11

Note that systemctl enable accept absolute paths to unit files. (See systemctl man page) So there's no need to copy it manually.

I have tested on Ubuntu 22.04:

$ sudo systemctl enable /usr/share/systemd/tmp.mount
Created symlink /etc/systemd/system/local-fs.target.wants/tmp.mount → /usr/share/systemd/tmp.mount.
Created symlink /etc/systemd/system/tmp.mount → /usr/share/systemd/tmp.mount.
2
  • Interesting. And will systemd deal with all the required configuration details, e.g. properly formatting the in-memory /tmp and so forth (or whatever the initialisation it requires)? All I see on Ubuntu 22.04 is that it is expected to eat up 50% of all available memory, which seems to me to be overkill... Sep 7, 2022 at 17:08
  • @GwynethLlewelyn "formatting" a tmpfs makes no sense, it's a virtual filesystem so the kernel just provides you with a clean one when asked. tmpfs allowing use of up to 50% of RAM is the default, but that doesn't mean that 50% of RAM is immediately marked as used when a tmpfs is mounted.
    – muru
    Jan 30 at 8:06

You must log in to answer this question.

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