From eefb46c83b130ccec16891c3dd89aa4f32229e80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kai=20L=C3=BCke?= Date: Thu, 5 Feb 2026 18:51:07 +0100 Subject: [PATCH] repart: Discard only once The indirect discard in mkfs.btrfs on the loop device mapped to the region on disk can hang and fail the first-boot creation of the rootfs. Since there already is a discard done we anyway don't need to do it twice. This might help for most cases to avoid the failure in mkfs.btrfs. Keep track if the direct discard worked and then skip the mkfs.btrfs discard if it did. This still leaves the case where mkfs.btrfs can hang when the direct discard couldn't succeed and mkfs.btrfs tries again but since the conditions are rather the same it might be that this case is not easy to trigger. If the problem still shows up and the kernel won't be fixed soon we can still disable the mkfs discard for at least btrfs. --- src/repart/repart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/repart/repart.c b/src/repart/repart.c index b3ecb62e93e..e59288221b3 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -422,6 +422,7 @@ typedef struct Partition { bool dropped; bool factory_reset; + bool discarded; int32_t priority; uint32_t weight, padding_weight; @@ -2748,7 +2749,7 @@ static bool partition_needs_populate(const Partition *p) { static MakeFileSystemFlags partition_mkfs_flags(const Partition *p) { MakeFileSystemFlags flags = 0; - if (arg_discard) + if (arg_discard && !p->discarded) flags |= MKFS_DISCARD; if (streq(p->format, "erofs") && !DEBUG_LOGGING && !isatty_safe(STDERR_FILENO)) @@ -4668,6 +4669,7 @@ static int context_discard_partition(Context *context, Partition *p) { return log_error_errno(r, "Failed to discard data for future partition %" PRIu64 ".", p->partno); log_info("Successfully discarded data from future partition %" PRIu64 ".", p->partno); + p->discarded = true; return 1; } -- 2.47.3