[PATCH 04/17] meta-isar: deploy-image: Drop umount attempt after installation

4 views
Skip to first unread message

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Under systemd, this fails because /install is still busy. In that setup,
systemd will take care of properly unmounting this partition anyway on
reboot. In other setups, the caller should take care.

This also obsoletes the "set -e" because no commands are left that can
produce errors and are not checked explicitly.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../recipes-installer/deploy-image/files/deploy-image-wic.sh | 5 -----
1 file changed, 5 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 12c1eea2..9a1fa651 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -90,7 +90,6 @@ fi
TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE /dev/"$TARGET_DEVICE")
dialog --msgbox "Start installing '$DISK_IMAGE' to '$TARGET_DEVICE'(Size: '$TARGET_DEVICE_SIZE' )." 7 60

-set -e
bmap_options=""
if [ -z "$DISK_BMAP" ]; then
bmap_options="--nobmap"
@@ -100,9 +99,5 @@ if ! bmaptool copy "${bmap_options}" "$DISK_IMAGE" "/dev/${TARGET_DEVICE}"; then
exit 1
fi

-# we need to umount before reboot to avoid
-# data corruption due to the use of vfat.
-umount "$installdata"
-sync
dialog --title "Reboot" --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 7 60
exit 0
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Terminate if the users chooses to cancel. Offer this option also on the
final message box before the start.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 284252fb..09d6cc11 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -12,10 +12,12 @@ if [ -z "$DISK_IMAGE" ]; then
shopt -s nullglob
array=(*)
shopt -u nullglob
- DISK_IMAGE=$(dialog --no-tags \
- --menu "Select image to be installed" 10 60 3 \
- "${array[@]}" --output-fd 1)
popd
+ if ! DISK_IMAGE=$(dialog --no-tags \
+ --menu "Select image to be installed" 10 60 3 \
+ "${array[@]}" --output-fd 1)
+ exit 0
+ fi
fi
if [ ! -f "$installdata/$DISK_IMAGE" ]; then
dialog --msgbox "Could not find an image to install. Installation aborted." 7 60
@@ -80,15 +82,19 @@ if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target")
array+=("/dev/$target" "/dev/$target $target_size")
done
- TARGET_DEVICE=$(dialog --no-tags \
- --menu "Select device to install $DISK_IMAGE" 10 60 3 \
- "${array[@]}" --output-fd 1)
-
+ if ! TARGET_DEVICE=$(dialog --no-tags \
+ --menu "Select device to install image to" 10 60 3 \
+ "${array[@]}" --output-fd 1); then
+ exit 0
+ fi
else
TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
fi
TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE")
-dialog --msgbox "Start installing '$DISK_IMAGE' to '$TARGET_DEVICE'(Size: '$TARGET_DEVICE_SIZE' )." 7 60
+if ! dialog --yes-label Ok --no-label Cancel \
+ --yesno "Start installing '$DISK_IMAGE' to '$TARGET_DEVICE'(Size: '$TARGET_DEVICE_SIZE' )." 7 60; then
+ exit 0
+fi

bmap_options=""
if [ -z "$DISK_BMAP" ]; then
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Even though kas processes it, "menuconfig" is not a valid entry for a
choice. While fixing this, also make the installer payload a choice,
rather than a string input, to make it easier for users.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas/image/Kconfig | 43 ++++++++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/kas/image/Kconfig b/kas/image/Kconfig
index 45611c4e..e4f64dcc 100644
--- a/kas/image/Kconfig
+++ b/kas/image/Kconfig
@@ -30,24 +30,45 @@ config IMAGE_CI
This image includes is for running CI. Via isar-ci-ssh-setup recipe.
It creates ci user with non-interactive ssh access to the board.

-menuconfig IMAGE_INSTALLER
+config IMAGE_INSTALLER
bool "Installer image"
help
This image contains a target image and scripts to install the target image on a device.

-config INSTALLER_TARGET_IMAGE
- string "Install Base or Debug image"
- default "isar-image-base"
+endchoice
+
+if IMAGE_INSTALLER
+
+choice
+ prompt "Image to install"
+ default INSTALL_IMAGE_BASE
+
+config INSTALL_IMAGE_BASE
+ bool "Base image"
help
- This selects the target image of the installer:
- - isar-image-base
- - isar-image-debug
- If left empty it will generate a installer image without payload.
- The user of that image needs then to copy a image to the partition
- labeled INSTALLDATA.
- depends on IMAGE_INSTALLER
+ Embed the basic Isar image into the installer image.
+
+config INSTALL_IMAGE_DEBUG
+ bool "Debug image"
+ help
+ Embed the Isar debug image into the installer image.
+
+config INSTALL_EMPTY
+ bool "No installer payload"
+ help
+ This will generate a installer image without payload. The user of
+ that image needs then to copy a image to the partition labeled
+ INSTALLDATA.
+
endchoice

+config INSTALLER_TARGET_IMAGE
+ string
+ default "isar-image-base" if INSTALL_IMAGE_BASE
+ default "isar-image-base" if INSTALL_IMAGE_DEBUG
+
+endif
+
config KAS_INCLUDE_IMAGE
string
default "kas/image/isar-image-base.yaml" if IMAGE_BASE
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

We are not using --and-widget.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 5c362bcf..284252fb 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -12,9 +12,9 @@ if [ -z "$DISK_IMAGE" ]; then
shopt -s nullglob
array=(*)
shopt -u nullglob
- DISK_IMAGE=$(dialog --clear \
- --no-tags --menu "Select image to be installed" 10 60 3 \
- "${array[@]}" --output-fd 1)
+ DISK_IMAGE=$(dialog --no-tags \
+ --menu "Select image to be installed" 10 60 3 \
+ "${array[@]}" --output-fd 1)
popd
fi
if [ ! -f "$installdata/$DISK_IMAGE" ]; then
@@ -80,9 +80,9 @@ if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target")
array+=("/dev/$target" "/dev/$target $target_size")
done
- TARGET_DEVICE=$(dialog --clear \
- --no-tags --menu "Select device to install $DISK_IMAGE" 10 60 3 \
- "${array[@]}" --output-fd 1)
+ TARGET_DEVICE=$(dialog --no-tags \
+ --menu "Select device to install $DISK_IMAGE" 10 60 3 \
+ "${array[@]}" --output-fd 1)

else
TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Pull the reboot out of the script. This allows for cleaner integration
with different calling environment, may they be a systemd unit, an
initramfs script or simply a shell for testing purposes.

And if the script exits with an error, wait a minute before rebooting
the system, rather than just trying to re-execute it. This permits to
inspect potential error as well.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../recipes-installer/deploy-image/files/deploy-image-wic.sh | 2 +-
.../recipes-installer/deploy-image/files/install.override.conf | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 8043aff1..12c1eea2 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -105,4 +105,4 @@ fi
umount "$installdata"
sync
dialog --title "Reboot" --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 7 60
-reboot
+exit 0
diff --git a/meta-isar/recipes-installer/deploy-image/files/install.override.conf b/meta-isar/recipes-installer/deploy-image/files/install.override.conf
index 73874caa..357d8662 100644
--- a/meta-isar/recipes-installer/deploy-image/files/install.override.conf
+++ b/meta-isar/recipes-installer/deploy-image/files/install.override.conf
@@ -1,5 +1,5 @@
[Service]
ExecStart=
-ExecStart=/usr/bin/deploy-image-wic.sh
+ExecStart=/bin/sh -c "deploy-image-wic.sh || (echo 'Rebooting in 60 s'; sleep 60); reboot"
StandardInput=tty
StandardOutput=tty
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
Address several issues of the image installer, specifically the script.
It also brings some simplistic way to make the installer operate without
user interaction.

What is still missing, though, is documentation of how to integrate all
that in own projects. Also, I would like to make hooking into the script
possible so that certain interactions with the user can be customized
without having to fork the recipe. Still needs to be designed, and would
have only made this queue even longer.

Jan

Jan Kiszka (17):
Kconfig: Rework installer image submenu
installer: Do not show systemd boot menu
meta-isar: deploy-image: Change reboot logic
meta-isar: deploy-image: Drop umount attempt after installation
meta-isar: deploy-image: Fix bmap support
meta-isar: deploy-image: Improve root mountpoint discovery
meta-isar: deploy-image: Make TARGET_DEVICE a complete path
meta-isar: deploy-image: Drop pointless --clear options from dialog
meta-isar: deploy-image: Allow to cancel installation
meta-isar: deploy-image: Warn if overwriting a non-empty disk
meta-isar: deploy-image: Fix and enhance image selection dialog
meta-isar: deploy-image: Improve target device list dialog
meta-isar: deploy-image: Polish some dialogs
meta-isar: deploy-image: Re-indent
meta-isar: deploy-image: Prepare for auto-installation mode
meta-isar: deploy-image: Introduce auto-installation mode
meta-isar: deploy-image: Polish recipe

kas/image/Kconfig | 43 +++-
.../deploy-image/deploy-image_0.1.bb | 9 +-
.../deploy-image/files/deploy-image-wic.sh | 188 +++++++++++-------
.../deploy-image/files/install.override.conf | 2 +-
.../lib/wic/canned-wks/installer-efi.wks.in | 2 +-
5 files changed, 150 insertions(+), 94 deletions(-)

--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

We only have a single target to boot.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
meta-isar/scripts/lib/wic/canned-wks/installer-efi.wks.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta-isar/scripts/lib/wic/canned-wks/installer-efi.wks.in b/meta-isar/scripts/lib/wic/canned-wks/installer-efi.wks.in
index 62c045b6..be8127cb 100644
--- a/meta-isar/scripts/lib/wic/canned-wks/installer-efi.wks.in
+++ b/meta-isar/scripts/lib/wic/canned-wks/installer-efi.wks.in
@@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: MIT

-bootloader --ptable gpt --timeout 3 --append "rootwait console=ttyS0,115200 console=tty0 earlyprintk"
+bootloader --ptable gpt --timeout 0 --append "rootwait console=ttyS0,115200 console=tty0 earlyprintk"
part /boot --source bootimg-efi-isar --sourceparams "loader=systemd-boot" --label efi --part-type EF00 --align 1024 --use-uuid
part / --source rootfs --fstype ext4 --exclude-path=install --label installroot --align 1024 --use-uuid
part /install --source rootfs --change-directory=install --label INSTALLDATA --size 4G --fstype=vfat --use-uuid --align 1024
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

The rootfs mountpoint may only appear as /dev/root in /proc/mounts.
Therefore, reuse the pattern we have in expand-on-first-boot already and
switch to findmnt.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../recipes-installer/deploy-image/files/deploy-image-wic.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index d27a0189..f73a48a9 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -25,7 +25,7 @@ DISK_BMAP=$(find "$installdata" -type f -iname "${DISK_IMAGE%.wic*}.wic.bmap")
# inspired by poky/meta/recipes-core/initrdscripts/files/install-efi.sh

target_device_list=""
-current_root_dev=$(grep "[[:blank:]]/[[:blank:]]" /proc/mounts | awk '{print $1}')
+current_root_dev=$(readlink -f "$(findmnt / -o source -n)")
current_root_dev=${current_root_dev#\/dev/}
case $current_root_dev in
mmcblk*)
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

If the to-be-installed image was compressed, its corresponding .bmap
file was not found. Fix that and also ensure that bmaptool is correctly
invoked if --nobmap does not have to be inserted.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 9a1fa651..d27a0189 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -6,7 +6,7 @@

installdata=${INSTALL_DATA:-/install}

-DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap")
+DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap" -exec basename {} \;)
if [ -z "$DISK_IMAGE" ]; then
pushd "$installdata"
shopt -s nullglob
@@ -17,11 +17,11 @@ if [ -z "$DISK_IMAGE" ]; then
"${array[@]}" --output-fd 1)
popd
fi
-if [ ! -f "$DISK_IMAGE" ]; then
+if [ ! -f "$installdata/$DISK_IMAGE" ]; then
dialog --msgbox "Could not find an image to install. Installation aborted." 7 60
exit 1
fi
-DISK_BMAP=$(find "$installdata" -type f -iname "$DISK_IMAGE.bmap")
+DISK_BMAP=$(find "$installdata" -type f -iname "${DISK_IMAGE%.wic*}.wic.bmap")
# inspired by poky/meta/recipes-core/initrdscripts/files/install-efi.sh

target_device_list=""
@@ -95,7 +95,7 @@ if [ -z "$DISK_BMAP" ]; then
bmap_options="--nobmap"
fi
clear
-if ! bmaptool copy "${bmap_options}" "$DISK_IMAGE" "/dev/${TARGET_DEVICE}"; then
+if ! bmaptool copy ${bmap_options} "$installdata/$DISK_IMAGE" "/dev/${TARGET_DEVICE}"; then
exit 1
fi

--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:35 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Avoids having to prepend /dev/ at every user.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index f73a48a9..5c362bcf 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -78,16 +78,16 @@ if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
array=()
for target in $target_device_list; do
target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target")
- array+=("$target" "/dev/$target $target_size")
+ array+=("/dev/$target" "/dev/$target $target_size")
done
TARGET_DEVICE=$(dialog --clear \
--no-tags --menu "Select device to install $DISK_IMAGE" 10 60 3 \
"${array[@]}" --output-fd 1)

else
- TARGET_DEVICE=$(echo "$target_device_list" | tr -d " ")
+ TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
fi
-TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE /dev/"$TARGET_DEVICE")
+TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE")
dialog --msgbox "Start installing '$DISK_IMAGE' to '$TARGET_DEVICE'(Size: '$TARGET_DEVICE_SIZE' )." 7 60

bmap_options=""
@@ -95,7 +95,7 @@ if [ -z "$DISK_BMAP" ]; then
bmap_options="--nobmap"
fi
clear
-if ! bmaptool copy ${bmap_options} "$installdata/$DISK_IMAGE" "/dev/${TARGET_DEVICE}"; then
+if ! bmaptool copy ${bmap_options} "$installdata/$DISK_IMAGE" "${TARGET_DEVICE}"; then

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

If a special file called auto.install is found in the installation data
directory, parse this and attempt an unattended installation. The file
consists of 2 to 3 lines:

- source file name
- target device path
- optionally, "OVERWRITE" to ignore if the target device is non-empty

e.g.:
$ cat /install/auto.install
isar-image-base-debian-bookworm-qemuamd64.wic.zst
/dev/vda
OVERWRITE

Errors are still stopping the process, switching it back to interactive
mode.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 9df93fe7..8b25b1d2 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -7,8 +7,20 @@
installdata=${INSTALL_DATA:-/install}

AUTO_INSTALL=false
+OVERWRITE=

-if ! $AUTO_INSTALL; then
+if [ -f "$installdata/auto.install" ]; then
+ exec 3<"$installdata/auto.install"
+ read -r DISK_IMAGE <&3
+ read -r TARGET_DEVICE <&3
+ read -r OVERWRITE <&3
+ exec 3>&-
+ if [ ! -b ${TARGET_DEVICE} ]; then
+ dialog --msgbox "Target device is not a valid block device. Installation aborted." 6 60
+ exit 1
+ fi
+ AUTO_INSTALL=true
+else
DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap" -exec basename {} \;)
if [ -z "$DISK_IMAGE" ] || [ ! -f "$installdata/$DISK_IMAGE" ]; then
pushd "$installdata"
@@ -110,7 +122,7 @@ if ! $AUTO_INSTALL; then
fi
fi

-if ! cmp /dev/zero "$TARGET_DEVICE" -n 1M && \
+if [ "$OVERWRITE" != "OVERWRITE" ] && ! cmp /dev/zero "$TARGET_DEVICE" -n 1M && \
! dialog --defaultno \
--yesno "WARNING: Target device is not empty! Continue anyway?" 5 60; then
exit 0
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Sort the list by device name to make navigation easier. Show also if a
device probably still contains data.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 35029728..673b2eb3 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -80,9 +80,14 @@ fi

if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
array=()
- for target in $target_device_list; do
- target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target")
- array+=("/dev/$target" "/dev/$target $target_size")
+ for target in $(echo "$target_device_list" | xargs -n1 | sort); do
+ target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target" | tr -d " ")
+ if cmp /dev/zero /dev/"$target" -n 1M; then
+ state="empty"
+ else
+ state="contains data"
+ fi
+ array+=("/dev/$target" "/dev/$target ($target_size, $state)")
done
if ! TARGET_DEVICE=$(dialog --no-tags \
--menu "Select device to install image to" 10 60 3 \
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

No functional changes, just style improvements.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 5ae62a55..77eebe18 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -33,12 +33,12 @@ current_root_dev=$(readlink -f "$(findmnt / -o source -n)")
current_root_dev=${current_root_dev#\/dev/}
case $current_root_dev in
mmcblk*)
- ;;
+ ;;
nvme*)
- ;;
+ ;;
*)
current_root_dev=${current_root_dev%%[0-9]*}
- ;;
+ ;;
esac

echo "Searching for target device..."
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Wrap the code blocks that will be skipped in auto-installation mode
separately to ease review. As the controlling variable remains false for
now, there are effectively no functional changes.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 163 +++++++++---------
1 file changed, 86 insertions(+), 77 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 77eebe18..9df93fe7 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -6,21 +6,26 @@

installdata=${INSTALL_DATA:-/install}

-DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap" -exec basename {} \;)
-if [ -z "$DISK_IMAGE" ] || [ ! -f "$installdata/$DISK_IMAGE" ]; then
- pushd "$installdata"
- for f in $(find . -type f); do
- array+=("$f" "$f")
- done
- popd
- if [ ${#array[@]} -gt 0 ]; then
- if ! DISK_IMAGE=$(dialog --no-tags \
- --menu "Select image to be installed" 10 60 3 \
- "${array[@]}" --output-fd 1); then
- exit 0
+AUTO_INSTALL=false
+
+if ! $AUTO_INSTALL; then
+ DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap" -exec basename {} \;)
+ if [ -z "$DISK_IMAGE" ] || [ ! -f "$installdata/$DISK_IMAGE" ]; then
+ pushd "$installdata"
+ for f in $(find . -type f); do
+ array+=("$f" "$f")
+ done
+ popd
+ if [ ${#array[@]} -gt 0 ]; then
+ if ! DISK_IMAGE=$(dialog --no-tags \
+ --menu "Select image to be installed" 10 60 3 \
+ "${array[@]}" --output-fd 1); then
+ exit 0
+ fi
fi
fi
fi
+
if [ ! -f "$installdata/$DISK_IMAGE" ]; then
dialog --msgbox "Could not find an image to install. Installation aborted." 6 60
exit 1
@@ -28,79 +33,81 @@ fi
DISK_BMAP=$(find "$installdata" -type f -iname "${DISK_IMAGE%.wic*}.wic.bmap")
# inspired by poky/meta/recipes-core/initrdscripts/files/install-efi.sh

-target_device_list=""
-current_root_dev=$(readlink -f "$(findmnt / -o source -n)")
-current_root_dev=${current_root_dev#\/dev/}
-case $current_root_dev in
- mmcblk*)
- ;;
- nvme*)
- ;;
- *)
- current_root_dev=${current_root_dev%%[0-9]*}
- ;;
-esac
-
-echo "Searching for target device..."
-
-devices=$(find /sys/block/ -type b,c,f,l -not -iname "mmcblk*" -printf "%f\n") || true
-mmc_devices=$(find /sys/block/ -type b,c,f,l -iname "mmcblk[0-9]" -printf "%f\n") || true
-devices="$devices $mmc_devices"
-
-for device in $devices; do
- case $device in
- loop*)
- # skip loop device
- ;;
- mtd*)
+if ! $AUTO_INSTALL; then
+ target_device_list=""
+ current_root_dev=$(readlink -f "$(findmnt / -o source -n)")
+ current_root_dev=${current_root_dev#\/dev/}
+ case $current_root_dev in
+ mmcblk*)
;;
- sr*)
- # skip CDROM device
- ;;
- ram*)
- # skip ram device
+ nvme*)
;;
*)
- case $device in
- $current_root_dev*)
- # skip the device we are running from
- ;;
- *)
- target_device_list="$target_device_list $device"
- ;;
- esac
+ current_root_dev=${current_root_dev%%[0-9]*}
;;
esac
-done

-if [ -z "${target_device_list}" ]; then
- dialog --msgbox "You need another device (besides the live device /dev/${current_root_dev}) to install the image. Installation aborted." 7 60
- exit 1
-fi
+ echo "Searching for target device..."

-if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
- array=()
- for target in $(echo "$target_device_list" | xargs -n1 | sort); do
- target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target" | tr -d " ")
- if cmp /dev/zero /dev/"$target" -n 1M; then
- state="empty"
- else
- state="contains data"
- fi
- array+=("/dev/$target" "/dev/$target ($target_size, $state)")
+ devices=$(find /sys/block/ -type b,c,f,l -not -iname "mmcblk*" -printf "%f\n") || true
+ mmc_devices=$(find /sys/block/ -type b,c,f,l -iname "mmcblk[0-9]" -printf "%f\n") || true
+ devices="$devices $mmc_devices"
+
+ for device in $devices; do
+ case $device in
+ loop*)
+ # skip loop device
+ ;;
+ mtd*)
+ ;;
+ sr*)
+ # skip CDROM device
+ ;;
+ ram*)
+ # skip ram device
+ ;;
+ *)
+ case $device in
+ $current_root_dev*)
+ # skip the device we are running from
+ ;;
+ *)
+ target_device_list="$target_device_list $device"
+ ;;
+ esac
+ ;;
+ esac
done
- if ! TARGET_DEVICE=$(dialog --no-tags \
- --menu "Select device to install image to" 10 60 3 \
- "${array[@]}" --output-fd 1); then
+
+ if [ -z "${target_device_list}" ]; then
+ dialog --msgbox "You need another device (besides the live device /dev/${current_root_dev}) to install the image. Installation aborted." 7 60
+ exit 1
+ fi
+
+ if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
+ array=()
+ for target in $(echo "$target_device_list" | xargs -n1 | sort); do
+ target_size=$(lsblk --nodeps --noheadings -o SIZE /dev/"$target" | tr -d " ")
+ if cmp /dev/zero /dev/"$target" -n 1M; then
+ state="empty"
+ else
+ state="contains data"
+ fi
+ array+=("/dev/$target" "/dev/$target ($target_size, $state)")
+ done
+ if ! TARGET_DEVICE=$(dialog --no-tags \
+ --menu "Select device to install image to" 10 60 3 \
+ "${array[@]}" --output-fd 1); then
+ exit 0
+ fi
+ else
+ TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
+ fi
+ TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE" | tr -d " ")
+ if ! dialog --yes-label Ok --no-label Cancel \
+ --yesno "Start installing\n'$DISK_IMAGE'\nto $TARGET_DEVICE (capacity: $TARGET_DEVICE_SIZE)" 7 60; then
exit 0
fi
-else
- TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
-fi
-TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE" | tr -d " ")
-if ! dialog --yes-label Ok --no-label Cancel \
- --yesno "Start installing\n'$DISK_IMAGE'\nto $TARGET_DEVICE (capacity: $TARGET_DEVICE_SIZE)" 7 60; then
- exit 0
fi

if ! cmp /dev/zero "$TARGET_DEVICE" -n 1M && \
@@ -118,6 +125,8 @@ if ! bmaptool copy ${bmap_options} "$installdata/$DISK_IMAGE" "${TARGET_DEVICE}"
exit 1
fi

-dialog --title "Reboot" \
- --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 6 60
+if ! $AUTO_INSTALL; then
+ dialog --title "Reboot" \
+ --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 6 60
+fi
exit 0
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Add linewraps at defined points to the start dialog, strip spaces from
device size output, adjust formattings. Some other message boxes can be
shrunk in height.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 673b2eb3..5ae62a55 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -22,7 +22,7 @@ if [ -z "$DISK_IMAGE" ] || [ ! -f "$installdata/$DISK_IMAGE" ]; then
fi
fi
if [ ! -f "$installdata/$DISK_IMAGE" ]; then
- dialog --msgbox "Could not find an image to install. Installation aborted." 7 60
+ dialog --msgbox "Could not find an image to install. Installation aborted." 6 60
exit 1
fi
DISK_BMAP=$(find "$installdata" -type f -iname "${DISK_IMAGE%.wic*}.wic.bmap")
@@ -97,9 +97,9 @@ if [ "$(echo "$target_device_list" | wc -w)" -gt 1 ]; then
else
TARGET_DEVICE=/dev/$(echo "$target_device_list" | tr -d " ")
fi
-TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE")
+TARGET_DEVICE_SIZE=$(lsblk --nodeps --noheadings -o SIZE "$TARGET_DEVICE" | tr -d " ")
if ! dialog --yes-label Ok --no-label Cancel \
- --yesno "Start installing '$DISK_IMAGE' to '$TARGET_DEVICE'(Size: '$TARGET_DEVICE_SIZE' )." 7 60; then
+ --yesno "Start installing\n'$DISK_IMAGE'\nto $TARGET_DEVICE (capacity: $TARGET_DEVICE_SIZE)" 7 60; then
exit 0
fi

@@ -118,5 +118,6 @@ if ! bmaptool copy ${bmap_options} "$installdata/$DISK_IMAGE" "${TARGET_DEVICE}"
exit 1
fi

-dialog --title "Reboot" --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 7 60
+dialog --title "Reboot" \
+ --msgbox "Installation is successful. System will be rebooted. Please remove the USB stick." 6 60
exit 0
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:36 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Check of the first MB of the target device is only containing zero and
warn otherwise before overwriting potentially valuable data. Looking
at the first MB should cover enough partition table and file system
structures to detect a valid disk.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 09d6cc11..81a006ce 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -96,6 +96,12 @@ if ! dialog --yes-label Ok --no-label Cancel \
exit 0
fi

+if ! cmp /dev/zero "$TARGET_DEVICE" -n 1M && \
+ ! dialog --defaultno \
+ --yesno "WARNING: Target device is not empty! Continue anyway?" 5 60; then
+ exit 0
+fi
+
bmap_options=""
if [ -z "$DISK_BMAP" ]; then
bmap_options="--nobmap"
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:37 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

The dialog was broken because an array of tag/value tuples had to be
provided, not just a list of files.

Use the chance an also fall back to the dialog if the search for
DISK_IMAGE does deliver a result but not a clear one. But only open the
dialog if there are entries.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../deploy-image/files/deploy-image-wic.sh | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
index 81a006ce..35029728 100644
--- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-wic.sh
@@ -7,16 +7,18 @@
installdata=${INSTALL_DATA:-/install}

DISK_IMAGE=$(find "$installdata" -type f -iname "*.wic*" -a -not -iname "*.wic.bmap" -exec basename {} \;)
-if [ -z "$DISK_IMAGE" ]; then
+if [ -z "$DISK_IMAGE" ] || [ ! -f "$installdata/$DISK_IMAGE" ]; then
pushd "$installdata"
- shopt -s nullglob
- array=(*)
- shopt -u nullglob
+ for f in $(find . -type f); do
+ array+=("$f" "$f")
+ done
popd
- if ! DISK_IMAGE=$(dialog --no-tags \
- --menu "Select image to be installed" 10 60 3 \
- "${array[@]}" --output-fd 1)
- exit 0
+ if [ ${#array[@]} -gt 0 ]; then
+ if ! DISK_IMAGE=$(dialog --no-tags \
+ --menu "Select image to be installed" 10 60 3 \
+ "${array[@]}" --output-fd 1); then
+ exit 0
+ fi
fi
fi
if [ ! -f "$installdata/$DISK_IMAGE" ]; then
--
2.43.0

Jan Kiszka

unread,
Jul 2, 2024, 9:38:37 AM (4 days ago) Jul 2
to isar-users, Quirin Gylstorff
From: Jan Kiszka <jan.k...@siemens.com>

Adjust description to what the tool actually does. Reindent.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
.../recipes-installer/deploy-image/deploy-image_0.1.bb | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/meta-isar/recipes-installer/deploy-image/deploy-image_0.1.bb b/meta-isar/recipes-installer/deploy-image/deploy-image_0.1.bb
index 0e61de03..3f34424f 100644
--- a/meta-isar/recipes-installer/deploy-image/deploy-image_0.1.bb
+++ b/meta-isar/recipes-installer/deploy-image/deploy-image_0.1.bb
@@ -3,8 +3,7 @@
#
# SPDX-License-Identifier: MIT

-DESCRIPTION = "add target image to rootfs"
-
+DESCRIPTION = "Install image to device"

inherit dpkg-raw

@@ -16,7 +15,7 @@ do_install[cleandirs] = "${D}/usr/bin/ \
${D}/usr/lib/systemd/system/ge...@tty1.service.d/ \
${D}/usr/lib/systemd/system/serial...@ttyS0.service.d/"
do_install() {
- install -m 0755 ${WORKDIR}/deploy-image-wic.sh ${D}/usr/bin/deploy-image-wic.sh
- install -m 0600 ${WORKDIR}/install.override.conf ${D}/usr/lib/systemd/system/ge...@tty1.service.d/override.conf
- install -m 0600 ${WORKDIR}/install.override.conf ${D}/usr/lib/systemd/system/serial...@ttyS0.service.d/override.conf
+ install -m 0755 ${WORKDIR}/deploy-image-wic.sh ${D}/usr/bin/deploy-image-wic.sh
+ install -m 0600 ${WORKDIR}/install.override.conf ${D}/usr/lib/systemd/system/ge...@tty1.service.d/override.conf
+ install -m 0600 ${WORKDIR}/install.override.conf ${D}/usr/lib/systemd/system/serial...@ttyS0.service.d/override.conf
}
--
2.43.0

MOESSBAUER, Felix

unread,
Jul 3, 2024, 11:53:21 AM (3 days ago) Jul 3
to isar-...@googlegroups.com, Kiszka, Jan, quirin.g...@siemens.com
On Tue, 2024-07-02 at 15:38 +0200, 'Jan Kiszka' via isar-users wrote:
> From: Jan Kiszka <jan.k...@siemens.com>
>
> Check of the first MB of the target device is only containing zero
-------^ typo: if

> and
> warn otherwise before overwriting potentially valuable data. Looking
> at the first MB should cover enough partition table and file system
> structures to detect a valid disk.
>
> Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
> ---
>  .../deploy-image/files/deploy-image-wic.sh                  | 6
> ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-
> image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-
> image-wic.sh
> index 09d6cc11..81a006ce 100644
> --- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-
> wic.sh
> +++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-
> wic.sh
> @@ -96,6 +96,12 @@ if ! dialog --yes-label Ok --no-label Cancel \
>      exit 0
>  fi
>  
> +if ! cmp /dev/zero "$TARGET_DEVICE" -n 1M && \
> +   ! dialog --defaultno \
> +            --yesno "WARNING: Target device is not empty! Continue

Ok, but I'm sure this will almost always fire.
Even fresh devices are not necessarily zeroed.

Felix

> anyway?" 5 60; then
> +    exit 0
> +fi
> +
>  bmap_options=""
>  if [ -z "$DISK_BMAP" ]; then
>      bmap_options="--nobmap"
> --
> 2.43.0
>

--
Siemens AG, Technology
Linux Expert Center


Jan Kiszka

unread,
Jul 3, 2024, 11:56:00 AM (3 days ago) Jul 3
to Moessbauer, Felix (T CED OES-DE), isar-...@googlegroups.com, Gylstorff, Quirin (T CED OES-DE)
Flash drives are generally by design. But if you have a concrete
proposal how to improve the heuristics, I'm all ears.

Jan

MOESSBAUER, Felix

unread,
Jul 3, 2024, 11:56:32 AM (3 days ago) Jul 3
to isar-...@googlegroups.com, Kiszka, Jan, quirin.g...@siemens.com
On Tue, 2024-07-02 at 15:38 +0200, 'Jan Kiszka' via isar-users wrote:
> From: Jan Kiszka <jan.k...@siemens.com>
>
> If a special file called auto.install is found in the installation
> data
> directory, parse this and attempt an unattended installation. The
> file
> consists of 2 to 3 lines:
>
> - source file name
> - target device path
> - optionally, "OVERWRITE" to ignore if the target device is non-empty

Ehm... did you forget to include a documentation update for this?

Felix

>
> e.g.:
> $ cat /install/auto.install
> isar-image-base-debian-bookworm-qemuamd64.wic.zst
> /dev/vda
> OVERWRITE
>
> Errors are still stopping the process, switching it back to
> interactive
> mode.
>
> Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
> ---
>  .../deploy-image/files/deploy-image-wic.sh       | 16
> ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/meta-isar/recipes-installer/deploy-image/files/deploy-
> image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/deploy-
> image-wic.sh
> index 9df93fe7..8b25b1d2 100644
> --- a/meta-isar/recipes-installer/deploy-image/files/deploy-image-
> wic.sh
> +++ b/meta-isar/recipes-installer/deploy-image/files/deploy-image-
> wic.sh

Jan Kiszka

unread,
Jul 3, 2024, 12:08:50 PM (3 days ago) Jul 3
to Moessbauer, Felix (T CED OES-DE), isar-...@googlegroups.com, Gylstorff, Quirin (T CED OES-DE)
On 03.07.24 17:56, Moessbauer, Felix (T CED OES-DE) wrote:
> On Tue, 2024-07-02 at 15:38 +0200, 'Jan Kiszka' via isar-users wrote:
>> From: Jan Kiszka <jan.k...@siemens.com>
>>
>> If a special file called auto.install is found in the installation
>> data
>> directory, parse this and attempt an unattended installation. The
>> file
>> consists of 2 to 3 lines:
>>
>> - source file name
>> - target device path
>> - optionally, "OVERWRITE" to ignore if the target device is non-empty
>
> Ehm... did you forget to include a documentation update for this?
>

Not forgotten - not yet done. At some point I first wanted to send out
the longer and longer queue.

Jan
Reply all
Reply to author
Forward
0 new messages