From 657b46823124ae01e231f444516a07d6f736c8a6 Mon Sep 17 00:00:00 2001 From: macmpi <16296055+macmpi@users.noreply.github.com> Date: Sun, 12 Oct 2025 17:34:29 +0200 Subject: [PATCH] scripts/mkimg.arm.sh: build Pi img as resizable FAT16 partition Construct a partitioned disk, resizable with libparted-based tools (gparted and al.). libparted has limitations to cross cluster size boundaries in resize operations [1]. Use the minimum image file size to ensure FAT16 partition crosses the 2K/4K cluster size boundary (128MB+)[2]. In MB alignment, this is a full image 130MB = 129MB + 1MB offset for partition table (sector 2048 =1MB). [1] https://www.gnu.org/software/parted/manual/html_node/parted_58.html [2] https://www.pctechguide.com/hard-disks/file-systems-fat-fat8-fat16-fat32-and-ntfs-explained --- scripts/mkimg.arm.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/mkimg.arm.sh b/scripts/mkimg.arm.sh index 120751b7774..694b952ec73 100644 --- a/scripts/mkimg.arm.sh +++ b/scripts/mkimg.arm.sh @@ -52,12 +52,14 @@ profile_rpi() { } create_image_imggz() { + MIN_IMG_SIZE=130 # exceed 128MB minimum FAT16 partition size in MB to cross 4k cluster size boundary sync "$DESTDIR" - local image_size=$(du -L -k -s "$DESTDIR" | awk '{print $1 + 8192}' ) local imgfile="${OUTDIR}/${output_filename%.gz}" - dd if=/dev/zero of="$imgfile" bs=1M count=$(( image_size / 1024 )) - mformat -i "$imgfile" -N 0 :: - mcopy -s -i "$imgfile" "$DESTDIR"/* "$DESTDIR"/.alpine-release :: + local image_size=$(du -L -k -s "$DESTDIR" | awk '{print int(($1 + 8192) / 1024)}' ) + dd if=/dev/zero of="$imgfile" bs=1M count=$(( image_size > $MIN_IMG_SIZE ? image_size : $MIN_IMG_SIZE )) + echo 'start=2048, type=6, bootable' | sfdisk "$imgfile" # create partition table with FAT16 at standard 2048 sector (1MB) + mkfs.vfat -n PIBOOT -F 16 --offset 2048 "$imgfile" + mcopy -s -i "$imgfile"@@2048s "$DESTDIR"/* "$DESTDIR"/.alpine-release :: echo "Compressing $imgfile..." pigz -v -f -9 "$imgfile" || gzip -f -9 "$imgfile" }