From 7e5b119696592c19028be3ea8514feeef7b679f0 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Thu, 18 Aug 2022 16:11:32 +0200 Subject: [PATCH 1/2] feat: Install a bootstrap Artifact in /data/mender/bootstrap.mender Changelog: A bootstrap Artifact is now installed in /data/mender/bootstrap.mender, on every conversion, adding the ability to have the Mender client bootstrap the database without running an update first, thus enabling delta-updates to be installed without first running a full rootfs update. Please note that this will require a minimum of the Mender client at version 3.4.x. However, the generated Artifact is still usable in any case. Ticket: MEN-5594 Signed-off-by: Ole Petter --- mender-convert-modify | 5 ----- mender-convert-package | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/mender-convert-modify b/mender-convert-modify index a777609..68e95d3 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -213,11 +213,6 @@ fi run_and_log_cmd "echo 'device_type=${device_type}' > work/device_type" run_and_log_cmd "sudo install -m 0444 work/device_type work/rootfs/data/mender/" -if [ "${MENDER_CLIENT_INSTALL}" = "y" ]; then - run_and_log_cmd "echo 'artifact_name=${MENDER_ARTIFACT_NAME}' \ - | sudo tee work/rootfs/etc/mender/artifact_info" -fi - log_info "Creating state scripts version file." case "${MENDER_CLIENT_VERSION}" in 1*) VERSION_STRING='2' ;; diff --git a/mender-convert-package b/mender-convert-package index b9ab77b..7171443 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -199,11 +199,10 @@ else log_fatal "Could not determine root file-system type. Aborting..." fi -disk_create_file_system_from_folder "work/rootfs/data/" "work/data.img" \ - "${data_part_sectors}" "${image_fs_type}" - -# Clear this area as it will be contained in the data.img -sudo rm -rf work/rootfs/data/* +# NOTE: Since the data partition has a dependency on the rootfs.img checksum +# when writing the bootstrap Artifact we have to move the datadir out of the +# way, and write the rootfs image first. +run_and_log_cmd "mv --force work/rootfs/data work/data" disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \ "${rootfs_image_sectors}" "${image_fs_type}" @@ -211,6 +210,22 @@ disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \ log_info "Copying root filesystem image to deploy directory" run_and_log_cmd "cp --sparse=always work/rootfs.img deploy/${image_name}.${image_fs_type}" +# Add the bootstrap Artifact to the data.img before packaging +# the data image +log_info "Installing the bootstrap Artifact" +rootfs_img_checksum=$(sha256sum work/rootfs.img | cut -d ' ' -f1) +run_and_log_cmd "mender-artifact write bootstrap-artifact \ + --artifact-name "${MENDER_ARTIFACT_NAME}" \ + --no-progress \ + --device-type "${device_type}" \ + --provides rootfs-image.version:"${MENDER_ARTIFACT_NAME}" \ + --provides rootfs-image.checksum:${rootfs_img_checksum} \ + --output-path work/data/mender/bootstrap.mender" + +disk_create_file_system_from_folder "work/data/" "work/data.img" \ + "${data_part_sectors}" "${image_fs_type}" +run_and_log_cmd "rm -rf work/data" + if [ "${MENDER_CLIENT_INSTALL}" != "y" ]; then log_warn "Generating Artifact with no Mender client in it; not suitable for deployment" fi From d3dc6ffbae643f57b9d7304f9eb3198f60c3995e Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Tue, 23 Aug 2022 11:36:40 +0200 Subject: [PATCH 2/2] chore(minversion): Log a warning if the client != required version Added a simple check to log a warning when an image is generated with the client installed, and the version installed will lead to the image being unusable. Signed-off-by: Ole Petter --- mender-convert-package | 10 ++++++++++ modules/versioncmp.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 modules/versioncmp.sh diff --git a/mender-convert-package b/mender-convert-package index 7171443..b28e4fc 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -39,6 +39,7 @@ echo "Running $(basename $0): $@" source modules/bootstrap.sh source modules/disk.sh source modules/testscfg.sh +source modules/versioncmp.sh # The mender_convert_config is always used and provides all the defaults declare -a configs=("configs/mender_convert_config") @@ -204,6 +205,15 @@ fi # way, and write the rootfs image first. run_and_log_cmd "mv --force work/rootfs/data work/data" +if [[ "${MENDER_CLIENT_INSTALL}" == y ]]; then + # If the client version is less than 3.4, then log a warning + if ! miminum_required_version "3.4.0" "${MENDER_CLIENT_VERSION}"; then + log_warn "You are now installing a Mender client which does not support the " \ + "bootstrap Artifact present in the image. This means that updates will not " \ + "work, and your image is impossible to update" + fi +fi + disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \ "${rootfs_image_sectors}" "${image_fs_type}" diff --git a/modules/versioncmp.sh b/modules/versioncmp.sh new file mode 100644 index 0000000..0a5e0a7 --- /dev/null +++ b/modules/versioncmp.sh @@ -0,0 +1,33 @@ +# Copyright 2022 Northern.tech AS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source modules/log.sh +source modules/probe.sh . + +# Compare the version of a string to a given minimum version requirement +# +# NOTE: Also works for 'master', in that sort does sort it correctly by accident. +# The same goes for all other branches/names, which are not semver. +# +# $1 - Minimum required version +# $2 - Version string +# +# @return - bool +# +function minimum_required_version() { + if [[ $# -ne 2 ]]; then + log_fatal "minimum_required_version() requires two parameters" + fi + [[ "$1" == "$(printf "$1\n$2" | sort --version-sort | head --lines 1)" ]] +}