diff --git a/configs/mender_convert_config b/configs/mender_convert_config index b056b74..b4929da 100644 --- a/configs/mender_convert_config +++ b/configs/mender_convert_config @@ -127,6 +127,41 @@ MENDER_USE_BMAP="n" # In most cases you would like this enabled. MENDER_COPY_BOOT_GAP="y" +# The size of each of the two rootfs filesystems, in KiB. If this is 0, +# mender-convert will use the size of the filesystem content as a basis. If the +# value is -1, mender-convert will use the maximum size that will fit inside the +# created partition. The size is further modified by IMAGE_ROOTFS_EXTRA_SPACE +# and IMAGE_OVERHEAD_FACTOR. +# +# This variable directly mirrors the variable from the Yocto Project, which is +# why it is missing a "MENDER_" prefix. +IMAGE_ROOTFS_SIZE="0" + +# The amount of extra free space requested on the rootfs, in KiB. This is added +# to the value of IMAGE_ROOTFS_SIZE. The size is further modified by +# IMAGE_OVERHEAD_FACTOR. +# +# Note that due to reserved space for the root user on the filesystem, "df" may +# report a significantly lower number than requested. A more accurate number can +# be fetched using for example "dumpe2fs" and looking for the "Free blocks" +# field, but even this value is usually going to be lower than requested due to +# meta data on the filesystem. +# +# This variable directly mirrors the variable from the Yocto Project, which is +# why it is missing a "MENDER_" prefix. +IMAGE_ROOTFS_EXTRA_SPACE="0" + +# This factor is multiplied by the used space value for the generated rootfs, +# and if the result is larger than IMAGE_ROOTFS_SIZE + IMAGE_ROOTFS_EXTRA_SPACE, +# it will be used as the size of the rootfs instead of the other two variables. +# +# The actual free space will usually be lower than requested. See comment for +# IMAGE_ROOTFS_EXTRA_SPACE. +# +# This variable directly mirrors the variable from the Yocto Project, which is +# why it is missing a "MENDER_" prefix. +IMAGE_OVERHEAD_FACTOR="1.5" + source configs/mender_grub_config # Function to create Mender Artifact diff --git a/mender-convert-package b/mender-convert-package index 1a78a20..cf48049 100755 --- a/mender-convert-package +++ b/mender-convert-package @@ -142,15 +142,32 @@ image_name="${device_type}-${artifact_name}" actual_rootfs_size=$(sudo du -s --block-size=512 work/rootfs | cut -f 1) -# 50 % free space, not to be confused with rootfs_part_sectors -rootfs_image_sectors=$(awk -v r1="$actual_rootfs_size" 'BEGIN{printf "%.0f", r1 * 1.50}') +# KiB -> 512 sectors +image_rootfs_size_sectors=$((${IMAGE_ROOTFS_SIZE} * 2)) + +if [ "${IMAGE_ROOTFS_SIZE}" -eq -1 ]; then + rootfs_image_sectors="${rootfs_part_sectors}" +elif [ "${image_rootfs_size_sectors}" -lt "${actual_rootfs_size}" ]; then + rootfs_image_sectors="${actual_rootfs_size}" +else + rootfs_image_sectors="${image_rootfs_size_sectors}" +fi + +rootfs_image_sectors=$((${rootfs_image_sectors} + ${IMAGE_ROOTFS_EXTRA_SPACE} * 2)) + +rootfs_image_sectors_overhead=$(awk -v r1="$actual_rootfs_size" "BEGIN{printf \"%.0f\", r1 * ${IMAGE_OVERHEAD_FACTOR}}") +if [ "${rootfs_image_sectors_overhead}" -gt "${rootfs_image_sectors}" ]; then + rootfs_image_sectors="${rootfs_image_sectors_overhead}" +fi if [ ${rootfs_image_sectors} -gt ${rootfs_part_sectors} ]; then log_warn "The calculated rootfs partition size $(disk_sectors_to_mb ${rootfs_part_sectors}) MiB is too small." log_warn "The actual rootfs image size is $(disk_sectors_to_mb ${rootfs_image_sectors}) MiB" - log_fatal "You can try adjusting the MENDER_STORAGE_TOTAL_SIZE_MB variable to increase available space" + log_fatal "You can try adjusting the MENDER_STORAGE_TOTAL_SIZE_MB variable to increase available space, or modify one of the variables IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_EXTRA_SPACE or IMAGE_OVERHEAD_FACTOR to reduce the size of the root filesystem." fi +log_info "Rootfs filesystem size will be $(disk_sectors_to_mb ${rootfs_image_sectors}) MiB" + # Extract file-system type from rootfs if file ${root_part} | grep -q ext4; then image_fs_type="ext4"