diff --git a/projects/ArchR/packages/sysutils/busybox/scripts/fs-resize b/projects/ArchR/packages/sysutils/busybox/scripts/fs-resize index d97b2a8866..ef8ac6e7db 100755 --- a/projects/ArchR/packages/sysutils/busybox/scripts/fs-resize +++ b/projects/ArchR/packages/sysutils/busybox/scripts/fs-resize @@ -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