diff --git a/man/systemd-fsck@.service.xml b/man/systemd-fsck@.service.xml
index b0e2ebafbd..3df215ba1f 100644
--- a/man/systemd-fsck@.service.xml
+++ b/man/systemd-fsck@.service.xml
@@ -110,6 +110,34 @@
+
+ Credentials
+
+ systemd-fsck supports the service credentials logic as implemented by
+ ImportCredential=/LoadCredential=/SetCredential=
+ (see systemd.exec5 for
+ details). The following credentials are used when passed in:
+
+
+
+ fsck.mode
+ fsck.repair
+
+
+ The contents of the credentials are parsed as same as the kernel command line options with
+ the same name. See above for more details.
+
+
+
+
+
+
+ Note that by default the systemd-fsck@.service,
+ systemd-fsck-root.service, and systemd-fsck-usr.service unit
+ files are set up to inherit both fsck.mode and fsck.repair
+ credentials from the service manager.
+
+
See Also
diff --git a/man/systemd.system-credentials.xml b/man/systemd.system-credentials.xml
index d436cff5d4..0411061ca3 100644
--- a/man/systemd.system-credentials.xml
+++ b/man/systemd.system-credentials.xml
@@ -510,6 +510,20 @@
+
+
+ fsck.*
+
+
+ Read by systemd-fsck@.service,
+ systemd-fsck-root.service, and systemd-fsck-usr.service.
+ See
+ systemd-fsck@.service8
+ for more details.
+
+
+
+
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 7f2b0f5d36..1d7f4ea3af 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -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)
diff --git a/src/shared/generator.c b/src/shared/generator.c
index ea665a6c33..f978d43fe8 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -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,
diff --git a/test/test-fstab-generator/test-12-dev-sdx.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-12-dev-sdx.expected/systemd-fsck-root.service
index 147348899d..797ffa08db 100644
--- a/test/test-fstab-generator/test-12-dev-sdx.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-12-dev-sdx.expected/systemd-fsck-root.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/test/test-fstab-generator/test-13-label.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-13-label.expected/systemd-fsck-root.service
index 85c1936bce..ee146aa3b2 100644
--- a/test/test-fstab-generator/test-13-label.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-13-label.expected/systemd-fsck-root.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/disk/by-label/Root
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/test/test-fstab-generator/test-14-uuid.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-14-uuid.expected/systemd-fsck-root.service
index 1c7eaea103..73e9134fb1 100644
--- a/test/test-fstab-generator/test-14-uuid.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-14-uuid.expected/systemd-fsck-root.service
@@ -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.*
diff --git a/test/test-fstab-generator/test-15-partuuid.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-15-partuuid.expected/systemd-fsck-root.service
index ab27bfd79c..2d5c9bfbfd 100644
--- a/test/test-fstab-generator/test-15-partuuid.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-15-partuuid.expected/systemd-fsck-root.service
@@ -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.*
diff --git a/test/test-fstab-generator/test-17-initrd-sysroot.fstab.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-17-initrd-sysroot.fstab.expected/systemd-fsck-root.service
index 147348899d..797ffa08db 100644
--- a/test/test-fstab-generator/test-17-initrd-sysroot.fstab.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-17-initrd-sysroot.fstab.expected/systemd-fsck-root.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/test/test-fstab-generator/test-18-options.fstab.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-18-options.fstab.expected/systemd-fsck-root.service
index 147348899d..797ffa08db 100644
--- a/test/test-fstab-generator/test-18-options.fstab.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-18-options.fstab.expected/systemd-fsck-root.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-root.service b/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-root.service
index 147348899d..797ffa08db 100644
--- a/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-root.service
+++ b/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-root.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx1
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-usr.service b/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-usr.service
index 512e7b1636..61c0af0490 100644
--- a/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-usr.service
+++ b/test/test-fstab-generator/test-19-mounts-from-cmdline.expected/systemd-fsck-usr.service
@@ -15,3 +15,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-fsck /dev/sdx5
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/units/systemd-fsck-root.service.in b/units/systemd-fsck-root.service.in
index ebe8262a49..22e86acadd 100644
--- a/units/systemd-fsck-root.service.in
+++ b/units/systemd-fsck-root.service.in
@@ -22,3 +22,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart={{LIBEXECDIR}}/systemd-fsck
TimeoutSec=infinity
+ImportCredential=fsck.*
diff --git a/units/systemd-fsck@.service.in b/units/systemd-fsck@.service.in
index 8eb4821d41..d5caed6ae0 100644
--- a/units/systemd-fsck@.service.in
+++ b/units/systemd-fsck@.service.in
@@ -22,3 +22,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart={{LIBEXECDIR}}/systemd-fsck %f
TimeoutSec=infinity
+ImportCredential=fsck.*