/tmp in tmpfs, how do this only with systemd?
I have now a laptop with Ubuntu 18.04 and i love it. i have mounted /tmp as tmpfs via /etc/fstab
line as this:
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777 0 0
now, i like to know how i can do this only with systemd
, i need only to activate a new systemd
service only (tmp.mount
related), or i need one more thing ? how i can replace my actual /etc/fstab
line with systemd
in my laptop on live mode?
Please note that using /etc/fstab
is still the preferred approach with systemd!
See the man page for systemd.mount which states:
In general, configuring mount points through /etc/fstab is the preferred approach.
systemd ships systemd-fstab-generator which converts those to mount units.
If you really want to turn that mount into a mount unit, my recommendation is to check its current exact configuration, with the following command:
$ systemctl cat tmp.mount
Or:
$ systemctl cat /tmp
Which will show you the dynamic unit created by systemd-fstab-generator, and should look similar to:
# /run/systemd/generator/tmp.mount
# Automatically generated by systemd-fstab-generator
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target
[Mount]
What=tmpfs
Where=/tmp
Type=tmpfs
Options=noatime,nosuid,nodev,noexec,mode=1777
You could save these contents into /etc/systemd/system/tmp.mount
and run systemctl enable tmp.mount
to activate it. (You will need to add an [Install]
section and a WantedBy=local-fs.target
to be able to successfully enable it.)
(Another option is to use the tmp.mount from the systemd sources. Some other distributions, like Fedora, are shipping and enabling that one.)
Don't forget to remove the one from /etc/fstab
, otherwise they might conflict. (I believe the one in fstab would prevail, as I'd expect /run
to have priority over /etc
.)
But, as said before, managing through /etc/fstab
is still the preferred solution... So I'd probably recommend you still stick with that one.