From 426d1c7db8c40630721ae9ddbec3d16f193c268d Mon Sep 17 00:00:00 2001 From: Tomaz Zaman Date: Mon, 10 Aug 2026 16:12:49 +0200 Subject: [PATCH 11/72] layerscape: ext4 rootfs with first-boot auto-expand The rootfs partition is created at its final full-eMMC size in the GPT at image-assembly time and only the filesystem grows on first boot (online resize2fs via uci-defaults). No partition tool ever runs against the live eMMC: standard tools rewrite the GPT with the entry array at LBA2, which on this board would land on the raw boot firmware at 4K. make_ext4fs output cannot be grown online (the kernel resizer rejects its reserved-GDT layout with 'reserved block not at offset'); e2fsck plus one offline grow to 1.5G during image assembly rebuilds the resize metadata. Verified by loop-mounting the artifact and growing it online. Co-Authored-By: Claude Fable 5 --- .../10-mono-gateway-expand-rootfs | 17 +++++++++++ .../layerscape/image/gen_mono_emmc_img.sh | 28 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 target/linux/layerscape/base-files/etc/uci-defaults/10-mono-gateway-expand-rootfs diff --git a/target/linux/layerscape/base-files/etc/uci-defaults/10-mono-gateway-expand-rootfs b/target/linux/layerscape/base-files/etc/uci-defaults/10-mono-gateway-expand-rootfs new file mode 100644 index 0000000000..f6d9fb4933 --- /dev/null +++ b/target/linux/layerscape/base-files/etc/uci-defaults/10-mono-gateway-expand-rootfs @@ -0,0 +1,17 @@ +#!/bin/sh +# The eMMC image ships a 1 GB ext4 rootfs inside a partition already +# sized to the full eMMC (the GPT is never rewritten on-device because +# the entry array lives at 5 MiB, clear of the raw boot firmware, and +# standard partition tools would relocate it). Grow the filesystem to +# the partition once, online, on first boot. +. /lib/functions.sh + +case "$(board_name)" in +mono,gateway-dk|mono,gateway-dk-sdboot) + root_dev=$(readlink -f /dev/root 2>/dev/null) + [ "$root_dev" = "/dev/mmcblk0p2" ] || root_dev=/dev/mmcblk0p2 + resize2fs "$root_dev" 2>&1 | logger -t expand-rootfs + ;; +esac + +exit 0 diff --git a/target/linux/layerscape/image/gen_mono_emmc_img.sh b/target/linux/layerscape/image/gen_mono_emmc_img.sh index 92d37d004d..f921cae2c0 100755 --- a/target/linux/layerscape/image/gen_mono_emmc_img.sh +++ b/target/linux/layerscape/image/gen_mono_emmc_img.sh @@ -11,7 +11,7 @@ # set -ex [ $# -eq 5 ] || { - echo "SYNTAX: $0 " + echo "SYNTAX: $0 " exit 1 } @@ -19,14 +19,36 @@ OUTPUT="$1" BOOTFS="$2" ROOTFS="$3" BOOTFSSIZE="$4" -ROOTFSSIZE="$5" +ROOTFSPARTSIZE="$5" + +# The rootfs PARTITION is created at its final (full-eMMC) size; the +# filesystem image inside is smaller and resize2fs grows it on first +# boot. This avoids any on-device GPT rewrite, which standard tools +# would relocate over the raw boot-firmware region. +# +# make_ext4fs output cannot be grown online (its reserved-GDT layout is +# rejected by the kernel resizer: "reserved block not at offset"). +# e2fsck plus ONE offline grow on the host rebuilds the resize metadata; +# after that the first-boot online resize works. Verified via loop mount. +cp "$ROOTFS" "$OUTPUT.rootfs" +e2fsck -fy "$OUTPUT.rootfs" || [ $? -le 2 ] +truncate -s 1536M "$OUTPUT.rootfs" +resize2fs "$OUTPUT.rootfs" +ROOTFS="$OUTPUT.rootfs" set $(ptgen -o $OUTPUT -v -g -e 5120 \ -N boot -p ${BOOTFSSIZE}M@32M \ - -N rootfs -p ${ROOTFSSIZE}M) + -N rootfs -p ${ROOTFSPARTSIZE}M) BOOTOFFSET=$(($1 / 512)) ROOTFSOFFSET=$(($3 / 512)) dd bs=512 if="$BOOTFS" of="$OUTPUT" seek=${BOOTOFFSET} conv=notrunc dd bs=512 if="$ROOTFS" of="$OUTPUT" seek=${ROOTFSOFFSET} conv=notrunc + +# Trim the image after the rootfs payload: the partition extends far +# beyond it, and the alternate GPT ptgen placed at partition end would +# otherwise make the image eMMC-sized. The kernel accepts the primary +# GPT alone. +ROOTFSBYTES=$(stat -c%s "$ROOTFS") +truncate -s $(($3 + ROOTFSBYTES)) "$OUTPUT" -- 2.47.3