In the email from Monday, 11 July 2022 11:16:02 +03 user Tobias Schmidl wrote:
> If the disk is too small, resizing might have detrimental effects.
> Because of aligning issues, it could happen the the final partition is
> _smaller_ than desired, which might lead to an unusable last partition.
>
> Signed-off-by: Tobias Schmidl <tobiasschmidl@siemens.com>
> ---
> .../files/expand-last-partition.sh | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git
> a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> index c0edde7..0aa1063 100755
> ---
> a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> +++
> b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> @@ -22,6 +22,22 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
> exit 1
> fi
>
> +# this value is in blocks. Normally a block has 512 bytes.
> +BUFFER_SIZE=32768
> +BOOT_DEV_NAME=${BOOT_DEV##*/}
> +DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
> +ALL_PARTS_SIZE=0
> +for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do
It seems to be working only for something like 'sda' => 'sda1'.
For RPi I have
root@isar:~# ls /sys/class/block/ | grep mmc
mmcblk0
mmcblk0p1
mmcblk0p2
So, "p" suffix is required.
Some other devices (like nvme) also need some prefix.
> + PART_SIZE=$(cat "${PARTITION}"/size)
> + ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
> +done
> +
> +MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
> +if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
> + echo "Disk is practically already full, doing nothing." >&2
> + exit 0
> +fi
> +
> LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f
> 1)"
>
> # Transform the partition table as follows:
--
Uladzimir Bely