From d34361149f897eac5c6a41854fa4edca4804b49b Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 29 Jun 2024 15:36:28 +0200 Subject: [PATCH 1/2] repart: Don't set filesystem sector size to 512 We want to use 4K as the default sector size for filesystems so they don't have to be regenerated to work on 512, 2048 or 4096 sector sizes. --- src/partition/repart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partition/repart.c b/src/partition/repart.c index 8ec655d493..fc5d61e47c 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2564,7 +2564,7 @@ static int context_load_partition_table(Context *context) { if (IN_SET(arg_empty, EMPTY_REQUIRE, EMPTY_FORCE, EMPTY_CREATE) && S_ISREG(st.st_mode)) /* Don't probe sector size from partition table if we are supposed to start from an empty disk */ - fs_secsz = ssz = 512; + ssz = 512; else { /* Auto-detect sector size if not specified. */ r = probe_sector_size_prefer_ioctl(context->backing_fd, &ssz); From 03c9e88fb7eb8973477c33aa63dc6bcf0cab52c9 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 29 Jun 2024 15:27:02 +0200 Subject: [PATCH 2/2] mkfs-util: Set sector size for btrfs as well btrfs used to default the sector size to the page size and didn't support anything else. Since 6.7, it defaults to 4K and using 4K makes the filesystem compatible with all page sizes. So let's make sure we use minimum 4K as well (lower causes failures on systems with a 4K page size) but still allow larger sector sizes if specified by the user. --- src/shared/mkfs-util.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index 4d440127e5..14bf82b564 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -461,6 +461,15 @@ int make_filesystem( if (quiet) stdio_fds[1] = -EBADF; + if (sector_size > 0) { + if (strv_extend(&argv, "--sectorsize") < 0) + return log_oom(); + + /* mkfs.btrfs expects a sector size of at least 4k bytes. */ + if (strv_extendf(&argv, "%"PRIu64, MAX(sector_size, 4 * U64_KB)) < 0) + return log_oom(); + } + } else if (streq(fstype, "f2fs")) { argv = strv_new(mkfs, "-g", /* "default options" */