From c92f38218de9e9d5affcc9559c81beeb885fe300 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Thu, 31 Oct 2019 12:01:15 -0600 Subject: [PATCH 1/2] Backport: Add `ignition-subsequent.target` for non-Ignition boots This is needed for Red Hat CoreOS work for encrypted disks. With the CoreOS Assembler commit 8bcd5608c473a959dae240a6488ce3451ddcdc69, the `root=` and `rootflags` kargs are removed. Red Hat CoreOS is also using b29bf79c5bd27d683519cf2e236f6f9088f6d127 from Fedora CoreOS that uses a service to mount and locate the root filesystem on first boot via `ignition-ostree-mount-sysroot.service`. The problem, however, is that there are different dependencies/ordering if we're doing the "Ignition boot" versus a "subsequent" boot. Add a new target that's queued up if we detect we're doing a "subsequent" boot. --- dracut/30ignition/ignition-generator | 6 ++++++ dracut/30ignition/ignition-subsequent.target | 14 ++++++++++++++ dracut/30ignition/module-setup.sh | 3 +++ 3 files changed, 23 insertions(+) create mode 100644 dracut/30ignition/ignition-subsequent.target diff --git a/dracut/30ignition/ignition-generator b/dracut/30ignition/ignition-generator index 7033e96..812508b 100755 --- a/dracut/30ignition/ignition-generator +++ b/dracut/30ignition/ignition-generator @@ -56,6 +56,12 @@ if $(cmdline_bool 'ignition.firstboot' 0); then #Conflicts=dracut-emergency.service #EOF #fi +else + # If we're doing a non-Ignition (subsequent) boot, then + # queue a different target. This is necessary so that units + # like `ignition-ostree-mount-sysroot.service` + # can cleanly distinguish between the two. + add_requires ignition-subsequent.target initrd.target fi # Write ignition-setup.service customized for PXE/ISO or regular boot diff --git a/dracut/30ignition/ignition-subsequent.target b/dracut/30ignition/ignition-subsequent.target new file mode 100644 index 0000000..0282336 --- /dev/null +++ b/dracut/30ignition/ignition-subsequent.target @@ -0,0 +1,14 @@ +# This target is queued to run when Ignition will *not* run. +# It's intended right now for mounting sysroot, which happens in a quite +# different order on the Ignition boot versus "subsequent" boots. +[Unit] +Description=Subsequent (Not Ignition) boot complete +Before=initrd.target + +# See comments in ignition-complete.target +OnFailure=emergency.target +OnFailureJobMode=isolate + +# Make sure we stop all the units before switching root +Conflicts=initrd-switch-root.target umount.target +Conflicts=dracut-emergency.service emergency.service emergency.target diff --git a/dracut/30ignition/module-setup.sh b/dracut/30ignition/module-setup.sh index 3ed68d5..4ddb21a 100755 --- a/dracut/30ignition/module-setup.sh +++ b/dracut/30ignition/module-setup.sh @@ -60,6 +60,9 @@ install() { inst_simple "$moddir/coreos-teardown-initramfs-network.service" \ "$systemdutildir/system/coreos-teardown-initramfs-network.service" + inst_simple "$moddir/ignition-subsequent.target" \ + "$systemdsystemunitdir/ignition-subsequent.target" + # inst_simple "$moddir/sysroot-boot.service" \ # "$systemdsystemunitdir/sysroot-boot.service" From fff34fb30785594643ff81096b7ab24a7c88fce2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 7 Nov 2019 00:33:50 +0000 Subject: [PATCH 2/2] Minimal backport of ignition-complete.target This helps RHCOS rebase on the latest fedora-coreos-config changes. - Add a stub ignition-mount.service for ordering purposes - Don't change the dependencies of all of the units just yet to minimize churn --- dracut/30ignition/ignition-complete.target | 19 +++++++++++++ dracut/30ignition/ignition-generator | 13 ++++----- dracut/30ignition/ignition-mount.service | 31 ++++++++++++++++++++++ dracut/30ignition/module-setup.sh | 5 ++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 dracut/30ignition/ignition-complete.target create mode 100644 dracut/30ignition/ignition-mount.service diff --git a/dracut/30ignition/ignition-complete.target b/dracut/30ignition/ignition-complete.target new file mode 100644 index 0000000..7c447a4 --- /dev/null +++ b/dracut/30ignition/ignition-complete.target @@ -0,0 +1,19 @@ +# This target is reached when Ignition finishes running. Note that it gets +# activated *only* on first boot (or if ignition.firstboot=1 is provided). +# Thus, it is also an API for units to use so that they are activated only on +# first boot. Simply add a link under ignition-complete.target.requires in the +# initrd. +[Unit] +Description=Ignition Complete +Before=initrd.target + +# initrd.target has OnFailureJobMode=replace-irreversibly, which seems to +# cause unit restart loops in the initramfs if one of our units fails. Thus +# we intercept Ignition unit failures here and isolate to emergency.target. +# https://github.com/coreos/ignition-dracut/issues/115 +OnFailure=emergency.target +OnFailureJobMode=isolate + +# Make sure we stop all the units before switching root +Conflicts=initrd-switch-root.target umount.target +Conflicts=dracut-emergency.service emergency.service emergency.target diff --git a/dracut/30ignition/ignition-generator b/dracut/30ignition/ignition-generator index 812508b..897bfd1 100755 --- a/dracut/30ignition/ignition-generator +++ b/dracut/30ignition/ignition-generator @@ -27,7 +27,8 @@ cmdline_bool() { add_requires() { local name="$1"; shift - local requires_dir="${UNIT_DIR}/initrd.target.requires" + local target="$1"; shift + local requires_dir="${UNIT_DIR}/${target}.requires" mkdir -p "${requires_dir}" ln -sf "../${name}" "${requires_dir}/${name}" } @@ -36,11 +37,11 @@ add_requires() { # starts the unit's dependencies. We want to start networkd only on first # boot. if $(cmdline_bool 'ignition.firstboot' 0); then - add_requires ignition-fetch.service - add_requires ignition-disks.service - add_requires ignition-files.service - add_requires ignition-ask-var-mount.service - add_requires coreos-teardown-initramfs-network.service + add_requires ignition-complete.target initrd.target + for svc in fetch disks files mount ask-var-mount; do + add_requires ignition-${svc}.service initrd.target + done + add_requires coreos-teardown-initramfs-network.service initrd.target #if [[ $(cmdline_arg coreos.oem.id) == "packet" ]]; then # add_requires coreos-static-network.service #fi diff --git a/dracut/30ignition/ignition-mount.service b/dracut/30ignition/ignition-mount.service new file mode 100644 index 0000000..92ab9ec --- /dev/null +++ b/dracut/30ignition/ignition-mount.service @@ -0,0 +1,31 @@ +[Unit] +Description=Ignition (mount) [stub] +DefaultDependencies=false +Before=ignition-complete.target + +# This a copy of ignition-mount.service from master, but it does +# nothing right now. We just keep the dependencies to ensure +# other services are ordered correctly. + +# Make sure ExecStop= runs before we switch root +Before=initrd-switch-root.target + +# Make sure if ExecStop= fails, the boot fails +OnFailure=emergency.target +OnFailureJobMode=isolate + +# Make sure the final /sysroot is ready first, since we're mounting under there +Requires=initrd-root-fs.target +After=initrd-root-fs.target + +# Make sure root filesystem is remounted read-write if needed +After=ignition-remount-sysroot.service + +# This is guaranteed through After=initrd-root-fs.target but just to +# be explicit. +After=ignition-disks.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/true \ No newline at end of file diff --git a/dracut/30ignition/module-setup.sh b/dracut/30ignition/module-setup.sh index 4ddb21a..4de1937 100755 --- a/dracut/30ignition/module-setup.sh +++ b/dracut/30ignition/module-setup.sh @@ -51,6 +51,9 @@ install() { inst_simple "$moddir/ignition-files.service" \ "$systemdsystemunitdir/ignition-files.service" + inst_simple "$moddir/ignition-mount.service" \ + "$systemdsystemunitdir/ignition-mount.service" + inst_simple "$moddir/ignition-ask-var-mount.service" \ "$systemdsystemunitdir/ignition-ask-var-mount.service" @@ -60,6 +63,8 @@ install() { inst_simple "$moddir/coreos-teardown-initramfs-network.service" \ "$systemdutildir/system/coreos-teardown-initramfs-network.service" + inst_simple "$moddir/ignition-complete.target" \ + "$systemdsystemunitdir/ignition-complete.target" inst_simple "$moddir/ignition-subsequent.target" \ "$systemdsystemunitdir/ignition-subsequent.target"