]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto-generator: also honor systemd.swap=no
authorDavid Tardon <dtardon@redhat.com>
Thu, 25 May 2023 07:03:10 +0000 (09:03 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 25 May 2023 17:30:32 +0000 (19:30 +0200)
man/systemd-gpt-auto-generator.xml
src/gpt-auto-generator/gpt-auto-generator.c

index 1730039b62c5024e8f0131fa2336310711ea5af0..100c5c259e8eb48f2d58e185297242458b63ca2f 100644 (file)
         <citerefentry><refentrytitle>systemd-remount-fs.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
         </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, automatic discovery of swap partition(s) based on GPT partition type is disabled.
+        Defaults to enabled.</para></listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
 
index 030ada5d6e89a237db0228363f7f2301cfdba3d8..e3b3b1b22809e5d7da0d54c39e27a2fb758bc5cf 100644 (file)
@@ -41,6 +41,7 @@
 static const char *arg_dest = NULL;
 static bool arg_enabled = true;
 static bool arg_root_enabled = true;
+static bool arg_swap_enabled = true;
 static char *arg_root_fstype = NULL;
 static char *arg_root_options = NULL;
 static int arg_root_rw = -1;
@@ -350,6 +351,9 @@ static int add_partition_swap(DissectedPartition *p) {
         assert(p);
         assert(p->node);
 
+        if (!arg_swap_enabled)
+                return 0;
+
         /* Disable the swap auto logic if at least one swap is defined in /etc/fstab, see #6192. */
         r = fstab_has_fstype("swap");
         if (r < 0)
@@ -891,6 +895,19 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
         else if (proc_cmdline_key_streq(key, "systemd.image_policy"))
                 return parse_image_policy_argument(optarg, &arg_image_policy);
 
+        else if (proc_cmdline_key_streq(key, "systemd.swap")) {
+
+                r = value ? parse_boolean(value) : 1;
+                if (r < 0)
+                        log_warning_errno(r, "Failed to parse swap switch \"%s\", ignoring: %m", value);
+                else
+                        arg_swap_enabled = r;
+
+                if (!arg_swap_enabled)
+                        log_debug("Disabling swap partitions auto-detection, systemd.swap=no is defined.");
+
+        }
+
         return 0;
 }