From: Henning Schild <henning.schild@siemens.com>
To: "T. Schaffner" <tobias.schaffner@siemens.com>
Cc: <isar-users@googlegroups.com>, <felix.moessbauer@siemens.com>,
<jan.kiszka@siemens.com>
Subject: Re: [PATCH] expand-on-first-boot: wait for udev to create symlink
Date: Thu, 8 Dec 2022 18:39:19 +0100 [thread overview]
Message-ID: <20221208183919.1703fb25@md1za8fc.ad001.siemens.net> (raw)
In-Reply-To: <20221208165542.2451856-1-tobias.schaffner@siemens.com>
Am Thu, 8 Dec 2022 17:55:42 +0100
schrieb "T. Schaffner" <tobias.schaffner@siemens.com>:
> 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
Newer systemd versions will not need that anymore. Maybe write down
which version that would be and starting from which debian distro we
can drop that. Who knows when that udev stuff changes and the symlinks
will never appear ... We should only wait for them in systemd versions
that use them.
If we already have a version out there ... like bookworm? We can
already implement it without the wait.
> /dev/block/ as +# systemd-growfs depends on it
> +while ! readlink /dev/block/* | grep -q "${LAST_PART_NAME}"; do
I would make that much stricter to not be tricked by partial matches
sda4 vs sda42
readlink -f /dev/block/* | grep -e -q "^${LAST_PART}$"
> + sleep 0.1
I wonder if there is anything we could do here. Maybe "udevadm trigger"
and depend on udev after all. Because the 5 is a nasty guess ...
> + CURRENT_TIME="$(date +%s)"
> + if [ $(( CURRENT_TIME - START_TIME )) -gt "5" ]; then
we can simply i++ > 50, no need to call date
so maybe
err=1
for i in $(seq 0 50); do
if readlink -f /dev/block/* | grep -e -q "^${LAST_PART}$"; then
err=0
break
fi
sleep 0.1
done
if $err ...
> + 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}"
we could also loop over calling this until it goes "0" or we reach a
retry counter, that way we magically handle new systemd versions that
do not need symlinks and do not implement anything with symlinks.
Henning
> umount "${MOUNT_POINT}"
next prev parent reply other threads:[~2022-12-08 17:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 16:55 T. Schaffner
2022-12-08 17:39 ` Henning Schild [this message]
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
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=20221208183919.1703fb25@md1za8fc.ad001.siemens.net \
--to=henning.schild@siemens.com \
--cc=felix.moessbauer@siemens.com \
--cc=isar-users@googlegroups.com \
--cc=jan.kiszka@siemens.com \
--cc=tobias.schaffner@siemens.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