From 252efbec7e29ab1c9bc0b306f93b113a2d647d01 Mon Sep 17 00:00:00 2001 From: "Aaron D. Lee" Date: Thu, 8 Jan 2026 13:00:37 -0500 Subject: [PATCH] Add filesystem validation after flashing Run fsck.vfat on boot partition and e2fsck on root partition after flashing to catch and fix any corruption. Co-Authored-By: Claude Opus 4.5 --- rpi/flash-image.sh | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/rpi/flash-image.sh b/rpi/flash-image.sh index 794fa81..743f9ac 100755 --- a/rpi/flash-image.sh +++ b/rpi/flash-image.sh @@ -307,23 +307,37 @@ echo "" echo -e "${GREEN}Syncing...${NC}" sync +# Wait for partitions to appear +sleep 2 +partprobe "$SELECTED" 2>/dev/null || true +sleep 1 + +# Determine partition names +if [[ "$SELECTED" == *"nvme"* ]] || [[ "$SELECTED" == *"mmcblk"* ]]; then + BOOT_PART="${SELECTED}p1" + ROOT_PART="${SELECTED}p2" +else + BOOT_PART="${SELECTED}1" + ROOT_PART="${SELECTED}2" +fi + +# Validate and repair filesystems +echo "" +echo -e "${YELLOW}Validating filesystems...${NC}" + +echo " Checking boot partition ($BOOT_PART)..." +sudo fsck.vfat -a "$BOOT_PART" 2>&1 | grep -v "^$" || true + +echo " Checking root partition ($ROOT_PART)..." +sudo e2fsck -f -y "$ROOT_PART" 2>&1 | tail -5 || true + +echo -e "${GREEN} ✓ Filesystems validated${NC}" + # Inject WiFi config if config.json was loaded if [ "$HAS_CONFIG" = true ]; then echo "" echo -e "${GREEN}Configuring WiFi from config.json...${NC}" - # Wait for partitions to appear - sleep 2 - partprobe "$SELECTED" 2>/dev/null || true - sleep 1 - - # Determine boot partition - if [[ "$SELECTED" == *"nvme"* ]] || [[ "$SELECTED" == *"mmcblk"* ]]; then - BOOT_PART="${SELECTED}p1" - else - BOOT_PART="${SELECTED}1" - fi - if [ -b "$BOOT_PART" ]; then MOUNT_DIR=$(mktemp -d) if mount "$BOOT_PART" "$MOUNT_DIR" 2>/dev/null; then