4

How can I disable a unit generated by systemd-fstab-generator or systemd.generator?

Here's my attempt:

$ systemctl is-enabled media-backup.automount
generated
$ echo $?
0
$ sudo systemctl disable media-backup.automount
$ echo $?
0
$ systemctl is-enabled media-backup.automount
generated
$ echo $?
0

As you can see from the exit status 0 the .automount unit is still enabled.

Tom Hale
  • 30,455

2 Answers2

4

From this answer:

Generated unit files are not automatically activated by systemd. There's nothing special about them as far as systemd is concerned. Each individual generator has to explicitly create symbolic links that connect a generated unit to a target, so that activating the target activates the generated unit via a dependency in the normal way.

Removing the symlink under /run/systemd/generator/local-fs.target.wants will disable the .automount until the next boot.

To stop the boot-time generation of the unit, add noauto to the /etc/fstab entry as sebasth said.

Be aware that there is some magic required tostop an.automount` unit without unmounting the filesystem.

Tom Hale
  • 30,455
2

You can use noauto option in fstab to disable systemd from automatically mounting the fstab entry.

sebasth
  • 14,872
  • 2
    Maybe. systemd will still manage noauto entries under circumstances which are poorly defined, and which the systemd maintainers refuse to fix. https://github.com/systemd/systemd/issues/1741 – Julie in Austin May 29 '20 at 15:23