fs-resize: gate resize2fs on fsck, fix sd* boot partition name, explain warnings

Analysis of a first-boot resize log (docs/resize.log):

- The two FAT warnings it records are expected and harmless. The 256MB
  boot partition ships the same out-of-spec FAT32 (16375 clusters, below
  the 65525 minimum) as ROCKNIX and the rest of the RK3326 ecosystem;
  vendor U-Boots are only tested against that layout, so reformatting it
  is exactly the change that has caused boot loops before. The
  boot-sector/backup difference is the kernel vfat dirty flag, written
  to the primary sector only while /flash is mounted read-write; the
  shipped image was verified to carry identical primary and backup
  sectors. The script now appends a NOTE to the log so the warnings stop
  being reported as failures.

Real defects fixed:

- resize2fs ran regardless of the e2fsck result; on unfixed corruption
  (exit above 2) growing the filesystem would compound the damage. The
  resize is now skipped in that case, leaving the grown partition for a
  later retry after a manual fsck.
- The boot-partition path was hardcoded as ${DISK}p1, which is wrong for
  /dev/sdX disks (sdXp1 does not exist), so the FAT serial
  randomization silently never ran there. Derive the partition name per
  device type alongside DISK.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Douglas Teles
2026-07-01 22:39:12 -03:00
parent 1d892b9231
commit 235f113c25
@@ -39,9 +39,14 @@ if [ -e /storage/.please_resize_me ] ; then
case $PART in
"/dev/mmcblk"*|"/dev/nvme"*)
DISK=$(echo $PART | sed s/p[0-9]$//g)
PART1="${DISK}p1"
;;
*)
DISK=$(echo $PART | sed s/[0-9]$//g)
# /dev/sdX partitions have no "p" separator; ${DISK}p1 pointed at a
# nonexistent node and the boot-partition serial was never randomized
# on those devices.
PART1="${DISK}1"
;;
esac
@@ -60,9 +65,26 @@ if [ -e /storage/.please_resize_me ] ; then
echo ""
StartProgressLog spinner "Resizing partition... " "parted -s -f -m $DISK resizepart $PARTNUM 100% >>$LOG 2>&1"
StartProgressLog spinner "Checking file system... " "e2fsck -f -p $PART >>$LOG 2>&1"
StartProgressLog spinner "Resizing file system... " "resize2fs $PART >>$LOG 2>&1"
StartProgressLog spinner "Regenerating UUIDs... " "tune2fs $PART -U random >>$LOG 2>&1; fatlabel -i -r ${DISK}p1 >>$LOG 2>&1"
# e2fsck -p exits 0 (clean), 1 (fixed) or 2 (fixed, reboot wanted);
# anything above means unfixed corruption, and growing a broken
# filesystem with resize2fs would compound the damage. Leave the
# partition grown but the filesystem untouched; a later boot can
# retry after a manual fsck.
StartProgressLog spinner "Checking file system... " "e2fsck -f -p $PART >>$LOG 2>&1; echo \$? >/tmp/fsck-status"
FSCK_STATUS=$(cat /tmp/fsck-status 2>/dev/null || echo 0)
if [ "${FSCK_STATUS:-0}" -le 2 ]; then
StartProgressLog spinner "Resizing file system... " "resize2fs $PART >>$LOG 2>&1"
else
echo "e2fsck exited ${FSCK_STATUS}; skipping resize2fs to avoid growing a corrupted filesystem" | tee -a $LOG
fi
StartProgressLog spinner "Regenerating UUIDs... " "tune2fs $PART -U random >>$LOG 2>&1; fatlabel -i -r $PART1 >>$LOG 2>&1"
# The two FAT warnings fatlabel prints here are expected and harmless:
# the 256MB boot partition ships the same out-of-spec FAT32 layout as
# the whole RK3326 ecosystem (vendor U-Boots are only tested against
# it, so it must not be "fixed"), and the boot-sector/backup difference
# is the kernel vfat dirty flag, written to the primary sector only
# while /flash is mounted read-write.
echo "NOTE: the FAT32 cluster-count and boot-sector-backup warnings above are expected and harmless." >>$LOG
StartProgressLog spinner "Syncing to disk... " "sync >>$LOG 2>&1"
StartProgress countdown "Rebooting in 5s... " 5 "NOW"
else