From 9a2982b687fe00676b9eac0d8e3ae9bdc88e5711 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Thu, 25 May 2023 09:03:10 +0200 Subject: [PATCH] gpt-auto-generator: also honor systemd.swap=no --- man/systemd-gpt-auto-generator.xml | 8 ++++++++ src/gpt-auto-generator/gpt-auto-generator.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/man/systemd-gpt-auto-generator.xml b/man/systemd-gpt-auto-generator.xml index 1730039b62c..100c5c259e8 100644 --- a/man/systemd-gpt-auto-generator.xml +++ b/man/systemd-gpt-auto-generator.xml @@ -284,6 +284,14 @@ systemd-remount-fs.service8. + + + systemd.swap= + + 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. + diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 030ada5d6e8..e3b3b1b2280 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -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; }