5

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?

6

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.

|improve this answer|||||
  • I have made the changes, how do I now "remount" using systemctl ? – Felipe Alvarez Jul 23 '19 at 1:27
  • You can mount a systemd mount unit with systemctl start, but if you had it mounted before the command you may end up with a double mount or it might fail... If you're unable to unmount it (because the filesystem is busy), perhaps rebooting is the safest way... – filbranden Jul 23 '19 at 3:02

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.