Skip to content

Commit

Permalink
fstab-generator: optional read addtional fstab lines from credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
poettering committed Jun 30, 2023
1 parent 12a316b commit d873238
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions man/systemd-fstab-generator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ systemd.swap=/dev/sda2:x-systemd.makefs</programlisting>
</variablelist>
</refsect1>

<refsect1>
<title>System Credentials</title>

<variablelist class='system-credentials'>
<varlistentry>
<term><varname>fstab.extra</varname></term>

<listitem><para>This credential may contain addition mounts to establish, in the same format as
<citerefentry
project='man-pages'><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>, with
one mount per line. It is read in addition to <filename>/etc/fstab</filename>.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1>
<title>See Also</title>
<para>
Expand Down
9 changes: 9 additions & 0 deletions man/systemd.system-credentials.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@
</listitem>
</varlistentry>

<varlistentry>
<term><varname>fstab.extra</varname></term>

<listitem>
<para>Additional mounts to establish at boot. For details, see
<citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>vconsole.keymap</varname></term>
<term><varname>vconsole.keymap_toggle</varname></term>
Expand Down
39 changes: 39 additions & 0 deletions src/fstab-generator/fstab-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "bus-error.h"
#include "bus-locator.h"
#include "chase.h"
#include "creds-util.h"
#include "efi-loader.h"
#include "env-util.h"
#include "fd-util.h"
Expand Down Expand Up @@ -1281,6 +1282,40 @@ static int add_mounts_from_cmdline(void) {
return ret;
}

static int add_mounts_from_creds(void) {
_cleanup_free_ void *b = NULL;
struct mntent *me;
int r, ret = 0;
size_t bs;

r = read_credential_with_decryption(
in_initrd() ? "fstab.extra.initrd" : "fstab.extra",
&b, &bs);
if (r <= 0)
return r;

_cleanup_fclose_ FILE *f = NULL;
f = fmemopen_unlocked(b, bs, "r");
if (!f)
return log_oom();

while ((me = getmntent(f))) {
r = parse_fstab_one(
"/run/credentials",
me->mnt_fsname,
me->mnt_dir,
me->mnt_type,
me->mnt_opts,
me->mnt_passno,
/* initrd = */ false,
/* use_swap_enabled = */ true);
if (r < 0 && ret >= 0)
ret = r;
}

return ret;
}

static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
int r;

Expand Down Expand Up @@ -1513,6 +1548,10 @@ static int run_generator(void) {
if (r < 0 && ret >= 0)
ret = r;

r = add_mounts_from_creds();
if (r < 0 && ret >= 0)
ret = r;

return ret;
}

Expand Down

0 comments on commit d873238

Please sign in to comment.