From 5253b4a99f658785fcdca0d30663259d1543c443 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Nov 2023 11:12:38 +0100 Subject: [PATCH 1/4] gpt-auto-generator: drop in_initrd() check in add_partition_root_rw() This call is never called in the initrd, hence we can drop the extra check, as it is redundant. Let's keep it as an assert() though, as a form of code-enforced documentation. --- src/gpt-auto-generator/gpt-auto-generator.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index d774740622..e4c3aeea8a 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -634,11 +634,9 @@ static int add_partition_root_rw(DissectedPartition *p) { int r; assert(p); + assert(!in_initrd()); - if (in_initrd()) { - log_debug("In initrd, not generating drop-in for systemd-remount-fs.service."); - return 0; - } + /* Invoked on the main system (not initrd), to honour GPT flag 60 on the root fs (ro) */ if (arg_root_rw >= 0) { log_debug("Parameter ro/rw specified on kernel command line, not generating drop-in for systemd-remount-fs.service."); From ca8ac0f9b5479eb98fad6d364303f9d6d38f410c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Nov 2023 11:14:11 +0100 Subject: [PATCH 2/4] gpt-auto-generator: add comment + assert() explaining mode of invocation We are not invoked in the initrd, and that deserves a comment. --- src/gpt-auto-generator/gpt-auto-generator.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index e4c3aeea8a..d1f6688f4c 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -793,6 +793,11 @@ static int enumerate_partitions(dev_t devnum) { _cleanup_free_ char *devname = NULL; int r; + assert(!in_initrd()); + + /* Run on the final root fs (not in the initrd), to mount auxiliary partitions, and hook in rw + * remount and growfs of the root partition */ + r = block_get_whole_disk(devnum, &devnum); if (r < 0) return log_debug_errno(r, "Failed to get whole block device for " DEVNUM_FORMAT_STR ": %m", From 40b1224ea7ebc17bbdc78f5e75946c1c65eb0dbe Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Nov 2023 13:17:31 +0100 Subject: [PATCH 3/4] gpt-auto-generator: don't eat up errors of generator_enable_remount_fs_service() I cannot see a reason why we should ignore this error, so let's not. We use RET_GATHER() on the returns anyway, i.e. collect errors but continue, so it makes sense to collect this one too. --- src/gpt-auto-generator/gpt-auto-generator.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index d1f6688f4c..b2c78ef4c2 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -648,7 +648,9 @@ static int add_partition_root_rw(DissectedPartition *p) { return 0; } - (void) generator_enable_remount_fs_service(arg_dest); + r = generator_enable_remount_fs_service(arg_dest); + if (r < 0) + return r; path = strjoina(arg_dest, "/systemd-remount-fs.service.d/50-remount-rw.conf"); From 6b5fe5d75e760bb554fb1c39c6bb874d18f1524f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Nov 2023 11:14:39 +0100 Subject: [PATCH 4/4] gpt-auto-generator: hook in "growfs" for the root fs if the GPT flag 59 says so Fixes: #29791 --- src/gpt-auto-generator/gpt-auto-generator.c | 34 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index b2c78ef4c2..a0c5a733cb 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -665,6 +665,33 @@ static int add_partition_root_rw(DissectedPartition *p) { return 0; } +static int add_partition_root_growfs(DissectedPartition *p) { + + assert(p); + assert(!in_initrd()); + + /* Invoked on the main system (not initrd), to honour GPT flag 59 on the root fs (growfs) */ + + if (!p->growfs) { + log_debug("Root partition not marked for growing the file system in the GPT partition table, not generating drop-in for systemd-growfs-root.service."); + return 0; + } + + return generator_hook_up_growfs(arg_dest, "/", SPECIAL_LOCAL_FS_TARGET); +} + +static int add_partition_root_flags(DissectedPartition *p) { + int r = 0; + + assert(p); + assert(!in_initrd()); + + RET_GATHER(r, add_partition_root_growfs(p)); + RET_GATHER(r, add_partition_root_rw(p)); + + return r; +} + #if ENABLE_EFI static int add_root_cryptsetup(void) { #if HAVE_LIBCRYPTSETUP @@ -710,8 +737,9 @@ static int add_root_mount(void) { return r; } - /* Note that we do not need to enable systemd-remount-fs.service here. If - * /etc/fstab exists, systemd-fstab-generator will pull it in for us. */ + /* Note that we do not need to enable systemd-remount-fs.service here. If /etc/fstab exists, + * systemd-fstab-generator will pull it in for us, and otherwise add_partition_root_flags() will do + * it, after the initrd transition. */ r = partition_pick_mount_options( PARTITION_ROOT, @@ -860,7 +888,7 @@ static int enumerate_partitions(dev_t devnum) { "var-tmp", "/var/tmp", "Temporary Data Partition")); if (m->partitions[PARTITION_ROOT].found) - RET_GATHER(r, add_partition_root_rw(m->partitions + PARTITION_ROOT)); + RET_GATHER(r, add_partition_root_flags(m->partitions + PARTITION_ROOT)); return r; }