fstab-generator: support for x-systemd.onfailure

Add support for the x-systemd.onfailure fstab option in fstab-generator.

This allows generated mount units to include the systemd OnFailure=
dependency specified through /etc/fstab.

x-systemd.onfailure= is handled by generalizing the existing
write_dependency() helper (already used for After=/Before=/Requires=/
Wants=) to take an optional unit-name suffix. When no suffix is given,
unit names are mangled without forcing a ".mount" suffix, since
OnFailure= targets are not necessarily mount units. write_on_failure()
is now a thin wrapper around write_dependency().

Example:

/dev/sda1 /data ext4 defaults,x-systemd.onfailure=emergency.target 0 2

generates:

OnFailure=emergency.target

This makes it possible to attach recovery targets or services to mount
failures directly from fstab configuration.

Add documentation and generator tests.
This commit is contained in:
nikhilnrr
2026-09-22 18:48:23 +02:00
committed by Luca Boccassi
parent 9d27286214
commit b7041b73cf
11 changed files with 96 additions and 5 deletions
+19
View File
@@ -284,6 +284,25 @@
<xi:include href="version-info.xml" xpointer="v220"/></listitem>
</varlistentry>
<varlistentry>
<term><option>x-systemd.onfailure=</option></term>
<listitem><para>In the created mount unit, configures an
<varname>OnFailure=</varname> dependency. The argument is a unit name, see
<option>x-systemd.requires=</option> above. This option may be specified more than
once. See <varname>OnFailure=</varname> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details.</para>
<para>Note that this option always applies to the created mount
unit only, regardless of whether <option>x-systemd.automount</option>
has been specified.</para>
<para>Note that this option is silently ignored on swap entries.</para>
<xi:include href="version-info.xml" xpointer="v262"/></listitem>
</varlistentry>
<varlistentry>
<term><option>x-systemd.graceful-option=</option></term>