How to "replace" broken squashfs images

My RPi HASSio started to keep rebooting every minute or so in a vicious cycle due to squashfs errors. Taking card out with following partitions

❯ sudo file -s /dev/mmcblk0p*
/dev/mmcblk0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, reserved sectors 4, root entries 512, Media descriptor 0xf8, sectors/FAT 64, sectors/track 32, heads 64, sectors 65536 (volumes > 32 MB), serial number 0xed2c3766, label: "hassos-boot", FAT (16 bit)
/dev/mmcblk0p2: Squashfs filesystem, little endian, version 4.0, lzo compressed, 10035612 bytes, 2 inodes, blocksize: 131072 bytes, created: Wed Mar 13 12:14:48 2024
/dev/mmcblk0p3: Squashfs filesystem, little endian, version 4.0, lz4 compressed, 147597885 bytes, 6513 inodes, blocksize: 131072 bytes, created: Wed Mar 13 12:14:46 2024
/dev/mmcblk0p4: Squashfs filesystem, little endian, version 4.0, lzo compressed, 10060442 bytes, 2 inodes, blocksize: 131072 bytes, created: Thu Apr 11 10:41:13 2024
/dev/mmcblk0p5: Squashfs filesystem, little endian, version 4.0, lz4 compressed, 154625010 bytes, 6575 inodes, blocksize: 131072 bytes, created: Thu Apr 11 10:41:12 2024
/dev/mmcblk0p6: OpenPGP Public Key
/dev/mmcblk0p7: Linux rev 1.0 ext4 filesystem data, UUID=a8b08e9b-eb96-41f3-89bc-30f39c592e14, volume name "hassos-overlay" (extents) (64bit) (large files) (huge files)
/dev/mmcblk0p8: Linux rev 1.0 ext4 filesystem data, UUID=d561dff3-3389-47ac-8225-fc8f0c7ea53b, volume name "hassos-data" (needs journal recovery) (errors) (extents) (64bit) (large files) (huge files)

I saw that it is 3 and 5 which are bad:

❯ sudo unsquashfs /dev/mmcblk0p3
Parallel unsquashfs: Using 20 processors
6336 inodes (7027 blocks) to write

[==============-                                                      ]  2907/13363  21%
lz4 uncompress failed with error code -15

FATAL ERROR: writer: failed to read/uncompress file squashfs-root/usr/bin/dirname

❯ sudo cat squashfs-root/etc/issue
Welcome to Home Assistant

and

❯ sudo unsquashfs /dev/mmcblk0p5
Parallel unsquashfs: Using 20 processors
6385 inodes (7171 blocks) to write

[================\                                                    ]  3232/13556  23%
lz4 uncompress failed with error code -30307

FATAL ERROR: writer: failed to read/uncompress file squashfs-root/usr/bin/dockerd

I would expect to make it back into working solution if I dump some correct/fixed squashfs images to them (possibly moving those partitions around on sd, but may be no need) and trying to boot again. But how to determine which images to use and where to get them?

If that would work – I wonder if it might be writing a simple generic script which given SD card would “fix it up” that way having determined that some image is bad.

The main data partition is /dev/mmcblk0p8, so I would recommend to make a backup of it’s content before trying anything :sweat_smile:

All other partitions have a static size, and are mostly stateless, so you can safely overwrite them from a newly downloaded image. The overlay partition has some OS settings like IP addresses etc. so, you can spare that as well if you want to keep these settings.

done that the first thing

❯ ls -l /var/tmp/hass-sdcard
total 3089204
-rw-r--r-- 1 root root   33554432 Jun  8 19:51 p1.dat
-rw-r--r-- 1 root root   25165824 Jun  8 19:51 p2.dat
-rw-r--r-- 1 root root  268435456 Jun  8 19:51 p3.dat
-rw-r--r-- 1 root root   25165824 Jun  8 19:51 p4.dat
-rw-r--r-- 1 root root  268435456 Jun  8 19:51 p5.dat
-rw-r--r-- 1 root root    8388608 Jun  8 19:51 p6.dat
-rw-r--r-- 1 root root  100663296 Jun  8 19:51 p7.dat
-rw-r--r-- 1 root root 2433535237 Jun  8 20:21 p8.ext4.tgz

that’s exactly what I would like to try – but to download where from?

You can find all images at the GitHub release page of the HAOS repo at Releases · home-assistant/operating-system · GitHub.

1 Like

Cool, FTR I can get flavor from

❯ grep -r haos squashfs-root
squashfs-root/etc/rauc/system.conf:compatible=haos-rpi3-64

and then from ext4 partition (8)

supervisor/updater.json:  "hassos": "12.3",

so I download haos_rpi3-64-12.3.img.xz. After that I xzcat into a .img file, and fdisk gives me

❯ fdisk -l haos_rpi3-64-12.3.img
Disk haos_rpi3-64-12.3.img: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 117224D8-16BB-4329-AD88-7D30B3C2300E

Device                   Start     End Sectors  Size Type
haos_rpi3-64-12.3.img1    2048   67583   65536   32M Microsoft reserved
haos_rpi3-64-12.3.img2   67584  116735   49152   24M Linux filesystem
haos_rpi3-64-12.3.img3  116736  641023  524288  256M Linux filesystem
haos_rpi3-64-12.3.img4  641024  690175   49152   24M Linux filesystem
haos_rpi3-64-12.3.img5  690176 1214463  524288  256M Linux filesystem
haos_rpi3-64-12.3.img6 1214464 1230847   16384    8M Linux filesystem
haos_rpi3-64-12.3.img7 1230848 1427455  196608   96M Linux filesystem
haos_rpi3-64-12.3.img8 1427456 4048895 2621440  1.3G Linux filesystem

so now I can use dd … but got into an oddity for partitions 4-6 (seems to be empty) on which asked at Home Assistant OS 12.3 · home-assistant/operating-system · Discussion #3345 · GitHub

edit: wrote the script to “safely” copy filesystems from the image to the sdcard: fix sdcard squashfs partitions for hassio · GitHub . The beast is running again

Blockquote

1 Like