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.
bool dropped;
bool factory_reset;
+ bool discarded;
int32_t priority;
uint32_t weight, padding_weight;
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))
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;
}