1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

Implement SYSTEMD_HOME_MKFS_OPTIONS_* envvars to configure mkfs options for homed LUKS directories

This commit is contained in:
Aidan Dang 2022-12-10 21:58:27 +11:00 committed by Lennart Poettering
parent 15cad3a2ab
commit 8f30c00c50
7 changed files with 46 additions and 11 deletions

View File

@ -480,6 +480,11 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
options. There's one variable for each of the supported file systems for the
LUKS home directory backend.
* `$SYSTEMD_HOME_MKFS_OPTIONS_BTRFS`, `$SYSTEMD_HOME_MKFS_OPTIONS_EXT4`,
`$SYSTEMD_HOME_MKFS_OPTIONS_XFS` configure additional arguments to use for
`mkfs` when formatting LUKS home directories. There's one variable for each
of the supported file systems for the LUKS home directory backend.
`kernel-install`:
* `$KERNEL_INSTALL_BYPASS` If set to "1", execution of kernel-install is skipped

View File

@ -2110,6 +2110,25 @@ static int home_truncate(
return !trunc; /* Return == 0 if we managed to truncate, > 0 if we managed to allocate */
}
static int mkfs_options_for_fstype(const char *fstype, char ***ret) {
_cleanup_(strv_freep) char **l = NULL;
const char *e;
char *n;
assert(fstype);
n = strjoina("SYSTEMD_HOME_MKFS_OPTIONS_", fstype);
e = getenv(ascii_strupper(n));
if (e) {
l = strv_split(e, NULL);
if (!l)
return -ENOMEM;
}
*ret = TAKE_PTR(l);
return 0;
}
int home_create_luks(
UserRecord *h,
HomeSetup *setup,
@ -2126,6 +2145,7 @@ int home_create_luks(
const char *fstype, *ip;
struct statfs sfs;
int r;
_cleanup_strv_free_ char **extra_mkfs_options = NULL;
assert(h);
assert(h->storage < 0 || h->storage == USER_LUKS);
@ -2333,7 +2353,10 @@ int home_create_luks(
log_info("Setting up LUKS device %s completed.", setup->dm_node);
r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), NULL, fs_uuid, user_record_luks_discard(h));
r = mkfs_options_for_fstype(fstype, &extra_mkfs_options);
if (r < 0)
return log_error_errno(r, "Failed to determine mkfs command line options for '%s': %m", fstype);
r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), NULL, fs_uuid, user_record_luks_discard(h), extra_mkfs_options);
if (r < 0)
return r;

View File

@ -65,7 +65,7 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to generate UUID for file system: %m");
return make_filesystem(device, fstype, basename(device), NULL, uuid, true);
return make_filesystem(device, fstype, basename(device), NULL, uuid, true, NULL);
}
DEFINE_MAIN_FUNCTION(run);

View File

@ -4032,7 +4032,7 @@ static int context_mkfs(Context *context) {
}
r = make_filesystem(partition_target_path(t), p->format, strempty(p->new_label), root,
p->fs_uuid, arg_discard);
p->fs_uuid, arg_discard, NULL);
if (r < 0)
return r;
@ -5362,7 +5362,7 @@ static int context_minimize(Context *context) {
return r;
}
r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, fs_uuid, arg_discard);
r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, fs_uuid, arg_discard, NULL);
if (r < 0)
return r;
@ -5415,7 +5415,7 @@ static int context_minimize(Context *context) {
if (r < 0 && r != -ENOENT && !ERRNO_IS_PRIVILEGE(r))
return log_error_errno(r, "Failed to make loopback device of %s: %m", temp);
r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, p->fs_uuid, arg_discard);
r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, p->fs_uuid, arg_discard, NULL);
if (r < 0)
return r;

View File

@ -302,7 +302,8 @@ int make_filesystem(
const char *label,
const char *root,
sd_id128_t uuid,
bool discard) {
bool discard,
char * const *extra_mkfs_args) {
_cleanup_free_ char *mkfs = NULL, *mangled_label = NULL;
_cleanup_strv_free_ char **argv = NULL;
@ -522,6 +523,12 @@ int make_filesystem(
if (!argv)
return log_oom();
if (extra_mkfs_args) {
r = strv_extend_strv(&argv, extra_mkfs_args, false);
if (r < 0)
return log_oom();
}
if (root && stat(root, &st) < 0)
return log_error_errno(errno, "Failed to stat %s: %m", root);

View File

@ -11,4 +11,4 @@ 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);
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);

View File

@ -245,16 +245,16 @@ static int run(int argc, char *argv[]) {
assert_se(r >= 0);
assert_se(sd_id128_randomize(&id) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", NULL, id, true) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", NULL, id, true, NULL) >= 0);
assert_se(sd_id128_randomize(&id) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", NULL, id, true) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", NULL, id, true, NULL) >= 0);
assert_se(sd_id128_randomize(&id) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", NULL, id, true) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", NULL, id, true, NULL) >= 0);
assert_se(sd_id128_randomize(&id) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", NULL, id, true) >= 0);
assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", NULL, id, true, NULL) >= 0);
dissected = dissected_image_unref(dissected);