diff --git a/man/systemd.special.xml b/man/systemd.special.xml
index 248fb924db..c839af1842 100644
--- a/man/systemd.special.xml
+++ b/man/systemd.special.xml
@@ -38,6 +38,7 @@
hibernate.target,
hybrid-sleep.target,
suspend-then-hibernate.target,
+ initrd.target,
initrd-fs.target,
initrd-root-device.target,
initrd-root-fs.target,
@@ -202,14 +203,16 @@
default.target
- The default unit systemd starts at bootup. Usually,
- this should be aliased (symlinked) to
- multi-user.target or
- graphical.target.
+ The default unit systemd starts at bootup. Usually, this should be aliased (symlinked) to
+ multi-user.target or graphical.target. See
+ bootup7 for
+ more discussion.
- The default unit systemd starts at bootup can be
- overridden with the systemd.unit= kernel
- command line option.
+ The default unit systemd starts at bootup can be overridden with the
+ systemd.unit= kernel command line option, or more conveniently, with the short
+ names like single, rescue, 1,
+ 3, 5, …; see
+ systemd1.
@@ -341,6 +344,15 @@
is active as long as the system is running.
+
+ initrd.target
+
+ This is the default target in the initramfs, similar to default.target
+ in the main system. It is used to mount the real root and transition to it. See
+ bootup7 for
+ more discussion.
+
+
initrd-fs.target
diff --git a/src/basic/special.h b/src/basic/special.h
index add1c1d507..0eb3f3a368 100644
--- a/src/basic/special.h
+++ b/src/basic/special.h
@@ -2,6 +2,7 @@
#pragma once
#define SPECIAL_DEFAULT_TARGET "default.target"
+#define SPECIAL_INITRD_TARGET "initrd.target"
/* Shutdown targets */
#define SPECIAL_UMOUNT_TARGET "umount.target"
diff --git a/src/core/main.c b/src/core/main.c
index 40ac88fbb4..e800ac3ced 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1997,20 +1997,36 @@ static int do_queue_default_job(
const char **ret_error_message) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ const char* default_unit;
Job *default_unit_job;
Unit *target = NULL;
int r;
- log_debug("Activating default unit: %s", arg_default_unit);
+ if (arg_default_unit)
+ default_unit = arg_default_unit;
+ else if (in_initrd())
+ default_unit = SPECIAL_INITRD_TARGET;
+ else
+ default_unit = SPECIAL_DEFAULT_TARGET;
- r = manager_load_startable_unit_or_warn(m, arg_default_unit, NULL, &target);
+ log_debug("Activating default unit: %s", default_unit);
+
+ r = manager_load_startable_unit_or_warn(m, default_unit, NULL, &target);
+ if (r < 0 && in_initrd() && !arg_default_unit) {
+ /* Fall back to default.target, which we used to always use by default. Only do this if no
+ * explicit configuration was given. */
+
+ log_info("Falling back to " SPECIAL_DEFAULT_TARGET ".");
+
+ r = manager_load_startable_unit_or_warn(m, SPECIAL_DEFAULT_TARGET, NULL, &target);
+ }
if (r < 0) {
- log_info("Falling back to rescue target: " SPECIAL_RESCUE_TARGET);
+ log_info("Falling back to " SPECIAL_RESCUE_TARGET ".");
r = manager_load_startable_unit_or_warn(m, SPECIAL_RESCUE_TARGET, NULL, &target);
if (r < 0) {
- *ret_error_message = r == -ERFKILL ? "Rescue target masked"
- : "Failed to load rescue target";
+ *ret_error_message = r == -ERFKILL ? SPECIAL_RESCUE_TARGET " masked"
+ : "Failed to load " SPECIAL_RESCUE_TARGET;
return r;
}
}
@@ -2222,15 +2238,6 @@ static int load_configuration(
return r;
}
- /* Initialize default unit */
- if (!arg_default_unit) {
- arg_default_unit = strdup(SPECIAL_DEFAULT_TARGET);
- if (!arg_default_unit) {
- *ret_error_message = "Failed to set default unit";
- return log_oom();
- }
- }
-
/* Initialize the show status setting if it hasn't been set explicitly yet */
if (arg_show_status == _SHOW_STATUS_INVALID)
arg_show_status = SHOW_STATUS_YES;
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c
index bc8714c4c7..4e41eca352 100644
--- a/src/debug-generator/debug-generator.c
+++ b/src/debug-generator/debug-generator.c
@@ -126,7 +126,15 @@ static int generate_wants_symlinks(void) {
STRV_FOREACH(u, arg_wants) {
_cleanup_free_ char *p = NULL, *f = NULL;
- const char *target = arg_default_unit ?: SPECIAL_DEFAULT_TARGET;
+ const char *target;
+
+ /* This should match what do_queue_default_job() in core/main.c does. */
+ if (arg_default_unit)
+ target = arg_default_unit;
+ else if (in_initrd())
+ target = SPECIAL_INITRD_TARGET;
+ else
+ target = SPECIAL_DEFAULT_TARGET;
p = strjoin(arg_dest, "/", target, ".wants/", *u);
if (!p)
diff --git a/src/journal-remote/journal-upload.h b/src/journal-remote/journal-upload.h
index 5711905f86..4994cd8391 100644
--- a/src/journal-remote/journal-upload.h
+++ b/src/journal-remote/journal-upload.h
@@ -4,6 +4,7 @@
#include "sd-event.h"
#include "sd-journal.h"
+
#include "time-util.h"
typedef enum {
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 9e51bf74f5..546b5d02c4 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -6,6 +6,7 @@
#include
#include "sd-dhcp-server.h"
+#include "sd-id128.h"
#include "alloc-util.h"
#include "dhcp-internal.h"
@@ -13,7 +14,6 @@
#include "fd-util.h"
#include "in-addr-util.h"
#include "io-util.h"
-#include "sd-id128.h"
#include "siphash24.h"
#include "string-util.h"
#include "unaligned.h"
diff --git a/src/run-generator/run-generator.c b/src/run-generator/run-generator.c
index 7d6c110912..a149b9c9c2 100644
--- a/src/run-generator/run-generator.c
+++ b/src/run-generator/run-generator.c
@@ -9,6 +9,7 @@
#include "generator.h"
#include "mkdir.h"
#include "proc-cmdline.h"
+#include "special.h"
#include "specifier.h"
#include "strv.h"
@@ -116,7 +117,7 @@ static int generate(void) {
return log_error_errno(r, "Failed to create unit file %s: %m", p);
/* And now redirect default.target to our new target */
- p = strjoina(arg_dest, "/default.target");
+ p = strjoina(arg_dest, "/" SPECIAL_DEFAULT_TARGET);
if (symlink("kernel-command-line.target", p) < 0)
return log_error_errno(errno, "Failed to link unit file kernel-command-line.target → %s: %m", p);
diff --git a/src/shared/bus-wait-for-jobs.h b/src/shared/bus-wait-for-jobs.h
index 8f21eb9cd6..614a2c9de9 100644
--- a/src/shared/bus-wait-for-jobs.h
+++ b/src/shared/bus-wait-for-jobs.h
@@ -2,6 +2,7 @@
#pragma once
#include "sd-bus.h"
+
#include "macro.h"
typedef struct BusWaitForJobs BusWaitForJobs;
diff --git a/src/shared/journal-importer.h b/src/shared/journal-importer.h
index b2e3c817f5..783edff5d3 100644
--- a/src/shared/journal-importer.h
+++ b/src/shared/journal-importer.h
@@ -6,8 +6,9 @@
#include
#include
-#include "io-util.h"
#include "sd-id128.h"
+
+#include "io-util.h"
#include "time-util.h"
/* Make sure not to make this smaller than the maximum coredump size.
diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c
index 6d65efbb9e..4cf9d22c87 100644
--- a/src/sulogin-shell/sulogin-shell.c
+++ b/src/sulogin-shell/sulogin-shell.c
@@ -6,14 +6,16 @@
#include
#include
+#include "sd-bus.h"
+
#include "bus-util.h"
#include "bus-error.h"
#include "def.h"
#include "env-util.h"
#include "log.h"
#include "process-util.h"
-#include "sd-bus.h"
#include "signal-util.h"
+#include "special.h"
static int reload_manager(sd_bus *bus) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -57,7 +59,7 @@ static int start_default_target(sd_bus *bus) {
"StartUnit",
&error,
NULL,
- "ss", "default.target", "isolate");
+ "ss", SPECIAL_DEFAULT_TARGET, "isolate");
if (r < 0)
return log_error_errno(r, "Failed to start default target: %s", bus_error_message(&error, r));