From: "T. Schaffner" <tobias.schaffner@siemens.com>
To: <isar-users@googlegroups.com>
Cc: <henning.schild@siemens.com>, <felix.moessbauer@siemens.com>,
<jan.kiszka@siemens.com>, <roberto.foglietta@gmail.com>,
Tobias Schaffner <tobias.schaffner@siemens.com>
Subject: [PATCH v2] expand-on-first-boot: wait for udev to create symlink
Date: Fri, 9 Dec 2022 11:35:40 +0100 [thread overview]
Message-ID: <20221209103540.13429-1-tobias.schaffner@siemens.com> (raw)
From: Tobias Schaffner <tobias.schaffner@siemens.com>
systemd-growfs depends on a symlink to the partition of the filesystem
that should be resized. This symlink is created by udev in /dev/block/.
If this symlink is not yet created for example because systemd-udev is
not up yet systemd-growfs will fail.
We could use Require and After to depend on the systemd-udev service
but this could again create a race condition if udev is up but not
fast enough after the partx -u.
Run systemd-growfs periodically until the symlink appears.
---
.../files/expand-last-partition.sh | 30 +++++++++++++++++--
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 57055cc..c5f96ec 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -79,7 +79,31 @@ if [ ! -d "${MOUNT_POINT}" ]; then
exit 1
fi
+# Send message to stdout, unmount mountpoint and exit.
+# $1 The message that should be send to stdout
+# $2 The mount point that should be unmounted
+# $3 The exit code that shout be used on exit
+growfs_cleanup_and_exit () {
+ echo $1
+ umount $2
+ rmdir $2
+ exit $3
+}
+
mount "${LAST_PART}" "${MOUNT_POINT}"
-/lib/systemd/systemd-growfs "${MOUNT_POINT}"
-umount "${MOUNT_POINT}"
-rmdir "${MOUNT_POINT}"
+
+# If systemd-udevd if not up yet or was not fast enough the symlinks in
+# /dev/block/ might be missing. Retry in that case.
+# This retry logic is only needed up to systemd-version 252
+for run in $(seq 0 50); do
+ if GROWFS_OUTPUT=$(/lib/systemd/systemd-growfs "${MOUNT_POINT}" 2>&1); then
+ growfs_cleanup_and_exit "${GROWFS_OUTPUT}" "${MOUNT_POINT}" 0
+ else:
+ if ! echo ${GROWFS_OUTPUT} | grep -q "^Failed to open \"/dev/block/.*\": No such file or directory$"; then
+ growfs_cleanup_and_exit "${GROWFS_OUTPUT}" "${MOUNT_POINT}" 1
+ fi
+ fi
+ sleep 0.1
+done
+growfs_cleanup_and_exit "${GROWFS_OUTPUT}" "${MOUNT_POINT}" 1
+
--
2.34.1
reply other threads:[~2022-12-09 10:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221209103540.13429-1-tobias.schaffner@siemens.com \
--to=tobias.schaffner@siemens.com \
--cc=felix.moessbauer@siemens.com \
--cc=henning.schild@siemens.com \
--cc=isar-users@googlegroups.com \
--cc=jan.kiszka@siemens.com \
--cc=roberto.foglietta@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox