From: Jan Kiszka <jan.kiszka@siemens.com>
To: cip-dev@lists.cip-project.org
Subject: [isar-cip-core][PATCH 1/2] initramfs-abrootfs-hook: Account for slower storage devices
Date: Thu, 2 Jun 2022 18:17:40 +0200 [thread overview]
Message-ID: <590cdfb4e4c4f66354e144875c28390122be66ea.1654186661.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1654186661.git.jan.kiszka@siemens.com>
From: Jan Kiszka <jan.kiszka@siemens.com>
Add a retry loop to account for storage devices that do not show up
immediately. Specifically USB can fall under this.
The logic is split along the classic PARTUUID/PARTLABEL case and the
more complex image UUID matching. To avoid continously mounting/
checking/unmounting the same partitions partitions, we keep track of the
already checked ones and only test those that are newly discovered.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
.../files/abrootfs.script | 86 +++++++++++++++----
1 file changed, 71 insertions(+), 15 deletions(-)
diff --git a/recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script b/recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script
index b61fe30..23bbfe7 100644
--- a/recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script
+++ b/recipes-initramfs/initramfs-abrootfs-hook/files/abrootfs.script
@@ -30,37 +30,93 @@ esac
. /scripts/functions
. /usr/share/abrootfs/image-uuid.env
+find_root_via_image_uuid()
+{
+ for part in $partitions; do
+ if [ "$(blkid -p "${part}" --match-types novfat -s USAGE -o value)" = "filesystem" ]; then
+ mount -o ro -t "$(get_fstype "${part}")" "${part}" "${rootmnt}"
+ . "${rootmnt}/etc/os-release"
+ umount "${rootmnt}"
+ if [ "${IMAGE_UUID}" = "${TARGET_IMAGE_UUID}" ]; then
+ found_root="${part}"
+ break
+ fi
+ fi
+ done
+}
+
# Even if this script fails horribly, make sure there won't be a chance the
# current $ROOT will be attempted. As this device most likely contains a
# perfectly valid filesystem, it would be mounted successfully, leading to a
# broken boot.
echo "ROOT=/dev/null" >/conf/param.conf
wait_for_udev 10
+
case "$ROOT" in
PART*)
- # root was given as PARTUUID= or PARTLABEL=. Use blkid to find the matching
- # partition
- ROOT=$(blkid --list-one --output device --match-token "$ROOT")
+ # Root was given as PARTUUID= or PARTLABEL=.
+ # Use blkid to find the matching partition
+ found_root=$(blkid --list-one --output device --match-token "$ROOT")
+ if [ -z "${found_root}" ]; then
+ log_begin_msg "Waiting for ${ROOT}"
+ while true; do
+ sleep 1
+ time_elapsed="$(time_elapsed)"
+
+ found_root=$(blkid --list-one --output device --match-token "$ROOT")
+ if [ -n "${found_root}" ]; then
+ log_end_msg 1
+ break
+ fi
+ if [ "${time_elapsed}" -ge 30 ]; then
+ log_end_msg 0
+ break
+ fi
+ done
+ fi
;;
"")
- # No Root device was given. Use find the matching IMAGE_UUID
- partitions=$(blkid -o device)
- for part in $partitions; do
- if [ "$(blkid -p ${part} --match-types novfat -s USAGE -o value)" = "filesystem" ]; then
- mount -o ro -t $(get_fstype $part) $part ${rootmnt}
- . ${rootmnt}/etc/os-release
- umount ${rootmnt}
- if [ "${IMAGE_UUID}" = "${TARGET_IMAGE_UUID}" ]; then
- ROOT="$part"
+ # No Root device was given. Search for the matching IMAGE_UUID
+ partitions="$(blkid -o device)"
+ find_root_via_image_uuid
+ if [ -z "${found_root}" ]; then
+ log_begin_msg "Waiting for IMAGE_UUID=${TARGET_IMAGE_UUID}"
+ scanned_partitions="${partitions}"
+ while true; do
+ sleep 1
+ time_elapsed="$(time_elapsed)"
+
+ unset partitions
+ for part in $(blkid -o device); do
+ unset found
+ for scanned_part in ${scanned_partitions}; do
+ if [ "${scanned_part}" = "${part}" ]; then
+ found=1
+ break
+ fi
+ done
+ if [ -z "${found}" ]; then
+ partitions="${partitions} ${part}"
+ fi
+ done
+ find_root_via_image_uuid
+ if [ -n "${found_root}" ]; then
+ log_end_msg 1
break
fi
- fi
- done
+ if [ "${time_elapsed}" -ge 30 ]; then
+ log_end_msg 0
+ break
+ fi
+ scanned_partitions="${scanned_partitions} ${partitions}"
+ done
+ fi
;;
esac
-if [ -z "${ROOT}" ]; then
+if [ -z "${found_root}" ]; then
panic "Can't find the root device with matching UUID!"
fi
+ROOT="${found_root}"
echo "ROOT=${ROOT}" >/conf/param.conf
--
2.35.3
next prev parent reply other threads:[~2022-06-02 16:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-02 16:17 [isar-cip-core][PATCH 0/2] swupodate: Account for slower storage in initramfs hooks Jan Kiszka
2022-06-02 16:17 ` Jan Kiszka [this message]
2022-06-02 16:17 ` [isar-cip-core][PATCH 2/2] initramfs-verity-hook: Account for slower storage devices Jan Kiszka
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=590cdfb4e4c4f66354e144875c28390122be66ea.1654186661.git.jan.kiszka@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=cip-dev@lists.cip-project.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.