Skip to content

Commit

Permalink
initrd-setup-root: Run always to ensure rootfs is populated
Browse files Browse the repository at this point in the history
In flatcar/Flatcar#944 we noticed that dbus
failed because of missing files in the rootfs when Ignition isn't
running in a PXE environment. This worked before by chance but the
underlying problem is that initrd-setup-root is required but wasn't
running because the "wants" symlinks in the module setup weren't
taking effect.

This is a backport of the relevant changes in
#50 to always run
initrd-setup-root instead of only when Ignition runs by pulling it in
from the two possible targets: either ignition-complete or
ignition-subsequent which runs in the other case.
The RequiresMountsFor=/sysroot/usr/share/oem directive didn't have any
effect because there was no mount unit defined. The directive
After=sysroot-usr.mount is already implied by
RequiresMountsFor=/sysroot/usr/.
  • Loading branch information
pothos committed Jan 9, 2023
1 parent 38b593a commit c8399e4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions dracut/30ignition/ignition-complete.target
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Documentation=https://github.com/coreos/ignition
ConditionPathExists=/etc/initrd-release
Before=initrd.target

# Run the generic rootfs setup helpers
Requires=initrd-setup-root.service
After=initrd-setup-root.service

# 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
4 changes: 4 additions & 0 deletions dracut/30ignition/ignition-subsequent.target
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Documentation=https://github.com/coreos/ignition
ConditionPathExists=/etc/initrd-release
Before=initrd.target

# Run the generic rootfs setup helpers
Requires=initrd-setup-root.service
After=initrd-setup-root.service

# 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
5 changes: 5 additions & 0 deletions dracut/99setup-root/initrd-setup-root
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

# Safe to run also after an official first boot and we do this now
# for consistency regardless if first_boot= is passed to create missing
# files if needed and make it easier to debug. In fact, it was required
# to use first_boot=1 with PXE to get a proper rootfs which is strange.

# /etc/machine-id after a new image is created:
COREOS_BLANK_MACHINE_ID="42000000000000000000000000000042"
MACHINE_ID_FILE="/sysroot/etc/machine-id"
Expand Down
6 changes: 4 additions & 2 deletions dracut/99setup-root/initrd-setup-root.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Description=Root filesystem setup
DefaultDependencies=no
RequiresMountsFor=/sysroot/usr/
RequiresMountsFor=/sysroot/usr/share/oem
After=sysroot-usr.mount
After=initrd-root-fs.target
Before=initrd-parse-etc.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/initrd-setup-root

[Install]
WantedBy=initrd.target
3 changes: 0 additions & 3 deletions dracut/99setup-root/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ install() {
inst_simple "${moddir}/initrd-setup-root.service" \
"${systemdsystemunitdir}/initrd-setup-root.service"

mkdir -p "${systemdsystemunitdir}/initrd.target.wants"
ln_r "${systemdsystemunitdir}/initrd-setup-root.service" \
"${systemdsystemunitdir}/initrd.target.wants/initrd-setup-root.service"
}

0 comments on commit c8399e4

Please sign in to comment.