OESF Portal | OESF Forum | OESF Wiki | LinuxPDA | #planetgemini chat on matrix.org | #gemini-pda chat on Freenode | #zaurus and #alarmz chat on Freenode | ELSI (coming soon) | Ibiblio


Welcome Guest ( Log In | Register )

Reply to this topicStart new topic
> Partitioning the Cosmo for multi-boot without losing your Android data
post Jan 18 2020, 10:09 AM
Post #1

Group: Members
Posts: 32
Joined: 28-November 19
Member No.: 860,591

Planet have finally released the promised multi-boot option. Unfortunately, using their Recovery, you cannot reformat the Cosmo without losing all your existing data. I didn't want to wipe my Android install, so...

How it works

Stock, the Cosmo's partition map includes a very large userdata partition (combined Android /data and /sdcard) at number 38, followed by otp (39) and flashinfo (40).

When you partition the Cosmo, the userdata partition is deleted and replaced by these, in this order:
- 43: 30/60/90GB linux
- 44: 30/60/90GB userdata (Android)

The tricky thing is that the userdata partition is encrypted using Android's FDE system (using some metadata stored in the 'metadata' partition); getting access to this from recovery mode is quite a pain.

Also, to match the Cosmo's 'intended' configuration, your userdata partition needs to be physically located after the other partitions. I have not done this; I've left userdata where it started. The partition numbers and names are correct, but the exact sector boundaries are different. Hopefully this won't cause issues!

Planet's 60GB Linux/60GB Android split is defined as follows (start sector number, end sector number):
- 38: 10158080 - 10223615 (65536 sectors)
- 41: 10223616 - 10289151 (65536 sectors)
- 42: 10289152 - 10354687 (65536 sectors)
- 43: 10354688 - 127542188 (117187501 sectors / 55.87GB)
- 44: 127543296 - 244164543 (116621248 sectors / 55.6GB)

I have defined mine as follows, to keep userdata (44) starting at the same original position:
- 38: 126779328 - 126844863 (65536 sectors)
- 41: 126844864 - 126910399 (65536 sectors)
- 42: 126910400 - 126975935 (65536 sectors)
- 43: 126976000 - 244163436 (117187437 sectors / 55.87GB)
- 44: 10158080 - 126779327 (116621248 sectors / 55.6GB)

How to do it

Caution: This is extremely experimental; try it at your own risk!

First, you will need my build of TWRP installed: https://www.oesf.org/forum/index.php?showtopic=35988
You will also need ADB set up, and easy access to a hex editor of some kind.

- Boot into TWRP and run 'adb shell' to get a shell on the Cosmo.
- Run ls /data/ to check that userdata has been decrypted successfully: you should see some stuff in there.
- Tap Mount on the TWRP main menu and uncheck Data.
- Run mount to view mounted filesystems: /dev/block/dm-0 should NOT be mounted and should not show up in the list in any form.
- Use ADB to push parted_static (from the official Cosmo recovery) to /tmp: https://wuffs.org/files/parted_static
- Run chmod +x /tmp/parted_static

You are now ready to re-partition your Cosmo.

Run the following commands:

resize2fs /dev/block/dm-0 116621248s
/tmp/parted_static /dev/block/mmcblk0 rm 38
/tmp/parted_static /dev/block/mmcblk0 u s mkpart primary 126779328 126844863
/tmp/parted_static /dev/block/mmcblk0 name 38 EMPTY_RECOVERY_BOOT_2
/tmp/parted_static /dev/block/mmcblk0 toggle 38 msftdata
/tmp/parted_static /dev/block/mmcblk0 u s mkpart primary 126844928 126910463
/tmp/parted_static /dev/block/mmcblk0 name 41 EMPTY_NORMAL_BOOT_3
/tmp/parted_static /dev/block/mmcblk0 toggle 41 msftdata
/tmp/parted_static /dev/block/mmcblk0 u s mkpart primary 126910464 126975999
/tmp/parted_static /dev/block/mmcblk0 name 42 EMPTY_NORMAL_BOOT_4
/tmp/parted_static /dev/block/mmcblk0 toggle 42 msftdata
/tmp/parted_static /dev/block/mmcblk0 u s mkpart primary 126976000 244163436
/tmp/parted_static /dev/block/mmcblk0 name 43 linux
/tmp/parted_static /dev/block/mmcblk0 toggle 43 msftdata
/tmp/parted_static /dev/block/mmcblk0 u s mkpart primary 10158080 126779327
/tmp/parted_static /dev/block/mmcblk0 name 44 userdata
/tmp/parted_static /dev/block/mmcblk0 toggle 44 msftdata

Do not paste the entire block in at once; do one command at a time. You may receive warnings from parted about the partition being in use, since devicemapper keeps it open - type I and press enter to ignore these.

Once all these commands have been run, your Cosmo has been re-partitioned.
You may wish to check your resulting partition table against what I received:
# /tmp/parted_static /dev/block/mmcblk0 u s p
Model: MMC hDEaP3 (sd/mmc)
Disk /dev/block/mmcblk0: 244285440s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start       End         Size        File system  Name                   Flags
1      64s         2111s       2048s                    boot_para              msftdata
2      2112s       67647s      65536s                   recovery               msftdata
3      67648s      68671s      1024s                    para                   msftdata
4      68672s      109631s     40960s                   expdb                  msftdata
5      109632s     111679s     2048s                    frp                    msftdata
6      111680s     177215s     65536s      ext4         nvcfg                  msftdata
7      177216s     308287s     131072s     ext4         nvdata                 msftdata
8      308288s     373823s     65536s                   metadata               msftdata
9      373824s     390207s     16384s      ext4         protect1               msftdata
10      390208s     409599s     19392s      ext4         protect2               msftdata
11      409600s     425983s     16384s                   seccfg                 msftdata
12      425984s     524287s     98304s      ext4         persist                msftdata
13      524288s     528383s     4096s                    sec1                   msftdata
14      528384s     534527s     6144s                    proinfo                msftdata
15      534528s     739327s     204800s                  md1img                 msftdata
16      739328s     772095s     32768s                   md1dsp                 msftdata
17      772096s     774143s     2048s                    spmfw                  msftdata
18      774144s     786431s     12288s                   scp1                   msftdata
19      786432s     798719s     12288s                   scp2                   msftdata
20      798720s     800767s     2048s                    sspm_1                 msftdata
21      800768s     802815s     2048s                    sspm_2                 msftdata
22      802816s     833535s     30720s                   cam_vpu1               msftdata
23      833536s     864255s     30720s                   cam_vpu2               msftdata
24      864256s     894975s     30720s                   cam_vpu3               msftdata
25      894976s     927743s     32768s                   gz1                    msftdata
26      927744s     960511s     32768s                   gz2                    msftdata
27      960512s     1091583s    131072s                  nvram                  msftdata
28      1091584s    1093631s    2048s                    lk                     msftdata
29      1093632s    1095679s    2048s                    lk2                    msftdata
30      1095680s    1161215s    65536s                   boot                   msftdata
31      1161216s    1177599s    16384s                   logo                   msftdata
32      1177600s    1193983s    16384s                   dtbo                   msftdata
33      1193984s    1204223s    10240s                   tee1                   msftdata
34      1204224s    1228799s    24576s                   tee2                   msftdata
35      1228800s    2981887s    1753088s    ext2         vendor                 msftdata
36      2981888s    9273343s    6291456s    ext2         system                 msftdata
37      9273344s    10158079s   884736s     ext4         cache                  msftdata
44      10158080s   126779327s  116621248s               userdata               msftdata
38      126779328s  126844863s  65536s                   EMPTY_RECOVERY_BOOT_2  msftdata
41      126844864s  126910399s  65536s                   EMPTY_NORMAL_BOOT_3    msftdata
42      126910400s  126975935s  65536s                   EMPTY_NORMAL_BOOT_4    msftdata
43      126976000s  244163436s  117187437s               linux                  msftdata
39      244164544s  244252607s  88064s                   otp                    msftdata
40      244252608s  244285375s  32768s                   flashinfo              msftdata

Now, in order to make the smaller userdata partition decrypt correctly, you'll need to modify the size inside the metadata partition. Run this on the Cosmo:
dd bs=512 count=32 if=/dev/block/by-name/metadata of=/tmp/meta.bin

Use adb pull /tmp/meta.bin to pull the metadata partition out and open it in a hex editor. The file will begin as follows...
C4 B1 B5 D0 01 00 03 00 30 09 00 00 00 00 00 00
10 00 00 00 01 00 00 00 C0 A7 F2 0D 00 00 00 00
                        ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^

The eight bytes highlighted above, C0 A7 F2 0D 00 00 00 00, are what you need to change - these must match the little-endian encoding of the userdata size. For my size of 116621248, these are: C0 7F F3 06 00 00 00 00. Replace these and save the file. Then, use adb push meta.bin /tmp/ to send it back to the Cosmo, and run this on it:
dd if=/tmp/meta.bin of=/dev/block/by-name/metadata

You can now exit the shell and reboot your Cosmo. You should receive the bootloader menu and all your Android data should be there.
Go to the top of the page
+Quote Post
post Jan 18 2020, 10:33 AM
Post #2

Group: Members
Posts: 4
Joined: 30-December 19
Member No.: 862,418

why not just make an adb backup? if one is rooted there are even more options for backups.
well, I haven't got an update, nor do I find anything on their support page. Maybe they provided it to you first because of your genius skills ;-)
EDIT: got it, too. my fw blocked it
Go to the top of the page
+Quote Post
post Feb 15 2020, 06:34 AM
Post #3

Group: Members
Posts: 19
Joined: 29-October 18
Member No.: 835,812

Wow! Great work!
Any disadvantages to expect? Does OTA update will perform in the future? What's about making a full backup image of data and metadata partition via adb, reformat the Cosmo and flashing back the backup? Or need it a pre-rooted device to backup or decrypt the data?

Thank you.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 22nd February 2020 - 02:55 AM