Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

setup-root: fix ordering with /sysroot/usr mount - #86

Merged
marineam merged 1 commit into
coreos:masterfrom
marineam:setup-root
Apr 7, 2016
Merged

marineam merged 1 commit into
coreos:masterfrom
marineam:setup-root

Conversation

@marineam

@marineam marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

First off, the script had a little bit of forgotten logic is left over
the read-only root and kexec days when things were much weirder and
allowing the setup to noop if /sysroot/usr wasn't mounted. This was
harmless until systemd 229 which includes the following change:

systemd/systemd@104bc12

So the fix is two fold: remove that bogus bit of logic so the setup
script explodes appropriately when /sysroot or /sysroot/usr isn't
mounted. Additionally fix the actual bug by ordering after
initrd-fs.target in addition to initrd-root-fs.target

@marineam

marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor Author

For reference, here is the diff sans-whitespace:

diff --git a/dracut/99setup-root/initrd-setup-root b/dracut/99setup-root/initrd-setup-root
index 9af496c..2499b46 100755
--- a/dracut/99setup-root/initrd-setup-root
+++ b/dracut/99setup-root/initrd-setup-root
@@ -6,7 +6,6 @@
 COREOS_BLANK_MACHINE_ID="42000000000000000000000000000042"
 MACHINE_ID_FILE="/sysroot/etc/machine-id"

-do_setup_root() {
 # Initialize base filesystem
 systemd-tmpfiles --root=/sysroot --create \
     baselayout.conf baselayout-etc.conf baselayout-usr.conf \
@@ -28,12 +27,6 @@ do_setup_root() {
 if grep -qs "${COREOS_BLANK_MACHINE_ID}" "${MACHINE_ID_FILE}"; then
     rm "${MACHINE_ID_FILE}"
 fi
-}
-
-# Skip if root and root/usr are not mount points
-if mountpoint --quiet /sysroot && mountpoint --quiet /sysroot/usr; then
-    do_setup_root
-fi

 # PXE initrds may provide OEM
 if [ -d /usr/share/oem ] && mountpoint --quiet /sysroot/usr/share/oem; then
diff --git a/dracut/99setup-root/initrd-setup-root.service b/dracut/99setup-root/initrd-setup-root.service
index f996716..d6fbf19 100644
--- a/dracut/99setup-root/initrd-setup-root.service
+++ b/dracut/99setup-root/initrd-setup-root.service
@@ -2,7 +2,7 @@
 Description=Root filesystem setup
 DefaultDependencies=no

-After=initrd-root-fs.target
+After=initrd-root-fs.target initrd-fs.target
 Before=initrd-parse-etc.service

 [Service]

First off, the script had a little bit of forgotten logic is left over
the read-only root and kexec days when things were much weirder and
allowing the setup to noop if /sysroot/usr wasn't mounted. This was
harmless until systemd 229 which includes the following change:

systemd/systemd@104bc12

So the fix is two fold: remove that bogus bit of logic so the setup
script explodes appropriately when /sysroot or /sysroot/usr isn't
mounted. Additionally fix the actual bug by ordering after all of the
possible paths under /sysroot that may be mounted.
@marineam

marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor Author

initrd-fs.target caused a dependency loop, using RequiresMountsFor=/sysroot/usr/share/oem instead to just depend on the mounts themselves, not other setup stuff like initd-parse-etc and ignition-files.

@marineam

marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor Author

New diff for reference:

diff --git a/dracut/99setup-root/initrd-setup-root b/dracut/99setup-root/initrd-setup-root
index 9af496c..2499b46 100755
--- a/dracut/99setup-root/initrd-setup-root
+++ b/dracut/99setup-root/initrd-setup-root
@@ -6,7 +6,6 @@
 COREOS_BLANK_MACHINE_ID="42000000000000000000000000000042"
 MACHINE_ID_FILE="/sysroot/etc/machine-id"

-do_setup_root() {
 # Initialize base filesystem
 systemd-tmpfiles --root=/sysroot --create \
     baselayout.conf baselayout-etc.conf baselayout-usr.conf \
@@ -28,12 +27,6 @@ do_setup_root() {
 if grep -qs "${COREOS_BLANK_MACHINE_ID}" "${MACHINE_ID_FILE}"; then
     rm "${MACHINE_ID_FILE}"
 fi
-}
-
-# Skip if root and root/usr are not mount points
-if mountpoint --quiet /sysroot && mountpoint --quiet /sysroot/usr; then
-    do_setup_root
-fi

 # PXE initrds may provide OEM
 if [ -d /usr/share/oem ] && mountpoint --quiet /sysroot/usr/share/oem; then
diff --git a/dracut/99setup-root/initrd-setup-root.service b/dracut/99setup-root/initrd-setup-root.service
index f996716..8e28b91 100644
--- a/dracut/99setup-root/initrd-setup-root.service
+++ b/dracut/99setup-root/initrd-setup-root.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Root filesystem setup
 DefaultDependencies=no
-
+RequiresMountsFor=/sysroot/usr/share/oem
 After=initrd-root-fs.target
 Before=initrd-parse-etc.service

@mischief

mischief commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

lgtm

@marineam
marineam merged commit b9e4988 into coreos:master Apr 7, 2016
@marineam
marineam deleted the setup-root branch April 7, 2016 19:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants