If expand last partition fails, unsupervised systems reboot

Message ID 4uin751ogvjz.BGcJ14VHPisZGHKiFLvkmQ2@16F0H.trk.elasticemail.com
State Superseded, archived
Headers show
Series If expand last partition fails, unsupervised systems reboot | expand

Commit Message

Roberto A. Foglietta Dec. 13, 2022, 6:21 a.m. UTC
From: "Roberto A. Foglietta" <roberto.foglietta@gmail.com>

Improvement for unsupervised embedded devices which need to reboot if expand last
partition fails because a under-provided system should not even complete the boot
in the field in order to avoid functioning failures at unexpected future time.
This patch do not affect the previous behaviour because requirs /etc/unsupervised

This patch applies after the following other patches:

 - In expand last partition script btrfs support added
 - In expand last partition wait for udev have finished

Signed-off-by: Roberto A. Foglietta <roberto.foglietta@gmail.com>
---
 .../expand-on-first-boot/files/expand-last-partition.sh     | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

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 e314f70..46f3019 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
@@ -9,6 +9,8 @@ 
 
 set -e
 
+test -e /etc/unsupervised && trap reboot EXIT
+
 udevadm settle
 
 ROOT_DEV="$(findmnt / -o source -n)"
@@ -21,6 +23,7 @@  fi
 BOOT_DEV="$(echo "${ROOT_DEV}" | sed 's/p\?[0-9]*$//')"
 if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
 	echo "Boot device equals root device - no partitioning found" >&2
+	trap - EXIT
 	exit 1
 fi
 
@@ -37,6 +40,7 @@  done
 MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
 if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
 	echo "Disk is practically already full, doing nothing." >&2
+	trap - EXIT
 	exit 0
 fi
 
@@ -73,3 +77,5 @@  case $(lsblk -fno FSTYPE "${LAST_PART}") in
 		umount $tmp/btrfs && rmdir $tmp/btrfs
 		;;
 esac
+
+trap - EXIT