repart: Allow configuring sector size
Let's allow users to configure the (logical) sector size of their image. This is required when building images for a 4k sector size disk on a 512b sector size host or vice-versa.
This commit is contained in:
+21
-2
@@ -301,6 +301,7 @@ int make_filesystem(
|
||||
const char *root,
|
||||
sd_id128_t uuid,
|
||||
bool discard,
|
||||
uint64_t sector_size,
|
||||
char * const *extra_mkfs_args) {
|
||||
|
||||
_cleanup_free_ char *mkfs = NULL, *mangled_label = NULL;
|
||||
@@ -397,6 +398,7 @@ int make_filesystem(
|
||||
"-I", "256",
|
||||
"-m", "0",
|
||||
"-E", discard ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
|
||||
"-b", "4096",
|
||||
node);
|
||||
if (!argv)
|
||||
return log_oom();
|
||||
@@ -413,6 +415,7 @@ int make_filesystem(
|
||||
"-O", "has_journal",
|
||||
"-m", "0",
|
||||
"-E", discard ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
|
||||
"-b", "4096",
|
||||
node);
|
||||
|
||||
if (root && strv_extend_strv(&argv, STRV_MAKE("-d", root), false) < 0)
|
||||
@@ -469,7 +472,15 @@ int make_filesystem(
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
} else if (streq(fstype, "vfat"))
|
||||
if (sector_size > 0) {
|
||||
if (strv_extend(&argv, "-s") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (strv_extendf(&argv, "size=%"PRIu64, sector_size) < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
} else if (streq(fstype, "vfat")) {
|
||||
|
||||
argv = strv_new(mkfs,
|
||||
"-i", vol_id,
|
||||
@@ -477,7 +488,15 @@ int make_filesystem(
|
||||
"-F", "32", /* yes, we force FAT32 here */
|
||||
node);
|
||||
|
||||
else if (streq(fstype, "swap"))
|
||||
if (sector_size > 0) {
|
||||
if (strv_extend(&argv, "-S") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (strv_extendf(&argv, "%"PRIu64, sector_size) < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
} else if (streq(fstype, "swap"))
|
||||
/* TODO: add --quiet here if
|
||||
* https://github.com/util-linux/util-linux/issues/1499 resolved. */
|
||||
|
||||
|
||||
@@ -11,4 +11,12 @@ int mkfs_exists(const char *fstype);
|
||||
|
||||
int mkfs_supports_root_option(const char *fstype);
|
||||
|
||||
int make_filesystem(const char *node, const char *fstype, const char *label, const char *root, sd_id128_t uuid, bool discard, char * const *extra_mkfs_args);
|
||||
int make_filesystem(
|
||||
const char *node,
|
||||
const char *fstype,
|
||||
const char *label,
|
||||
const char *root,
|
||||
sd_id128_t uuid,
|
||||
bool discard,
|
||||
uint64_t sector_size,
|
||||
char * const *extra_mkfs_args);
|
||||
|
||||
Reference in New Issue
Block a user