From 307785960bf03594ffb975fd0d8fabccf43e36ad Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Mon, 26 Jan 2026 14:10:38 +0100 Subject: [PATCH 1/2] repart: Restore early generation of fstab/crypttab Commit 15b1c33 ("repart: Generate fstab and crypttab late") moved fstab/crypttab generation to the late stage but this introduced a regression: it may be necessary to include fstab and crypttab into the generated partition (e.g. with CopyFiles=). This is incompatible with 'fixate-volume-key' option as it is impossible to capture LUKS volume key before it gets created but all the rest should work fine. Generate crypttab twice: early and late to capture possible changes. There's no need to do the same for fstab for now, so keep the status quo. --- man/repart.d.xml | 4 +++- src/repart/repart.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/man/repart.d.xml b/man/repart.d.xml index 5cdf2b0f34..66faa8c057 100644 --- a/man/repart.d.xml +++ b/man/repart.d.xml @@ -884,7 +884,9 @@ Note that this setting is only taken into account when - is specified on the systemd-repart command line. + is specified on the systemd-repart command line. As the crypttab with the expected + hashes can only be generated after LUKS volumes are formatted, the crypttab itself cannot be put to + the generated volume. diff --git a/src/repart/repart.c b/src/repart/repart.c index a3e17cc294..b3ecb62e93 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -8501,7 +8501,7 @@ static bool need_crypttab(Context *context) { return false; } -static int context_crypttab(Context *context) { +static int context_crypttab(Context *context, bool late) { _cleanup_(unlink_and_freep) char *t = NULL; _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *path = NULL; @@ -8544,7 +8544,7 @@ static int context_crypttab(Context *context) { strempty(p->encrypted_volume->options)); } - r = flink_tmpfile(f, t, path, 0); + r = flink_tmpfile(f, t, path, late ? LINK_TMPFILE_REPLACE : 0); if (r < 0) return log_error_errno(r, "Failed to link temporary file to %s: %m", path); @@ -10755,6 +10755,14 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; + r = context_fstab(context); + if (r < 0) + return r; + + r = context_crypttab(context, /* late= */ false); + if (r < 0) + return r; + r = context_update_verity_size(context); if (r < 0) return r; @@ -10810,11 +10818,7 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; - r = context_fstab(context); - if (r < 0) - return r; - - r = context_crypttab(context); + r = context_crypttab(context, /* late= */ true); if (r < 0) return r; From 7a4b51ce4caa445ce351cbe7953f57115a86a33b Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Mon, 26 Jan 2026 14:21:14 +0100 Subject: [PATCH 2/2] TEST-58-REPART: Add a test for fstab/crypttab inclusion Check that generated fstab/crypt are generated early and thus can be put to the created volume. --- test/units/TEST-58-REPART.sh | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index 9802f145bc..4ac4f2ee4b 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -1997,6 +1997,68 @@ EOF losetup -d "$loop" } +testcase_fstab_crypttab_in_repart() { + local defs imgs root volume + + defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + root="$(mktemp --directory "/var/test-repart.root.XXXXXXXXXX")" + # shellcheck disable=SC2064 + trap "rm -rf '$defs' '$imgs' '$root'" RETURN + chmod 0755 "$defs" + + echo "*** testcase for including fstab/crypttab into repart created volume ***" + + volume="test-repart-fstab-crypttab-$RANDOM" + + mkdir -p "$root/etc" + tee "$defs/root.conf" <