From c4925291f98312499f399f91d9d871efff1e62fe Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Fri, 28 Feb 2020 15:38:25 +0100 Subject: [PATCH 1/2] Added hooks to Mender convert This extends the current functionality of the platform_ function functionality into using hooks, so that each modification step can be called from multiple configuration files. The valid hooks are: * PLATFORM_MODIFY_HOOKS * PLATFORM_PACKAGE_HOOKS * USER_LOCAL_MODIFY_HOOKS and can be appended to as a regular bash array. Changelog: Commit Signed-off-by: Ole Petter (cherry picked from commit cab592b5e2ecac463fa56fc70b2f7874bedc3d57) --- mender-convert-modify | 12 ++++++++++-- mender-convert-package | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mender-convert-modify b/mender-convert-modify index 42edc9d..43f454d 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -19,10 +19,12 @@ function platform_modify() { true } +PLATFORM_MODIFY_HOOKS=(platform_modify) function user_local_modify() { true } +USER_LOCAL_MODIFY_HOOKS=(user_local_modify) function trap_exit() { echo "mender-convert-modify has finished. Cleaning up..." @@ -233,10 +235,16 @@ ${MENDER_STORAGE_DEVICE_BASE}${MENDER_DATA_PART_NUMBER} /data auto EOF" log_info "Performing platform specific modifications (if any)" -platform_modify +for hook in "${PLATFORM_MODIFY_HOOKS[@]}"; do + log_info "Running hook: $hook" + eval $hook +done log_info "Performing user/local specific modifications (if any)" -user_local_modify +for hook in "${USER_LOCAL_MODIFY_HOOKS[@]}"; do + log_info "Running hook: $hook" + eval $hook +done for overlay in "${overlays[@]}"; do log_info "Applying rootfs overlay: ${overlay}" diff --git a/mender-convert-package b/mender-convert-package index 1f1bd28..c0ce619 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -19,6 +19,7 @@ function platform_package() { true } +PLATFORM_PACKAGE_HOOKS=(platform_package) function trap_exit() { echo "mender-convert-package has finished. Cleaning up..." @@ -244,7 +245,10 @@ disk_write_at_offset "${output_dir}/rootfs.img" "${img_path}" "${rootfsb_start}" disk_write_at_offset "${output_dir}/data.img" "${img_path}" "${data_start}" log_info "Performing platform specific package operations (if any)" -platform_package +for hook in "${PLATFORM_PACKAGE_HOOKS[@]}"; do + log_info "Running hook: $hook" + eval $hook +done # Create bmap index if [ "${MENDER_USE_BMAP}" == "y" ]; then From 254f6526ebca3c2820e8ff9f03a6d38596eaf089 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Thu, 27 Feb 2020 19:16:18 +0100 Subject: [PATCH 2/2] MEN-3172: [rpi3] Fill all available space on the memory card This commit adds a systemd script which on boot runs parted to fill the remaining space on the memory card into the data partition. Changelog: None Signed-off-by: Ole Petter (cherry picked from commit db59222de16773a6b1da10cf5975811fdbcf0f88) --- configs/images/raspberrypi3_raspbian_config | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/configs/images/raspberrypi3_raspbian_config b/configs/images/raspberrypi3_raspbian_config index 925611e..7f83bab 100644 --- a/configs/images/raspberrypi3_raspbian_config +++ b/configs/images/raspberrypi3_raspbian_config @@ -12,3 +12,37 @@ IMAGE_OVERHEAD_FACTOR=1.0 # Best compression there is! MENDER_COMPRESS_DISK_IMAGE=lzma + +# +# Resize the data partition to fill the remaining space, using parted, with systemd +# +function grow_data_partition() { + log_info "Adding systemd init script to run parted and resize the data partition on boot" + log_info "to fill all the available space on the storage media" + run_and_log_cmd "sudo mkdir -p work/rpi/etc/systemd/system/" + run_and_log_cmd "sudo mkdir -p work/rootfs/etc/systemd/system/data.mount.wants/" + cat <<-EOF > work/rpi/etc/systemd/system/mender-grow-data.service + [Unit] + Description=Mender service to grow data partition size + DefaultDependencies=no + Before=data.mount + Before=systemd-growfs@data.service + + [Service] + Type=oneshot + User=root + Group=root + ExecStart=/sbin/parted --script /dev/mmcblk0 resizepart ${MENDER_DATA_PART_NUMBER} 100% + + [Install] + WantedBy=data.mount +EOF + + # Install + run_and_log_cmd "cp work/rpi/etc/systemd/system/mender-grow-data.service \ + work/rootfs/etc/systemd/system/" + run_and_log_cmd "ln -sf work/rootfs/etc/systemd/system/mender-grow-data.service \ + work/rootfs/etc/systemd/system/data.mount.wants/" +} + +PLATFORM_MODIFY_HOOKS+=(grow_data_partition)