cbepx-me / Anbernic-H700-RG-xx-StockOS-Modification

Anbernic H700 Stock OS Modification
https://drive.google.com/drive/folders/1uwCkGX3H-K09pj0VbB6hkS8I0_qhzrGY?usp=sharing
311 stars 5 forks source link

Base image partition is invalid #27

Open maroc81 opened 6 months ago

maroc81 commented 6 months ago

The base image file (e.g. RG35XX+-P-BASE-EN20240428-MOD-v2.0.img) has an invalid partition. This causes problems such as #6 unless the disk is fixed after writing the image to a disk. The base image should be fixed so any tool can be used to write the image without extra steps.

It looks like the image was created from a 16GB disk and then just truncated for the last unused partition. I was able to fix the image on a Linux system by doing the following:

  1. Create an empty disk image using dd that is slightly larger (21600512) than the current image (21600256). This leaves room for the backup GPT at the end of the image: dd if=/dev/zero of=base_fixed.img bs=512 count=21600512
  2. Overwrite the empty image with the contents of the broken image. dd if=RG35XX+-P-BASE-EN20240428-MOD-v2.0.img of=base_fixed.img conv=notrunc
  3. Use gdisk to fix the image:
    $ gdisk base_fixed.img
    Command (? for help): r <enter>
    Recovery/transformation command (? for help): x <enter>
    Expert command (? for help): e <enter>
    Expert command (? for help): w <enter>

Before the fix, fisk -l outputs an error message and only 1 partition:

GPT PMBR size mismatch (30277631 != 21600255) will be corrected by write.
Disk RG35XX+-P-BASE-EN20240428-MOD-v2.0.img: 10.3 GiB, 11059331072 bytes, 21600256 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: dos
Disk identifier: 0x00000000

Device                                  Boot Start      End  Sectors  Size Id Type
RG35XX+-P-BASE-EN20240428-MOD-v2.0.img1          1 21600255 21600255 10.3G ee GPT

After the fix, fdisk -l base_fixed.img shows the correct disk partitions:

Disk base_fixed.img: 10.3 GiB, 11059462144 bytes, 21600512 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: AB6F3888-569A-4926-9668-80941DCB40BC

Device             Start      End  Sectors  Size Type
base_fixed.img1    73728   204799   131072   64M Microsoft basic data
base_fixed.img2   204800   270335    65536   32M Microsoft basic data
base_fixed.img3   270336   303103    32768   16M Microsoft basic data
base_fixed.img4   303104   434175   131072   64M Microsoft basic data
base_fixed.img5   434176 17211391 16777216    8G Microsoft basic data
base_fixed.img6 17211392 21600255  4388864  2.1G Microsoft basic data
Jaffa00 commented 5 months ago

Can confirm this process also works on RG35XXH image, which appears to suffer the same problem.