public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2] If expand last partition fails, unsupervised systems reboot
@ 2022-12-14  7:52 Roberto A. Foglietta
  2022-12-14  8:47 ` Henning Schild
  2022-12-14  9:26 ` Roberto A. Foglietta
  0 siblings, 2 replies; 5+ messages in thread
From: Roberto A. Foglietta @ 2022-12-14  7:52 UTC (permalink / raw)
  To: isar-users

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

Hi all,

 in the expand last partition script I read this code

ROOT_DEV="$(findmnt / -o source -n)"
[...]
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

this means that there are no partitions because the boot partition
/dev/sda is equal to root partition /dev/sda, which happens only when
there is no partition table.

roberto$ echo /dev/sda2 | sed 's/p\?[0-9]*$//'
/dev/sda (which is different than /dev/sda2)
roberto$ echo /dev/sda | sed 's/p\?[0-9]*$//'
/dev/sda (there is no partition table)

That's ok but not exit 1 because IMHO, it will retry again the next
time but nothing will change the next time so it will continue to try
and fail at every boot. Because one-time-only in systemd means
one-successful-time-only and exit 1 prevents disabling the operation.

So, exit 0 would be the correct code to execute and this is the reason
because I removed the trap which would make an unsupervised system
reboot.

The patch v2 has been sent using the elastic mail SMTP and went in
moderation, here in attachment.

Best regards, R-

[-- Attachment #2: v2-0001-If-expand-last-partition-fails-unsupervised-syste.patch --]
[-- Type: text/x-patch, Size: 2110 bytes --]

From 14cff2bc150b1be77d5de4253ac3e92df2b4b0f9 Mon Sep 17 00:00:00 2001
From: "Roberto A. Foglietta" <roberto.foglietta@gmail.com>
Date: Tue, 13 Dec 2022 07:14:25 +0100
Subject: [PATCH v2] If expand last partition fails, unsupervised systems
 reboot

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

v2: if there is no partition table exit 0 instead of exit 1

Signed-off-by: Roberto A. Foglietta <roberto.foglietta@gmail.com>
---
 .../expand-on-first-boot/files/expand-last-partition.sh   | 8 +++++++-
 1 file changed, 7 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 f5bcad1..2c52b16 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,7 +23,8 @@ 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
-	exit 1
+	trap - EXIT
+	exit 0
 fi
 
 # this value is in blocks. Normally a block has 512 bytes.
@@ -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
 
@@ -72,3 +76,5 @@ case $(lsblk -fno FSTYPE "${LAST_PART}") in
 		umount $tmpdir && rmdir $tmpdir
 		;;
 esac
+
+trap - EXIT
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-14  9:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14  7:52 [PATCH v2] If expand last partition fails, unsupervised systems reboot Roberto A. Foglietta
2022-12-14  8:47 ` Henning Schild
2022-12-14  9:05   ` Henning Schild
2022-12-14  9:24     ` Roberto A. Foglietta
2022-12-14  9:26 ` Roberto A. Foglietta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox