From: Kai Lüke Date: Thu, 5 Feb 2026 17:51:07 +0000 (+0100) Subject: repart: Discard only once X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eefb46c83b130ccec16891c3dd89aa4f32229e80;p=thirdparty%2Fsystemd.git 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. --- 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; }