1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-28 20:25:38 +03:00

veritysetup-generator: imply x-initrd.attach for "usr" and "root" volumes

Similar to the previous commit, just vor Verity rather than LUKS.
This commit is contained in:
Lennart Poettering 2023-06-01 14:50:15 +02:00
parent 8ce02b87ce
commit bf1484c70a

View File

@ -102,10 +102,9 @@ static int create_device(
return r; return r;
fprintf(f, fprintf(f,
"Conflicts=umount.target\n" "Before=veritysetup.target\n"
"BindsTo=%s %s\n" "BindsTo=%s %s\n"
"After=%s %s\n" "After=%s %s\n",
"Before=veritysetup.target umount.target\n",
d, e, d, e,
d, e); d, e);
@ -288,6 +287,18 @@ static int determine_devices(void) {
return determine_device("usr", arg_usr_hash, &arg_usr_data_what, &arg_usr_hash_what); return determine_device("usr", arg_usr_hash, &arg_usr_data_what, &arg_usr_hash_what);
} }
static bool attach_in_initrd(const char *name, const char *options) {
assert(name);
/* Imply x-initrd.attach in case the volume name is among those defined in the Discoverable Partition
* Specification for partitions that we require to be mounted during the initrd host transition,
* i.e. for the root fs itself, and /usr/. This mirrors similar behaviour in
* systemd-fstab-generator. */
return fstab_test_option(options, "x-initrd.attach\0") ||
STR_IN_SET(name, "root", "usr");
}
static int create_disk( static int create_disk(
const char *name, const char *name,
const char *data_device, const char *data_device,
@ -300,7 +311,7 @@ static int create_disk(
*du_escaped = NULL, *hu_escaped = NULL, *name_escaped = NULL; *du_escaped = NULL, *hu_escaped = NULL, *name_escaped = NULL;
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
const char *dmname; const char *dmname;
bool noauto, nofail, netdev, attach_in_initrd; bool noauto, nofail, netdev;
int r; int r;
assert(name); assert(name);
@ -311,7 +322,6 @@ static int create_disk(
noauto = fstab_test_yes_no_option(options, "noauto\0" "auto\0"); noauto = fstab_test_yes_no_option(options, "noauto\0" "auto\0");
nofail = fstab_test_yes_no_option(options, "nofail\0" "fail\0"); nofail = fstab_test_yes_no_option(options, "nofail\0" "fail\0");
netdev = fstab_test_option(options, "_netdev\0"); netdev = fstab_test_option(options, "_netdev\0");
attach_in_initrd = fstab_test_option(options, "x-initrd.attach\0");
name_escaped = specifier_escape(name); name_escaped = specifier_escape(name);
if (!name_escaped) if (!name_escaped)
@ -361,8 +371,10 @@ static int create_disk(
fprintf(f, "After=remote-fs-pre.target\n"); fprintf(f, "After=remote-fs-pre.target\n");
/* If initrd takes care of attaching the disk then it should also detach it during shutdown. */ /* If initrd takes care of attaching the disk then it should also detach it during shutdown. */
if (!attach_in_initrd) if (!attach_in_initrd(name, options))
fprintf(f, "Conflicts=umount.target\n"); fprintf(f,
"Conflicts=umount.target\n"
"Before=umount.target\n");
if (!nofail) if (!nofail)
fprintf(f, fprintf(f,
@ -372,8 +384,7 @@ static int create_disk(
if (path_startswith(du, "/dev/")) if (path_startswith(du, "/dev/"))
fprintf(f, fprintf(f,
"BindsTo=%s\n" "BindsTo=%s\n"
"After=%s\n" "After=%s\n",
"Before=umount.target\n",
dd, dd); dd, dd);
else else
/* For loopback devices, add systemd-tmpfiles-setup-dev.service /* For loopback devices, add systemd-tmpfiles-setup-dev.service
@ -388,8 +399,7 @@ static int create_disk(
if (path_startswith(hu, "/dev/")) if (path_startswith(hu, "/dev/"))
fprintf(f, fprintf(f,
"BindsTo=%s\n" "BindsTo=%s\n"
"After=%s\n" "After=%s\n",
"Before=umount.target\n",
hd, hd); hd, hd);
else else
/* For loopback devices, add systemd-tmpfiles-setup-dev.service /* For loopback devices, add systemd-tmpfiles-setup-dev.service