mirror of
https://github.com/systemd/systemd.git
synced 2025-01-05 13:18:06 +03:00
Make initrd.target the default target in the initrd
First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd.target can be the default target in the initrd. (normal startup) : : v basic.target | ______________________/| / | | sysroot.mount | | | v | initrd-root-fs.target | | | v | initrd-parse-etc.service (custom initrd services) | | v | (sysroot-usr.mount and | various mounts marked | with fstab option | x-initrd.mount) | | | v | initrd-fs.target | | \______________________ | \| v initrd.target | v initrd-cleanup.service isolates to initrd-switch-root.target | v ______________________/| / | | initrd-udevadm-cleanup-db.service | | (custom initrd services) | | | \______________________ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root
This commit is contained in:
parent
c1dae1b3c9
commit
9e5f0f9291
@ -347,8 +347,9 @@ dist_systemunit_DATA = \
|
|||||||
units/kexec.target \
|
units/kexec.target \
|
||||||
units/local-fs.target \
|
units/local-fs.target \
|
||||||
units/local-fs-pre.target \
|
units/local-fs-pre.target \
|
||||||
|
units/initrd.target \
|
||||||
units/initrd-fs.target \
|
units/initrd-fs.target \
|
||||||
units/root-fs.target \
|
units/initrd-root-fs.target \
|
||||||
units/remote-fs.target \
|
units/remote-fs.target \
|
||||||
units/remote-fs-pre.target \
|
units/remote-fs-pre.target \
|
||||||
units/network.target \
|
units/network.target \
|
||||||
|
@ -173,6 +173,79 @@
|
|||||||
to them.</para>
|
to them.</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Systemd in the Initrd</title>
|
||||||
|
<para>If the initrd creation tool used the services provided
|
||||||
|
by systemd, the default target in the initrd is the
|
||||||
|
initrd-fs.target. The process is the same as above until the basic.target is reached.
|
||||||
|
Systemd now continues to the initrd.target. If the root device could be mounted
|
||||||
|
on /sysroot, the sysroot.mount unit is active and the initrd-root-fs.target is reached.
|
||||||
|
initrd-parse-etc.service scans /sysroot/etc/fstab for the /usr mountpoint and for entries
|
||||||
|
marked with the <emphasis>x-initrd.mount</emphasis> option set. If these mountpoint are
|
||||||
|
mounted in /sysroot, the initrd-fs.target is reached.
|
||||||
|
The initrd-cleanup.service isolates to the initrd-switch-root.target,
|
||||||
|
where cleanup services can run. At the very last end
|
||||||
|
initrd-switch-root.service is activated, which will cause
|
||||||
|
the system to switch root to /sysroot.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
(same as above)
|
||||||
|
:
|
||||||
|
:
|
||||||
|
v
|
||||||
|
basic.target
|
||||||
|
| emergency.service
|
||||||
|
______________________/| |
|
||||||
|
/ | v
|
||||||
|
| sysroot.mount <emphasis>emergency.target</emphasis>
|
||||||
|
| |
|
||||||
|
| v
|
||||||
|
| initrd-root-fs.target
|
||||||
|
| |
|
||||||
|
| v
|
||||||
|
| initrd-parse-etc.service
|
||||||
|
(custom initrd services) |
|
||||||
|
| v
|
||||||
|
| (sysroot-usr.mount and
|
||||||
|
| various mounts marked
|
||||||
|
| with fstab option
|
||||||
|
| x-initrd.mount)
|
||||||
|
| |
|
||||||
|
| v
|
||||||
|
| initrd-fs.target
|
||||||
|
| |
|
||||||
|
\______________________ |
|
||||||
|
\|
|
||||||
|
v
|
||||||
|
initrd.target
|
||||||
|
|
|
||||||
|
v
|
||||||
|
initrd-cleanup.service
|
||||||
|
isolates to
|
||||||
|
initrd-switch-root.target
|
||||||
|
|
|
||||||
|
v
|
||||||
|
______________________/|
|
||||||
|
/ |
|
||||||
|
| initrd-udevadm-cleanup-db.service
|
||||||
|
| |
|
||||||
|
(custom initrd services) |
|
||||||
|
| |
|
||||||
|
\______________________ |
|
||||||
|
\|
|
||||||
|
v
|
||||||
|
initrd-switch-root.target
|
||||||
|
|
|
||||||
|
v
|
||||||
|
initrd-switch-root.service
|
||||||
|
|
|
||||||
|
v
|
||||||
|
switch-root
|
||||||
|
</programlisting>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>System Manager Shutdown</title>
|
<title>System Manager Shutdown</title>
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
<filename>remote-fs.target</filename>,
|
<filename>remote-fs.target</filename>,
|
||||||
<filename>remote-fs-pre.target</filename>,
|
<filename>remote-fs-pre.target</filename>,
|
||||||
<filename>rescue.target</filename>,
|
<filename>rescue.target</filename>,
|
||||||
<filename>root-fs.target</filename>,
|
<filename>initrd-root-fs.target</filename>,
|
||||||
<filename>rpcbind.target</filename>,
|
<filename>rpcbind.target</filename>,
|
||||||
<filename>runlevel2.target</filename>,
|
<filename>runlevel2.target</filename>,
|
||||||
<filename>runlevel3.target</filename>,
|
<filename>runlevel3.target</filename>,
|
||||||
@ -523,7 +523,7 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><filename>root-fs.target</filename></term>
|
<term><filename>initrd-root-fs.target</filename></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>systemd automatically
|
<para>systemd automatically
|
||||||
adds dependencies of type
|
adds dependencies of type
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#define SPECIAL_LOCAL_FS_TARGET "local-fs.target"
|
#define SPECIAL_LOCAL_FS_TARGET "local-fs.target"
|
||||||
#define SPECIAL_LOCAL_FS_PRE_TARGET "local-fs-pre.target"
|
#define SPECIAL_LOCAL_FS_PRE_TARGET "local-fs-pre.target"
|
||||||
#define SPECIAL_INITRD_FS_TARGET "initrd-fs.target"
|
#define SPECIAL_INITRD_FS_TARGET "initrd-fs.target"
|
||||||
#define SPECIAL_ROOT_FS_TARGET "root-fs.target"
|
#define SPECIAL_INITRD_ROOT_FS_TARGET "initrd-root-fs.target"
|
||||||
#define SPECIAL_REMOTE_FS_TARGET "remote-fs.target" /* LSB's $remote_fs */
|
#define SPECIAL_REMOTE_FS_TARGET "remote-fs.target" /* LSB's $remote_fs */
|
||||||
#define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-pre.target"
|
#define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-pre.target"
|
||||||
#define SPECIAL_SWAP_TARGET "swap.target"
|
#define SPECIAL_SWAP_TARGET "swap.target"
|
||||||
|
@ -199,6 +199,12 @@ static bool mount_in_initrd(struct mntent *me) {
|
|||||||
streq(me->mnt_dir, "/usr");
|
streq(me->mnt_dir, "/usr");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool mount_is_rootfs(struct mntent *me) {
|
||||||
|
assert(me);
|
||||||
|
|
||||||
|
return hasmntopt(me, "x-initrd-rootfs.mount");
|
||||||
|
}
|
||||||
|
|
||||||
static int add_mount(const char *what, const char *where, const char *type, const char *opts,
|
static int add_mount(const char *what, const char *where, const char *type, const char *opts,
|
||||||
int passno, bool noauto, bool nofail, bool automount, bool isbind,
|
int passno, bool noauto, bool nofail, bool automount, bool isbind,
|
||||||
const char *pre, const char *post, const char *source) {
|
const char *pre, const char *post, const char *source) {
|
||||||
@ -434,6 +440,9 @@ static int parse_fstab(const char *prefix, bool initrd) {
|
|||||||
if (initrd) {
|
if (initrd) {
|
||||||
post = SPECIAL_INITRD_FS_TARGET;
|
post = SPECIAL_INITRD_FS_TARGET;
|
||||||
pre = NULL;
|
pre = NULL;
|
||||||
|
} else if (mount_is_rootfs(me)) {
|
||||||
|
post = SPECIAL_INITRD_ROOT_FS_TARGET;
|
||||||
|
pre = NULL;
|
||||||
} else if (mount_is_network(me)) {
|
} else if (mount_is_network(me)) {
|
||||||
post = SPECIAL_REMOTE_FS_TARGET;
|
post = SPECIAL_REMOTE_FS_TARGET;
|
||||||
pre = SPECIAL_REMOTE_FS_PRE_TARGET;
|
pre = SPECIAL_REMOTE_FS_PRE_TARGET;
|
||||||
@ -525,7 +534,7 @@ static int parse_new_root_from_proc_cmdline(void) {
|
|||||||
|
|
||||||
log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
|
log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
|
||||||
r = add_mount(what, "/sysroot", type, opts, 0, false, false, false,
|
r = add_mount(what, "/sysroot", type, opts, 0, false, false, false,
|
||||||
false, NULL, SPECIAL_ROOT_FS_TARGET, "/proc/cmdline");
|
false, NULL, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
|
||||||
|
|
||||||
return (r < 0) ? r : 0;
|
return (r < 0) ? r : 0;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ Description=Cleaning Up and Shutting Down Daemons
|
|||||||
DefaultDependencies=no
|
DefaultDependencies=no
|
||||||
ConditionPathExists=/etc/initrd-release
|
ConditionPathExists=/etc/initrd-release
|
||||||
OnFailure=emergency.target
|
OnFailure=emergency.target
|
||||||
Wants=root-fs.target initrd-fs.target
|
After=initrd-root-fs.target initrd-fs.target initrd.target
|
||||||
After=root-fs.target initrd-fs.target
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
@ -11,3 +11,4 @@ Documentation=man:systemd.special(7)
|
|||||||
OnFailure=emergency.target
|
OnFailure=emergency.target
|
||||||
OnFailureIsolate=yes
|
OnFailureIsolate=yes
|
||||||
ConditionPathExists=/etc/initrd-release
|
ConditionPathExists=/etc/initrd-release
|
||||||
|
After=initrd-parse-etc.service
|
||||||
|
@ -8,13 +8,14 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Reload Configuration from the Real Root
|
Description=Reload Configuration from the Real Root
|
||||||
DefaultDependencies=no
|
DefaultDependencies=no
|
||||||
Requires=root-fs.target
|
Requires=initrd-root-fs.target
|
||||||
After=root-fs.target
|
After=initrd-root-fs.target
|
||||||
OnFailure=emergency.target
|
OnFailure=emergency.target
|
||||||
ConditionPathExists=/etc/initrd-release
|
ConditionPathExists=/etc/initrd-release
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStartPre=@rootbindir@/systemctl daemon-reload
|
ExecStartPre=@rootbindir@/systemctl daemon-reload
|
||||||
ExecStart=@rootbindir@/systemctl start initrd-fs.target
|
# we have to retrigger initrd-fs.target after daemon-reload
|
||||||
|
ExecStart=-@rootbindir@/systemctl --no-block start initrd-fs.target
|
||||||
ExecStart=@rootbindir@/systemctl --no-block start initrd-cleanup.service
|
ExecStart=@rootbindir@/systemctl --no-block start initrd-cleanup.service
|
||||||
|
@ -9,3 +9,5 @@
|
|||||||
Description=Initrd Root File System
|
Description=Initrd Root File System
|
||||||
Documentation=man:systemd.special(7)
|
Documentation=man:systemd.special(7)
|
||||||
ConditionPathExists=/etc/initrd-release
|
ConditionPathExists=/etc/initrd-release
|
||||||
|
OnFailure=emergency.target
|
||||||
|
OnFailureIsolate=yes
|
@ -12,5 +12,5 @@ DefaultDependencies=no
|
|||||||
Requires=initrd-switch-root.service
|
Requires=initrd-switch-root.service
|
||||||
Before=initrd-switch-root.service
|
Before=initrd-switch-root.service
|
||||||
AllowIsolate=yes
|
AllowIsolate=yes
|
||||||
Wants=initrd-udevadm-cleanup-db.service root-fs.target initrd-fs.target systemd-journald.service
|
Wants=initrd-udevadm-cleanup-db.service initrd-root-fs.target initrd-fs.target systemd-journald.service
|
||||||
After=initrd-udevadm-cleanup-db.service root-fs.target initrd-fs.target emergency.service emergency.target
|
After=initrd-udevadm-cleanup-db.service initrd-root-fs.target initrd-fs.target emergency.service emergency.target
|
||||||
|
17
units/initrd.target
Normal file
17
units/initrd.target
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# This file is part of systemd.
|
||||||
|
#
|
||||||
|
# systemd is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Lesser General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Initrd Target
|
||||||
|
Documentation=man:systemd.special(7)
|
||||||
|
OnFailure=emergency.target
|
||||||
|
OnFailureIsolate=yes
|
||||||
|
ConditionPathExists=/etc/initrd-release
|
||||||
|
Requires=basic.target
|
||||||
|
Wants=initrd-root-fs.target initrd-fs.target initrd-parse-etc.service
|
||||||
|
After=initrd-root-fs.target initrd-fs.target basic.target rescue.service rescue.target
|
||||||
|
AllowIsolate=yes
|
Loading…
Reference in New Issue
Block a user