Skip to content

Commit

Permalink
Pull in systemd-remount-fs.service only when required
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keszybz committed Jan 3, 2019
1 parent 2572957 commit 9b69569
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
11 changes: 10 additions & 1 deletion man/systemd-remount-fs.service.xml
Expand Up @@ -50,14 +50,23 @@
<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>
<title>See Also</title>
<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>

Expand Down
2 changes: 2 additions & 0 deletions src/fstab-generator/fstab-generator.c
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/gpt-auto-generator/gpt-auto-generator.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/shared/generator.c
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/shared/generator.h
Expand Up @@ -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. */
Expand Down
3 changes: 1 addition & 2 deletions units/meson.build
Expand Up @@ -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/')],
Expand Down
1 change: 0 additions & 1 deletion units/systemd-remount-fs.service.in
Expand Up @@ -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
Expand Down

0 comments on commit 9b69569

Please sign in to comment.