/path/to/generator normal-dir early-dir late-dir
/run/systemd/system-generators/* /etc/systemd/system-generators/* /usr/local/lib/systemd/system-generators/* /usr/lib/systemd/system-generators/*
/run/systemd/user-generators/* /etc/systemd/user-generators/* /usr/local/lib/systemd/user-generators/* /usr/lib/systemd/user-generators/*
Each generator is called with three directory paths that are to be used for generator output. In these three directories, generators may dynamically generate unit files (regular ones, instances, as well as templates), unit file .d/ drop-ins, and create symbolic links to unit files to add additional dependencies, create aliases, or instantiate existing templates. Those directories are included in the unit load path of systemd(1), allowing generated configuration to extend or override existing definitions.
Directory paths for generator output differ by priority: .../generator.early has priority higher than the admin configuration in /etc/, while .../generator has lower priority than /etc/ but higher than vendor configuration in /usr/, and .../generator.late has priority lower than all other configuration. See the next section and the discussion of unit load paths and unit overriding in systemd.unit(5).
Generators are loaded from a set of paths determined during compilation, as listed above. System and user generators are loaded from directories with names ending in system-generators/ and user-generators/, respectively. Generators found in directories listed earlier override the ones with the same name in directories lower in the list. A symlink to /dev/null or an empty file can be used to mask a generator, thereby preventing it from running. Please note that the order of the two directories with the highest priority is reversed with respect to the unit load path, and generators in /run/ overwrite those in /etc/.
After installing new generators or updating the configuration, systemctl daemon-reload may be executed. This will delete the previous configuration created by generators, re-run all generators, and cause systemd to reload units from disk. See systemctl(1) for more information.
In normal use this is /run/systemd/generator in case of the system generators and $XDG_RUNTIME_DIR/generator in case of the user generators. Unit files placed in this directory take precedence over vendor unit configuration but not over native user/administrator unit configuration.
In normal use this is /run/systemd/generator.early in case of the system generators and $XDG_RUNTIME_DIR/generator.early in case of the user generators. Unit files placed in this directory override unit files in /usr/, /run/ and /etc/. This means that unit files placed in this directory take precedence over all normal configuration, both vendor and user/administrator.
In normal use this is /run/systemd/generator.late in case of the system generators and $XDG_RUNTIME_DIR/generator.late in case of the user generators. This directory may be used to extend the unit file tree without overriding any other unit files. Any native configuration files supplied by the vendor or user/administrator take precedence.
The SourcePath= directive should be used in generated files to specify the source configuration file they are generated from. This makes things more easily understood by the user and also has the benefit that systemd can warn the user about configuration files that changed on disk but have not been read yet by systemd. The SourcePath= value does not have to be a file in a physical filesystem. For example, in the common case of the generator looking at the kernel command line, SourcePath=/proc/cmdline should be used.
Of these two rules the first rule is probably the more important one and breaks the second one sometimes. Hence, when deciding whether to use argv, argv, or argv, your default choice should probably be argv.
systemd-fstab-generator(8) converts /etc/fstab into native mount units. It uses argv as location to place the generated unit files in order to allow the user to override /etc/fstab with their own native unit files, but also to ensure that /etc/fstab overrides any vendor default from /usr/.
After editing /etc/fstab, the user should invoke systemctl daemon-reload. This will re-run all generators and cause systemd to reload units from disk. To actually mount new directories added to fstab, systemctl start /path/to/mountpoint or systemctl start local-fs.target may be used.
Example 2. systemd-system-update-generator
systemd-system-update-generator(8) temporarily redirects default.target to system-update.target, if a system update is scheduled. Since this needs to override the default user configuration for default.target, it uses argv. For details about this logic, see systemd.offline-updates(7).
Example 3. Debugging a generator
dir=$(mktemp -d) SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system-generators/systemd-fstab-generator \ "$dir" "$dir" "$dir" find $dir