public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2] expand-on-first-boot: wait for udev to create symlink
@ 2022-12-09 10:35 T. Schaffner
  0 siblings, 0 replies; only message in thread
From: T. Schaffner @ 2022-12-09 10:35 UTC (permalink / raw)
  To: isar-users
  Cc: henning.schild, felix.moessbauer, jan.kiszka, roberto.foglietta,
	Tobias Schaffner

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-09 10:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 10:35 [PATCH v2] expand-on-first-boot: wait for udev to create symlink T. Schaffner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox