openwrt-ipq60xx / openwrt

Other
4 stars 1 forks source link

Redmi AX5 JDCloud Disk Repartition #9

Closed pexcn closed 7 months ago

pexcn commented 7 months ago

Prerequisites

All operations are based on this partition table, so you need to flash this partition table before executing the following commands.

# flash gpt.bin via `dd`
dd if=gpt.bin of=/dev/mmcblk0 bs=512 count=34

Fix partition table

You need to use interactive gdisk, and then directly press the w command to write to the partition table to repair it.

root@AX5-JDCloud:~# gdisk /dev/mmcblk0
GPT fdisk (gdisk) version 1.0.9

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: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Warning! Secondary partition table overlaps the last partition by
112096929 blocks!
Try reducing the partition table size by 448387716 entries.
(Use the 's' item on the experts' menu.)

Command (? for help): w

Warning! Secondary partition table overlaps the last partition by
112096929 blocks!
Try reducing the partition table size by 448387716 entries.
(Use the 's' item on the experts' menu.)
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): Y
Have moved second header and partition table to correct location.
Aborting write of new partition table.

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.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#

Repartition

Refer to the following commands to repartition.

# delete last partition
sgdisk --delete=25 /dev/mmcblk0

# create `extroot` partition (8GB)
sgdisk --new=25:793410:17570625 /dev/mmcblk0
sgdisk --change-name=25:"extroot" /dev/mmcblk0

# create `userdata` partition (remaining space)
sgdisk --new=26:17570626:119783389 /dev/mmcblk0
sgdisk --change-name=26:"userdata" /dev/mmcblk0

# print current partitions
sgdisk --print /dev/mmcblk0

The following is the operation logs.

root@AX5-JDCloud:~# sgdisk --delete=25 /dev/mmcblk0
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#
root@AX5-JDCloud:~# sgdisk --new=25:793410:17570625 /dev/mmcblk0
Warning! Unable to generate a proper UUID! Creating an improper one as a last
resort! Windows 7 may crash if you save this partition table!
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#
root@AX5-JDCloud:~# sgdisk --change-name=25:"extroot" /dev/mmcblk0
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#
root@AX5-JDCloud:~# sgdisk --new=26:17570626:119783389 /dev/mmcblk0
Warning! Unable to generate a proper UUID! Creating an improper one as a last
resort! Windows 7 may crash if you save this partition table!
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#
root@AX5-JDCloud:~# sgdisk --change-name=26:"userdata" /dev/mmcblk0
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@AX5-JDCloud:~#
root@AX5-JDCloud:~# sgdisk --print /dev/mmcblk0
Disk /dev/mmcblk0: 119783424 sectors, 57.1 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 98101B32-BBE2-4BF2-A06E-2BB33D000C20
Partition table holds up to 28 entries
Main partition table begins at sector 2 and ends at sector 8
First usable sector is 34, last usable sector is 119783390
Partitions will be aligned on 2-sector boundaries
Total free space is 1 sectors (512 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34            1569   768.0 KiB   A012  0:SBL1
   2            1570            2081   256.0 KiB   FFFF  0:BOOTCONFIG
   3            2082            2593   256.0 KiB   FFFF  0:BOOTCONFIG1
   4            2594            6177   1.8 MiB     A016  0:QSEE
   5            6178            9761   1.8 MiB     FFFF  0:QSEE_1
   6            9762           10273   256.0 KiB   FFFF  0:DEVCFG
   7           10274           10785   256.0 KiB   FFFF  0:DEVCFG_1
   8           10786           11297   256.0 KiB   A018  0:RPM
   9           11298           11809   256.0 KiB   FFFF  0:RPM_1
  10           11810           12321   256.0 KiB   A01B  0:CDT
  11           12322           12833   256.0 KiB   FFFF  0:CDT_1
  12           12834           13345   256.0 KiB   FFFF  0:APPSBLENV
  13           13346           14625   640.0 KiB   A015  0:APPSBL
  14           14626           15905   640.0 KiB   FFFF  0:APPSBL_1
  15           15906           16417   256.0 KiB   FFFF  0:ART
  16           16418           28705   6.0 MiB     FFFF  0:HLOS
  17           28706          260169   113.0 MiB   FFFF  rootfs
  18          260170          261193   512.0 KiB   FFFF  0:ETHPHYFW
  19          261194          261705   256.0 KiB   FFFF  bdata
  20          261706          262217   256.0 KiB   FFFF  crash
  21          262218          262729   256.0 KiB   FFFF  crash_syslog
  22          262730          524873   128.0 MiB   FFFF  rootfs_data
  23          524874          533065   4.0 MiB     FFFF  cfg_bak
  24          533066          793409   127.1 MiB   FFFF  overlay
  25          793410        17570625   8.0 GiB     8300  extroot
  26        17570626       119783389   48.7 GiB    8300  userdata
root@AX5-JDCloud:~#

TL;DR

If you want, you can directly flash into my repartitioned partition table, it has 8GB of extroot and all remaining space of userdata. But I have not tested it, please use it with caution.

# flash gpt-new.bin
dd if=gpt-new.bin of=/dev/mmcblk0 bs=512 count=34
pexcn commented 7 months ago

You can also use the following commands to view the partition status.

blkid
block info
lsblk -o KNAME,MAJ:MIN,START,SIZE,LABEL,PARTLABEL,PARTUUID,PTUUID,SERIAL
pexcn commented 5 months ago

This is my current partition table, it has 16GB of extroot and all remaining space of userdata.

# delete last partition
sgdisk --delete=25 /dev/mmcblk0
sgdisk --delete=26 /dev/mmcblk0

# create `extroot` partition (16GB)
sgdisk --new=25:793410:34347841 /dev/mmcblk0
sgdisk --change-name=25:"extroot" /dev/mmcblk0

# create `userdata` partition (remaining space)
sgdisk --new=26:34347842:119783389 /dev/mmcblk0
sgdisk --change-name=26:"userdata" /dev/mmcblk0

# print current partitions
sgdisk --print /dev/mmcblk0