From bccb55687afd52a72ccb52430b6b8a8516ee4f10 Mon Sep 17 00:00:00 2001
From: Caleb Connolly <caleb@postmarketos.org>
Date: Thu, 18 Apr 2024 21:51:58 +0100
Subject: [PATCH] postmarketos-initramfs: better wait_[br]oot_partition

Rework the messages and avoid re-spawning the splash on every check.
Additionally, add a call to check_keys, this lets users drop to a debug
shell or export logs to triage this failure (particularly useful for
hard-to-reproduce issues).

Finally, add a (liberal) 30 second timeout and dump logs at the end. If
we're just waiting for a device to show up and it doesn't after 30
seconds then it's probably never going to...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
---
 main/postmarketos-initramfs/APKBUILD          |  4 +-
 main/postmarketos-initramfs/init_functions.sh | 38 ++++++++++++++-----
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/main/postmarketos-initramfs/APKBUILD b/main/postmarketos-initramfs/APKBUILD
index dd7a5d8ca74..fcab8d20ffd 100644
--- a/main/postmarketos-initramfs/APKBUILD
+++ b/main/postmarketos-initramfs/APKBUILD
@@ -1,7 +1,7 @@
 # Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
 # Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
 pkgname=postmarketos-initramfs
-pkgver=2.6.0
+pkgver=2.6.1
 pkgrel=0
 pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
 url="https://postmarketos.org"
@@ -114,7 +114,7 @@ ab41b45b0613f25a61114ed8c8b92bc53c60838f6e2e0ba18c76e5369b2984e6023a066188769267
 ede9eb44fe180578ca97b7abfa2c4f1b4e277a49e4ca8b8911005acd844dbce38f200bc84280ded5a35fe5abd32bec391efc4af1929db12aa52da0c1036c6983  00-initramfs-fullsize.files
 8a4adad3785af474b36a09a05f6a3b2c4b4f43aac331a53b903abfa51ea12be1e3d1d807b7a6e66a1346815f3b0044daf8cd62e21e2dc75d2db13ee265a72985  00-initramfs-extra-base.files
 38acb5db6fc7e4f0b94a54f6293121dd5cb4321c446c50b855ac1d3ec782642ac3119933688ab041e69ef6ea8e53f60e040b970f7e032a8b6dc603cd29e88812  init.sh
-ea96fe57ac0c02b592fe7c8ea42561502bda286e1500e9f3f70810f4edecb333e3a207951bb4f25b3d2222e0d8cfe6876e0a94232254e9721661273bd21f3858  init_functions.sh
+855c756120e8b062c57efb1c9bfab9031554c60818e2ffd97d654cadc1fab39c78e2382d47fa42cc598b29dfb196e99736ec8af1df7d5074f3fadb124a6a10fa  init_functions.sh
 ba3275a9af788c7c782322a22a0f144d5e50e3498ea6886486a29331f23ae89cd32d500a3635cfa7cab369afba92edc18aeca64ccbf0cd589061cce23d15b46c  unudhcpd.conf
 675e7d5bee39b2df7d322117f8dcaccc274d61beaf4d50ead19bbf2109446d64b1c0aa0c5b4f9846eb6c1c403418f28f6364eff4537ba41120fbfcbc484b7da7  mdev.conf
 "
diff --git a/main/postmarketos-initramfs/init_functions.sh b/main/postmarketos-initramfs/init_functions.sh
index b1c8b59ed09..779e14e51c4 100644
--- a/main/postmarketos-initramfs/init_functions.sh
+++ b/main/postmarketos-initramfs/init_functions.sh
@@ -363,23 +363,41 @@ extract_initramfs_extra() {
 }
 
 wait_boot_partition() {
-	while [ -z "$(find_boot_partition)" ]; do
-		show_splash "ERROR: boot partition not found, retrying...\\nhttps://postmarketos.org/troubleshooting"
-		echo "Could not find the boot partition."
-		echo "If your install is on a removable disk, maybe you need to insert it?"
-		echo "Trying again..."
+	if [ -n "$PMOS_BOOT" ]; then
+		return
+	fi
+
+	show_splash "Waiting for boot partition...\\nhttps://postmarketos.org/troubleshooting"
+	for i in $(seq 1 30); do
+		if [ -n $(find_boot_partition) ]; then
+			return
+		fi
+		echo "Waiting for boot partition..."
 		sleep 1
+		check_keys
 	done
+
+	show_splash "ERROR: Boot partition not found!\\nhttps://postmarketos.org/troubleshooting"
+	fail_halt_boot
 }
 
 wait_root_partition() {
-	while [ -z "$(find_root_partition)" ]; do
-		show_splash "ERROR: root partition not found, retrying...\\nhttps://postmarketos.org/troubleshooting"
-		echo "Could not find the rootfs."
-		echo "If your install is on a removable disk, maybe you need to insert it?"
-		echo "Trying again..."
+	if [ -n "$PMOS_ROOT" ]; then
+		return
+	fi
+
+	show_splash "Waiting for root partition...\\nhttps://postmarketos.org/troubleshooting"
+	for i in $(seq 1 30); do
+		if [ -n $(find_root_partition) ]; then
+			return
+		fi
+		echo "Waiting for root partition..."
 		sleep 1
+		check_keys
 	done
+
+	show_splash "ERROR: Root partition not found!\\nhttps://postmarketos.org/troubleshooting"
+	fail_halt_boot
 }
 
 delete_old_install_partition() {
-- 
GitLab