fstab-generator: handle systemd.swap= command-line argument

Don't generate swap units if set to false

The inverse of this argument is present as "noswap" on Debian sysvinit

Ref:
4422988cb4/debian/vars.sh (L34)
4422988cb4/debian/src/initscripts/etc/init.d/mountall.sh (L78)

Fixes https://github.com/systemd/systemd/issues/6686
This commit is contained in:
nabijaczleweli 2019-12-21 07:17:59 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 392a2d5148
commit 567a530760
2 changed files with 23 additions and 0 deletions

View File

@ -198,6 +198,15 @@
automatically populate <filename>/etc</filename>, and also <filename>/var</filename> in case of
<literal>systemd.volatile=yes</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.swap</varname></term>
<listitem><para>Takes a boolean argument or enables the option if specified
without an argument. If disabled, causes the generator to ignore
any swap devices configured in <filename>/etc/fstab</filename>.
Defaults to enabled.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -40,6 +40,7 @@ typedef enum MountpointFlags {
static const char *arg_dest = NULL;
static const char *arg_dest_late = NULL;
static bool arg_fstab_enabled = true;
static bool arg_swap_enabled = true;
static char *arg_root_what = NULL;
static char *arg_root_fstype = NULL;
static char *arg_root_options = NULL;
@ -98,6 +99,11 @@ static int add_swap(
assert(what);
assert(me);
if (!arg_swap_enabled) {
log_info("Swap unit generation disabled on kernel command line, ignoring fstab swap entry for %s.", what);
return 0;
}
if (access("/proc/swaps", F_OK) < 0) {
log_info("Swap not supported, ignoring fstab swap entry for %s.", what);
return 0;
@ -896,6 +902,14 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
arg_volatile_mode = m;
} else
arg_volatile_mode = VOLATILE_YES;
} else if (streq(key, "systemd.swap")) {
r = value ? parse_boolean(value) : 1;
if (r < 0)
log_warning("Failed to parse systemd.swap switch %s. Ignoring.", value);
else
arg_swap_enabled = r;
}
return 0;