diff --git a/man/systemd-fstab-generator.xml b/man/systemd-fstab-generator.xml index ab33258858..59f1896860 100644 --- a/man/systemd-fstab-generator.xml +++ b/man/systemd-fstab-generator.xml @@ -198,6 +198,15 @@ automatically populate /etc, and also /var in case of systemd.volatile=yes. + + + systemd.swap + + 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 /etc/fstab. + Defaults to enabled. + diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 5a0a871759..08c7b76dba 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -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;