Fixed some race conditions

This commit is contained in:
2026-04-06 05:18:06 +08:00
parent 50d9440e0a
commit d662162921
4 changed files with 259 additions and 87 deletions

View File

@@ -108,7 +108,7 @@ wait_for_partnames() {
sleep 1
i=$((i + 1))
log "Still waiting for $@ to populate($i)"
log "Still waiting for $@ to populate($i)"
done
return 1
@@ -174,8 +174,6 @@ resolve_preferred_root() {
find_part_by_partuuid "$pref_root"
}
# Decide which root PARTNAME we want for the requested slot.
# Keep a compatibility fallback for legacy "rootfs" as slot A.
wanted_root_labels_for_slot() {
slot="$1"
@@ -184,8 +182,7 @@ wanted_root_labels_for_slot() {
echo "rootfsB"
;;
*)
# Try modern rootfsA first, then legacy rootfs
echo "rootfsA rootfs"
echo "rootfsA"
;;
esac
}
@@ -232,7 +229,7 @@ PREFERRED_PARTUUID="$(get_cmdline_arg pref_root || true)"
ROOT_DEV="$(resolve_preferred_root "$PREFERRED_PARTUUID" || true)"
if [ -n "$ROOT_DEV" ]; then
log "Using preferred root device: $ROOT_DEV"
log "Using preferred root device: $ROOT_DEV"
fi
if [ -z "$ROOT_DEV" ]; then
@@ -276,6 +273,16 @@ mount_or_panic -t overlay overlay \
-o "lowerdir=/newroot/etc,upperdir=/newroot/data/etc-overlay/upper,workdir=/newroot/data/etc-overlay/work" \
/newroot/etc
if [ "$BOOT_PART" = "A" ]; then
ALT_PART="$(find_sibling_part_on_same_disk "$ROOT_DEV" rootfsB || true)"
else
ALT_PART="$(find_sibling_part_on_same_disk "$ROOT_DEV" rootfsA || true)"
fi
if [ -n "$ALT_PART" ]; then
ln -sf "$ALT_PART" /dev/mksaltpart
fi
mount_or_panic --move /dev /newroot/dev
mount_or_panic --move /proc /newroot/proc
mount_or_panic --move /sys /newroot/sys