Hi!
After having my Raspberry Pi with home assistant plugged out of the powerlines for two weeks, I have trouble getting it to boot back up again. Before unplugging it, I had no issues.
When connecting the sdcard to a Linux laptop, and using fdisk -l, I get the following:
The backup GPT table is corrupt, but the primary appears OK, so that will be used. Disk /dev/mmcblk0: 29.72 GiB, 31914983424 bytes, 62333952 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: 1ED17572-FEA5-4C23-82C3-57C2F576F6B3 Device Start End Sectors Size Type /dev/mmcblk0p1 2048 67583 65536 32M Microsoft reserved /dev/mmcblk0p2 67584 116735 49152 24M Linux filesystem /dev/mmcblk0p3 116736 641023 524288 256M Linux filesystem /dev/mmcblk0p4 641024 690175 49152 24M Linux filesystem /dev/mmcblk0p5 690176 1214463 524288 256M Linux filesystem /dev/mmcblk0p6 1214464 1230847 16384 8M Linux filesystem /dev/mmcblk0p7 1230848 1427455 196608 96M Linux filesystem /dev/mmcblk0p8 1427456 62333918 60906463 29G Linux filesystem
Also, I can only mount the first (fat) partition, and not any of the other 7 (p2 to p8). It throws me an error about the superblocks:
ubuntu@ubuntu:~$ sudo mount /dev/mmcblk0p2 /media/sdcard mount: /media/sdcard: can't read superblock on /dev/mmcblk0p2. ubuntu@ubuntu:~$ sudo mount /dev/mmcblk0p8 /media/sdcard mount: /media/sdcard: wrong fs type, bad option, bad superblock on /dev/mmcblk0p8, missing codepage or helper program, or other error.
After some Googling I came across gdisk, so I ran sudo gdisk /dev/mmcblk0
and got the message that the backup header and backup partition table have an error. Therefore, I tried a standard validate (-v) and write (-w) to fix it:
ubuntu@ubuntu:~$ sudo gdisk /dev/mmcblk0 GPT fdisk (gdisk) version 1.0.8 Caution: invalid backup GPT header, but valid main header; regenerating backup header from main header. Warning! Main and backup partition tables differ! Use the 'c' and 'e' options on the recovery & transformation menu to examine the two tables. Warning! One or more CRCs don't match. You should repair the disk! Main header: OK Backup header: ERROR Main partition table: OK Backup partition table: ERROR Partition table scan: MBR: hybrid BSD: not present APM: not present GPT: damaged Found valid MBR and corrupt GPT. Which do you want to use? (Using the GPT MAY permit recovery of GPT data.) 1 - MBR 2 - GPT 3 - Create blank GPT Your answer: 2 Command (? for help): p Disk /dev/mmcblk0: 62333952 sectors, 29.7 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 1ED17572-FEA5-4C23-82C3-57C2F576F6B3 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 62333918 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 67583 32.0 MiB 0C01 hassos-boot 2 67584 116735 24.0 MiB 8300 hassos-kernel0 3 116736 641023 256.0 MiB 8300 hassos-system0 4 641024 690175 24.0 MiB 8300 hassos-kernel1 5 690176 1214463 256.0 MiB 8300 hassos-system1 6 1214464 1230847 8.0 MiB 8300 hassos-bootstate 7 1230848 1427455 96.0 MiB 8300 hassos-overlay 8 1427456 62333918 29.0 GiB 8300 hassos-data Command (? for help): v Caution: The CRC for the backup partition table is invalid. This table may be corrupt. This program will automatically create a new backup partition table when you save your partitions. Identified 1 problems! Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/mmcblk0. The operation has completed successfully.
Although there are no errors in the update process, rerunning gdisk gives exactly the same result as before. Therefore, I tried to rebuild the backup partition table and the backup header via the recovery menu of gdisk, If I then verify (before writing to disk), gdisk tells me all is good. So I write to disk:
ubuntu@ubuntu:~$ sudo gdisk /dev/mmcblk0 GPT fdisk (gdisk) version 1.0.8 Caution: invalid backup GPT header, but valid main header; regenerating backup header from main header. Warning! Main and backup partition tables differ! Use the 'c' and 'e' options on the recovery & transformation menu to examine the two tables. Warning! One or more CRCs don't match. You should repair the disk! Main header: OK Backup header: ERROR Main partition table: OK Backup partition table: ERROR Partition table scan: MBR: hybrid BSD: not present APM: not present GPT: damaged Found valid MBR and corrupt GPT. Which do you want to use? (Using the GPT MAY permit recovery of GPT data.) 1 - MBR 2 - GPT 3 - Create blank GPT Your answer: 2 Command (? for help): r Recovery/transformation command (? for help): ? b use backup GPT header (rebuilding main) c load backup partition table from disk (rebuilding main) d use main GPT header (rebuilding backup) e load main partition table from disk (rebuilding backup) f load MBR and build fresh GPT from it g convert GPT into MBR and exit h make hybrid MBR i show detailed information on a partition l load partition data from a backup file m return to main menu o print protective MBR data p print the partition table q quit without saving changes t transform BSD disklabel partition v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Recovery/transformation command (? for help): d Recovery/transformation command (? for help): e Warning! This will probably do weird things if you've converted an MBR to GPT form and haven't yet saved the GPT! Proceed? (Y/N): y Recovery/transformation command (? for help): v No problems found. 2014 free sectors (1007.0 KiB) available in 1 segments, the largest of which is 2014 (1007.0 KiB) in size. Recovery/transformation command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/mmcblk0. The operation has completed successfully.
Unfortunately, this does not seem to alter anything. If I run gdisk again, I get the same warnings about broken backup header and partition table. Also, fdisk -l and trying to mount it give the same warnings and errors as before. To me it seems as if gdisk is not actually writing to the disk, even though it does not throw errors.
I am in the dark now. It seems as If I have found the problem (corrupted backup partition table and backup header of GPT) and the solution (copying the main header and partition table to the backup via gdisk), which then seems to have effect (gdisk’s verify option gives no more errors), but does not actually do anything (restarting the gdisk process gives exactly the same errors).
Is there anyone who has an idea what I can do to further debug, and hopefully fix, the problem?