Right now, we will not touch any partition map.

This is because it may break devices.

Some (all?) android devices keep a small bit of their internal storage aside to put secondary bootloaders in.

When the storage is cleared, or their bootloaders stored therein are corrupt, many devices will boot to a proprietary download mode. Follows a random picking of links related.

It may be possible to recover, but this is highly device-dependent…​ and spooky.

Here’s an example guide from a user that re-partitions their device:


Generating a partitions listing

By adding this to local.nix, build an initramfs for your device and boot it.

{
  mobile.boot.stage-1.extraUtils = with pkgs; [
    gptfdisk
  ];
}

Run this command:

adb shell "echo p | gdisk /dev/mmcblk0" > devices/$DEVICE/partitions_$SIZE$UNIT.gdisk

Where:

  • $DEVICE is the device name

  • $SIZE is the size un $UNIT

  • $UNIT is GB, as in GigaBytes

This will dump everything gdisk knows about the partition scheme. Saving it raw will allow future tools to re-use the data as dumped to create a better metadata set. It is okay if you replace the Disk identifier (GUID) with a string of zeroes. (It is unknown if it is truly unique across similar devices.)

The storage size is included in the filename as some devices (most?) have different variants differing only in their storage size.