From 9775c0da2eb2da22ec15c073c3d53a324f62e59a Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 18 Feb 2025 18:57:03 +0100 Subject: [PATCH] feat: warn for signs of external mender installation mender-convert doesn't handle well if the input image has Mender installed already. This could happen if someone did the installation of the Debian Mender package and then attempted to mender-convert that image. This introduces a function that will detect detect the potential issue to aid troubleshooting from the logs once the error is hit. With it you will see: ``` 2025-02-18 18:06:44 [WARN] [mender-convert-modify] work/rootfs/var/lib/mender-monitor exists! 2025-02-18 18:06:44 [WARN] [mender-convert-modify] Input image contain traces Mender of previous Mender installation 2025-02-18 18:06:44 [WARN] [mender-convert-modify] The conversion might fail. Please provide a clean input image. Extra WARN context is above Below is old 2025-02-18 17:53:29 [INFO] [mender-convert-modify] Performing platform specific pre-modifications (if any) 2025-02-18 17:53:29 [INFO] [mender-convert-modify] Running hook: platform_pre_modify 2025-02-18 17:53:29 [INFO] [mender-convert-modify] Creating state folder in the data partition for Mender add-ons mender-convert-modify has finished. Cleaning up... 2025-02-18 17:53:29 [ERROR] [mender-convert] mender-convert failed 2025-02-18 17:53:29 [DEBUG] [mender-convert-modify] When running: (./mender-convert-modify:174): run_and_ log_cmd(): sudo ln -sf /data/mender work/rootfs/var/lib ln: work/rootfs/var/lib/mender: cannot overwrite directory 2025-02-18 17:53:29 [ERROR] [mender-convert] mender-convert failed 2025-02-18 17:53:29 [ERROR] [mender-convert] mender-convert exit code: 1 ``` Changelog: title Ticket: none Signed-off-by: Alan --- mender-convert-modify | 2 ++ modules/probe.sh | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mender-convert-modify b/mender-convert-modify index cec4c58a90..60bb0e3c46 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -103,6 +103,8 @@ mkdir -p work/rootfs sudo mount ${boot_part} work/boot sudo mount ${root_part} work/rootfs +probe_untainted_rootfs_input + if [ -z "${MENDER_DEVICE_TYPE}" ]; then # Observed systems who do not have this file, e.g images generated with mkosi if [ -f work/rootfs/etc/hostname ]; then diff --git a/modules/probe.sh b/modules/probe.sh index 0bdab40e26..782694569f 100644 --- a/modules/probe.sh +++ b/modules/probe.sh @@ -13,6 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Checks there is no preexisting mender integration on the golden image +# +# mender-convert expects a vanilla image wihtout mender installed by other means. +# If you provide as input an image that has mender installed by other means already +# it might fail. +# This function will just print warnings for traces of things that look like a tainted input image +probe_untainted_rootfs_input() { + # None of these should be present in a clean rootfs + directories=( + "work/rootfs/var/lib/mender-monitor" + "work/rootfs/var/lib/mender-configure" + "work/data/mender" + ) + + for dir in "${directories[@]}"; do + if [ -e "$dir" ]; then + log_warn "$dir exists!" + log_warn "Input image contain traces Mender of previous Mender installation" + log_warn "The conversion might fail. Please provide a clean input image." + fi + done +} + # Prints target architecture # # No input parameters and these work on the assumption that boot and root parts