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.
This commit is contained in:
Kai Lüke
2026-02-10 13:09:33 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent 7081618cd9
commit eefb46c83b
+3 -1
View File
@@ -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;
}