1
0
mirror of https://github.com/systemd/systemd synced 2025-10-02 18:24:46 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Lennart Poettering
725ad3b062 fstab-generator: add new root=tmpfs option
It's useful to be able to combine a regular /usr/ file system with a
tmpfs as root, for an OS that boots up in volatile mode on every single
boot.  Let's add explicit support for this via root=tmpfs.

Note the relationship to the existing systemd.volatile= option:

1. The kernel command line "root=/dev/… systemd.volatile=yes" will mount
   the specified root fs, and then hide everything at the top by
   overmounting it with a tmpfs, except for the /usr subtree.

2. The kernel command line "root=tmpfs mount.usr=/dev/…" otoh will mount
   a toot fs at the top (just like the case above), but will then mount
   the top-level dir of the fs specified in mount.usr= directly below
   it.

Or to say this differently: in the first case /usr/ from the physical
storage fs is going to become /usr/ of the hierarchy ultimately booted,
while in the second case / from the physical storage fs is going to
become /usr of the hierarchy booted.

Philosophically I figure systemd.volatile= is more an option for
"one-off" boots, while root=tmpfs is something to have as default mode
of operation for suitable images.

This is currently hard to test reasonably, since Dracut refuses to
accept root=tmpfs. This needs to be addressed separately though.
2021-03-03 12:16:32 +09:00
Lennart Poettering
ab05bee1dd time-util: simplify overflow check
And don't rely on 2s complement.
2021-03-03 12:16:21 +09:00
3 changed files with 54 additions and 17 deletions

View File

@ -82,9 +82,20 @@
<varlistentry> <varlistentry>
<term><varname>root=</varname></term> <term><varname>root=</varname></term>
<listitem><para>Takes the root filesystem to mount in the <listitem><para>Configures the operating system's root filesystem to mount when running in the
initrd. <varname>root=</varname> is honored by the initrd. This accepts a device node path (usually <filename>/dev/disk/by-uuid/…</filename> or
initrd.</para></listitem> <filename>/dev/disk/by-label/…</filename> or similar), or the special values <literal>gpt-auto</literal>
and <literal>tmpfs</literal>.</para>
<para>Use <literal>gpt-auto</literal> to explicitly request automatic root file system discovery via
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
<para>Use <literal>tmpfs</literal> in order to mount a <citerefentry
project='man-pages'><refentrytitle>tmpfs</refentrytitle><manvolnum>5</manvolnum></citerefentry> file
system as root file system of the OS. This is useful in combination with
<varname>mount.usr=</varname> (see below) in order to combine a volatile root file system with a
separate, immutable <filename>/usr/</filename> file system. Also see
<varname>systemd.volatile=</varname> below.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -193,10 +204,19 @@
or any other resources stored in the root file system are physically removed. It's thus safe to boot a system or any other resources stored in the root file system are physically removed. It's thus safe to boot a system
that is normally operated in non-volatile mode temporarily into volatile mode, without losing data.</para> that is normally operated in non-volatile mode temporarily into volatile mode, without losing data.</para>
<para>Note that with the exception of <literal>overlay</literal> mode, enabling this setting will only work <para>Note that with the exception of <literal>overlay</literal> mode, enabling this setting will
correctly on operating systems that can boot up with only <filename>/usr/</filename> mounted, and are able to only work correctly on operating systems that can boot up with only <filename>/usr/</filename>
automatically populate <filename>/etc/</filename>, and also <filename>/var/</filename> in case of mounted, and are able to automatically populate <filename>/etc/</filename>, and also
<literal>systemd.volatile=yes</literal>.</para></listitem> <filename>/var/</filename> in case of <literal>systemd.volatile=yes</literal>.</para>
<para>Also see <varname>root=tmpfs</varname> above, for a method to combine a
<literal>tmpfs</literal> file system with a regular <filename>/usr/</filename> file system (as
configured via <varname>mount.usr=</varname>). The main distinction between
<varname>systemd.volatile=yes</varname>, and <varname>root=tmpfs</varname> in combination
<varname>mount.usr=</varname> is that the former operates on top of a regular root file system and
temporarily obstructs the files and directories above its <filename>/usr/</filename> subdirectory,
while the latter does not hide any files, but simply mounts a unpopulated tmpfs as root file system
and combines it with a user picked <filename>/usr/</filename> file system.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -218,6 +238,7 @@
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-cryptsetup-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd-cryptsetup-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry> <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>
</para> </para>
</refsect1> </refsect1>

View File

@ -155,16 +155,14 @@ usec_t jiffies_to_usec(uint32_t jiffies);
bool in_utc_timezone(void); bool in_utc_timezone(void);
static inline usec_t usec_add(usec_t a, usec_t b) { static inline usec_t usec_add(usec_t a, usec_t b) {
usec_t c;
/* Adds two time values, and makes sure USEC_INFINITY as input results as USEC_INFINITY in output, and doesn't /* Adds two time values, and makes sure USEC_INFINITY as input results as USEC_INFINITY in output, and doesn't
* overflow. */ * overflow. */
c = a + b; if (a > USEC_INFINITY - b) /* overflow check */
if (c < a || c < b) /* overflow check */
return USEC_INFINITY; return USEC_INFINITY;
return c; return a + b;
} }
static inline usec_t usec_sub_unsigned(usec_t timestamp, usec_t delta) { static inline usec_t usec_sub_unsigned(usec_t timestamp, usec_t delta) {

View File

@ -671,7 +671,8 @@ static int parse_fstab(bool initrd) {
static int add_sysroot_mount(void) { static int add_sysroot_mount(void) {
_cleanup_free_ char *what = NULL; _cleanup_free_ char *what = NULL;
const char *opts; const char *opts, *fstype;
bool default_rw;
int r; int r;
if (isempty(arg_root_what)) { if (isempty(arg_root_what)) {
@ -691,12 +692,29 @@ static int add_sysroot_mount(void) {
return 0; return 0;
} }
what = fstab_node_to_udev_node(arg_root_what); if (streq(arg_root_what, "tmpfs")) {
if (!what) /* If root=tmpfs is specified, then take this as shortcut for a writable tmpfs mount as root */
return log_oom();
what = strdup("rootfs"); /* just a pretty name, to show up in /proc/self/mountinfo */
if (!what)
return log_oom();
fstype = arg_root_fstype ?: "tmpfs"; /* tmpfs, unless overriden */
default_rw = true; /* writable, unless overriden */;
} else {
what = fstab_node_to_udev_node(arg_root_what);
if (!what)
return log_oom();
fstype = arg_root_fstype; /* if not specified explicitly, don't default to anything here */
default_rw = false; /* read-only, unless overriden */
}
if (!arg_root_options) if (!arg_root_options)
opts = arg_root_rw > 0 ? "rw" : "ro"; opts = arg_root_rw > 0 || (arg_root_rw < 0 && default_rw) ? "rw" : "ro";
else if (arg_root_rw >= 0 || else if (arg_root_rw >= 0 ||
!fstab_test_option(arg_root_options, "ro\0" "rw\0")) !fstab_test_option(arg_root_options, "ro\0" "rw\0"))
opts = strjoina(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro"); opts = strjoina(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro");
@ -715,7 +733,7 @@ static int add_sysroot_mount(void) {
what, what,
"/sysroot", "/sysroot",
NULL, NULL,
arg_root_fstype, fstype,
opts, opts,
is_device_path(what) ? 1 : 0, /* passno */ is_device_path(what) ? 1 : 0, /* passno */
0, /* makefs off, growfs off, noauto off, nofail off, automount off */ 0, /* makefs off, growfs off, noauto off, nofail off, automount off */