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

fsck: add fsck.mode and fsck.repair credentials support

Maybe useful when kernel command line is hard to change, e.g. when UKI
is used.
This commit is contained in:
Yu Watanabe
2025-07-13 04:25:26 +09:00
parent a85428b1d3
commit 059afcadfd
14 changed files with 82 additions and 1 deletions

View File

@@ -110,6 +110,34 @@
</variablelist>
</refsect1>
<refsect1>
<title>Credentials</title>
<para><command>systemd-fsck</command> supports the service credentials logic as implemented by
<varname>ImportCredential=</varname>/<varname>LoadCredential=</varname>/<varname>SetCredential=</varname>
(see <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
details). The following credentials are used when passed in:</para>
<variablelist class='system-credentials'>
<varlistentry>
<term><varname>fsck.mode</varname></term>
<term><varname>fsck.repair</varname></term>
<listitem>
<para>The contents of the credentials are parsed as same as the kernel command line options with
the same name. See above for more details.</para>
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
</variablelist>
<para>Note that by default the <filename>systemd-fsck@.service</filename>,
<filename>systemd-fsck-root.service</filename>, and <filename>systemd-fsck-usr.service</filename> unit
files are set up to inherit both <varname>fsck.mode</varname> and <varname>fsck.repair</varname>
credentials from the service manager.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para><simplelist type="inline">

View File

@@ -510,6 +510,20 @@
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>fsck.*</varname></term>
<listitem>
<para>Read by <filename>systemd-fsck@.service</filename>,
<filename>systemd-fsck-root.service</filename>, and <filename>systemd-fsck-usr.service</filename>.
See
<citerefentry><refentrytitle>systemd-fsck@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
for more details.</para>
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@@ -16,6 +16,7 @@
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-util.h"
#include "creds-util.h"
#include "device-util.h"
#include "fd-util.h"
#include "fs-util.h"
@@ -129,6 +130,31 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
return 0;
}
static void parse_credentials(void) {
_cleanup_free_ char *value = NULL;
int r;
r = read_credential("fsck.mode", (void**) &value, /* ret_size = */ NULL);
if (r < 0)
log_debug_errno(r, "Failed to read credential 'fsck.mode', ignoring: %m");
else {
arg_mode = fsck_mode_from_string(value);
if (arg_mode < 0)
log_warning_errno(arg_mode, "Invalid 'fsck.mode' credential, ignoring: %s", value);
}
value = mfree(value);
r = read_credential("fsck.repair", (void**) &value, /* ret_size = */ NULL);
if (r < 0)
log_debug_errno(r, "Failed to read credential 'fsck.repair', ignoring: %m");
else {
arg_repair = fsck_repair_from_string(value);
if (arg_repair < 0)
log_warning_errno(arg_repair, "Invalid 'fsck.repair' credential, ignoring: %s", value);
}
}
static double percent(int pass, unsigned long cur, unsigned long max) {
/* Values stolen from e2fsck */
@@ -256,6 +282,8 @@ static int run(int argc, char *argv[]) {
if (r < 0)
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
parse_credentials();
bool show_progress = access("/run/systemd/show-status", F_OK) >= 0;
if (arg_mode == FSCK_SKIP)

View File

@@ -250,7 +250,8 @@ static int write_fsck_sysroot_service(
"Type=oneshot\n"
"RemainAfterExit=yes\n"
"ExecStart=" SYSTEMD_FSCK_PATH " %6$s\n"
"TimeoutSec=infinity\n",
"TimeoutSec=infinity\n"
"ImportCredential=fsck.*\n",
escaped,
unit,
device,

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/disk/by-label/Root
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/disk/by-uuid/3f5ad593-4546-4a94-a374-bcfb68aa11f7
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/disk/by-partuuid/3f5ad593-4546-4a94-a374-bcfb68aa11f7
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx5
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -22,3 +22,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart={{LIBEXECDIR}}/systemd-fsck
TimeoutSec=infinity
ImportCredential=fsck.*

View File

@@ -22,3 +22,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart={{LIBEXECDIR}}/systemd-fsck %f
TimeoutSec=infinity
ImportCredential=fsck.*