]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: handle systemd.swap= command-line argument
authornabijaczleweli <nabijaczleweli@gmail.com>
Sat, 21 Dec 2019 06:17:59 +0000 (07:17 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 12 Mar 2020 16:52:43 +0000 (17:52 +0100)
Don't generate swap units if set to false

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

Ref:
https://salsa.debian.org/debian/sysvinit/blob/4422988cb41c3022eee7444378cac3b2e36eac28/debian/vars.sh#L34
https://salsa.debian.org/debian/sysvinit/blob/4422988cb41c3022eee7444378cac3b2e36eac28/debian/src/initscripts/etc/init.d/mountall.sh#L78

Fixes https://github.com/systemd/systemd/issues/6686

man/systemd-fstab-generator.xml
src/fstab-generator/fstab-generator.c

index ab332588581b9c1ee39cefbe0591f276eb926b0e..59f18968608d74f9e30171947e35595637eec6a6 100644 (file)
         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>
 
index 5a0a871759ed467df723546f99e5351a1c794b9a..08c7b76dbaeb9378772f4b02289398aa8b22bc9e 100644 (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;