Pull in systemd-remount-fs.service only when required

Instead of enabling it unconditionally and then using ConditionPathExists=/etc/fstab,
and possibly masking this condition if it should be enabled for auto gpt stuff,
just pull it in explicitly when required.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-12-20 15:52:52 +01:00
parent 2572957e45
commit 9b69569d2c
7 changed files with 26 additions and 6 deletions

View File

@ -50,6 +50,13 @@
<para>For a longer discussion of kernel API file systems see
<ulink url="https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems">API
File Systems</ulink>.</para>
<para>Note: <filename>systemd-remount-fs.service</filename> is usually pulled in by
<citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
hence it is also affected by the kernel command line option <varname>fstab=</varname>, which may be used
to disable the generator. It may also pulled in by
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
which is affected by <varname>systemd.gpt_auto</varname> and other options.</para>
</refsect1>
<refsect1>
@ -57,7 +64,9 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry project='man-pages'><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>
<citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
</para>
</refsect1>

View File

@ -890,6 +890,8 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
/* If running in the initrd also parse the /etc/fstab from the host */
if (in_initrd())
r3 = parse_fstab(true);
else
r3 = generator_enable_remount_fs_service(arg_dest);
}
return r < 0 ? r : r2 < 0 ? r2 : r3;

View File

@ -467,13 +467,13 @@ static int add_root_rw(DissectedPartition *p) {
return 0;
}
(void) generator_enable_remount_fs_service(arg_dest);
path = strjoina(arg_dest, "/systemd-remount-fs.service.d/50-remount-rw.conf");
(void) mkdir_parents(path, 0755);
r = write_string_file(path,
"# Automatically generated by systemd-gpt-generator\n\n"
"[Unit]\n"
"ConditionPathExists=\n\n" /* We need to turn off the ConditionPathExist= in the main unit file */
"[Service]\n"
"Environment=SYSTEMD_REMOUNT_ROOT_RW=1\n",
WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_NOFOLLOW);
@ -678,6 +678,9 @@ static int add_root_mount(void) {
return r;
}
/* Note that we do not need to enable systemd-remount-fs.service here. If
* /etc/fstab exists, systemd-fstab-generator will pull it in for us. */
return add_mount(
"root",
"/dev/gpt-auto-root",

View File

@ -499,6 +499,12 @@ int generator_hook_up_growfs(
return generator_add_symlink(dir, where_unit, "wants", unit);
}
int generator_enable_remount_fs_service(const char *dir) {
/* Pull in systemd-remount-fs.service */
return generator_add_symlink(dir, SPECIAL_LOCAL_FS_TARGET, "wants",
SYSTEM_DATA_UNIT_PATH "/" SPECIAL_REMOUNT_FS_SERVICE);
}
void log_setup_generator(void) {
log_set_prohibit_ipc(true);
log_setup_service();

View File

@ -50,6 +50,8 @@ int generator_hook_up_growfs(
const char *where,
const char *target);
int generator_enable_remount_fs_service(const char *dir);
void log_setup_generator(void);
/* Similar to DEFINE_MAIN_FUNCTION, but initializes logging and assigns positional arguments. */

View File

@ -186,8 +186,7 @@ in_units = [
['systemd-quotacheck.service', 'ENABLE_QUOTACHECK'],
['systemd-random-seed.service', 'ENABLE_RANDOMSEED',
'sysinit.target.wants/'],
['systemd-remount-fs.service', '',
'local-fs.target.wants/'],
['systemd-remount-fs.service', ''],
['systemd-resolved.service', 'ENABLE_RESOLVE',
join_paths(pkgsysconfdir, 'system/dbus-org.freedesktop.resolve1.service') + ' ' +
join_paths(pkgsysconfdir, 'system/multi-user.target.wants/')],

View File

@ -16,7 +16,6 @@ Conflicts=shutdown.target
After=systemd-fsck-root.service
Before=local-fs-pre.target local-fs.target shutdown.target
Wants=local-fs-pre.target
ConditionPathExists=/etc/fstab
[Service]
Type=oneshot