1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

repart: Allow overriding fstype per partition designator

$SYSTEMD_REPART_OVERRIDE_FSTYPE is too invasive. Often you want to
override the fstype only for a specific designator, so let's support
that as well.
This commit is contained in:
Daan De Meyer 2024-07-02 18:34:39 +02:00
parent 690a85b1d4
commit 90a255779d
4 changed files with 49 additions and 0 deletions

View File

@ -634,6 +634,10 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
* `$SYSTEMD_REPART_OVERRIDE_FSTYPE` if set the value will override the file
system type specified in Format= lines in partition definition files.
Additionally, the filesystem for all partitions with a specific designator can
be overridden via a correspondingly named environment variable. For example,
to override the filesystem type for all partitions with `Type=root`, you can
set `SYSTEMD_REPART_OVERRIDE_FSTYPE_ROOT=ext4`.
`systemd-nspawn`, `systemd-networkd`:

View File

@ -1898,6 +1898,34 @@ static int config_parse_encrypted_volume(
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_verity, verity_mode, VerityMode, VERITY_OFF, "Invalid verity mode");
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_minimize, minimize_mode, MinimizeMode, MINIMIZE_OFF, "Invalid minimize mode");
static int partition_finalize_fstype(Partition *p, const char *path) {
_cleanup_free_ char *e = NULL, *upper = NULL;
assert(p);
assert(path);
if (!gpt_partition_type_has_filesystem(p->type))
return 0;
upper = strdup(partition_designator_to_string(p->type.designator));
if (!upper)
return log_oom();
e = strjoin("SYSTEMD_REPART_OVERRIDE_FSTYPE_", string_replace_char(ascii_strupper(upper), '-', '_'));
if (!e)
return log_oom();
const char *v = secure_getenv(e);
if (!v || streq(p->format, v))
return 0;
log_syntax(NULL, LOG_NOTICE, path, 1, 0,
"Overriding defined file system type '%s' for '%s' partition with '%s'.",
p->format, partition_designator_to_string(p->type.designator), v);
return free_and_strdup_warn(&p->format, v);
}
static int partition_read_definition(Partition *p, const char *path, const char *const *conf_file_dirs) {
ConfigTableItem table[] = {
@ -2087,6 +2115,10 @@ static int partition_read_definition(Partition *p, const char *path, const char
} else if (streq(p->split_name_format, "-"))
p->split_name_format = mfree(p->split_name_format);
r = partition_finalize_fstype(p, path);
if (r < 0)
return r;
return 1;
}

View File

@ -339,6 +339,18 @@ bool gpt_partition_type_knows_no_auto(GptPartitionType type) {
PARTITION_SWAP);
}
bool gpt_partition_type_has_filesystem(GptPartitionType type) {
return IN_SET(type.designator,
PARTITION_ROOT,
PARTITION_USR,
PARTITION_HOME,
PARTITION_SRV,
PARTITION_ESP,
PARTITION_XBOOTLDR,
PARTITION_TMP,
PARTITION_VAR);
}
bool gpt_header_has_signature(const GptHeader *p) {
assert(p);

View File

@ -72,6 +72,7 @@ const char* gpt_partition_type_mountpoint_nulstr(GptPartitionType type);
bool gpt_partition_type_knows_read_only(GptPartitionType type);
bool gpt_partition_type_knows_growfs(GptPartitionType type);
bool gpt_partition_type_knows_no_auto(GptPartitionType type);
bool gpt_partition_type_has_filesystem(GptPartitionType type);
typedef struct {
uint8_t partition_type_guid[16];