public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] expand-on-first-boot: wait for udev to create symlink
@ 2022-12-08 16:55 T. Schaffner
  2022-12-08 17:39 ` Henning Schild
  0 siblings, 1 reply; 7+ messages in thread
From: T. Schaffner @ 2022-12-08 16:55 UTC (permalink / raw)
  To: isar-users; +Cc: henning.schild, felix.moessbauer, jan.kiszka, 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.

Resolve the symlinks in /dev/block/ periodically until the symlink
appears before running systemd-growfs.
---
 .../files/expand-last-partition.sh               | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

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..7ebb3e5 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
@@ -38,7 +38,8 @@ if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
 	exit 0
 fi
 
-LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
+LAST_PART_NAME="$(lsblk -l -o NAME "${BOOT_DEV}" | tail -1)"
+LAST_PART="/dev/${LAST_PART_NAME}"
 
 # Transform the partition table as follows:
 #
@@ -79,6 +80,19 @@ if [ ! -d "${MOUNT_POINT}" ]; then
 	exit 1
 fi
 
+START_TIME="$(date +%s)"
+
+# Wait for udev to create the symlink to the partition in /dev/block/ as
+# systemd-growfs depends on it
+while ! readlink /dev/block/* | grep -q "${LAST_PART_NAME}"; do
+    sleep 0.1
+    CURRENT_TIME="$(date +%s)"
+    if [ $(( CURRENT_TIME - START_TIME )) -gt "5" ]; then
+        echo "Could not find symlink to last part in /dev/block/."
+        exit 1
+    fi
+done
+
 mount "${LAST_PART}" "${MOUNT_POINT}"
 /lib/systemd/systemd-growfs "${MOUNT_POINT}"
 umount "${MOUNT_POINT}"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-09 17:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 16:55 [PATCH] expand-on-first-boot: wait for udev to create symlink T. Schaffner
2022-12-08 17:39 ` Henning Schild
2022-12-08 19:18   ` Schaffner, Tobias
2022-12-08 19:42     ` Henning Schild
2022-12-09  0:22   ` Roberto A. Foglietta
2022-12-09 10:51     ` Schaffner, Tobias
2022-12-09 17:17       ` Roberto A. Foglietta

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