Skip to content
  • Michael Baudino's avatar
    feat(partitions): rewrite S11share for readability · af952374
    Michael Baudino authored and Bkg2k's avatar Bkg2k committed
    This commit started as an attempt to support logical partitions when
    creating SHARE and OVERLAY partitions in S11share.
    
    The rationale behind it was that NOOBS does not install OSs in a primary
    partition (since it supports installing many OSs at once), but rather
    creates an extended partition and then one logical partition inside it
    per installed OS (this setup allows NOOBS to create more than 4
    partitions, and thus to install as many OSs as they like on one disk).
    
    Unfortunately, our convention is that SHARE should be the partition
    immediately following the main one (the one mounted as /boot) and
    OVERLAY should be the partition immediately following SHARE. Which was
    an issue in the following scenario, occuring when installing Recalbox
    via NOOBS (when it only creates the root partition):
    1. NOOBS creates the following partitions (logical partitions are
    always numbered 5+, 1-4 being reserved for primary/extended partitions):
      * `/dev/mmcblk0p1` → RECOVERY (NOOBS recovery)
      * `/dev/mmcblk0p2` → extended partition
      * `/dev/mmcblk0p5` → SETTINGS (NOOBS persistence storage)
      * `/dev/mmcblk0p6` → ROOT (Recalbox main partition, mounted on /boot)
    2. on first boot, `S11share` checks if SHARE exists as `/dev/mmcblk0p7`
    but since it does not, it will attempt to create it
    3. `S11share` thus creates missing partitions, but as *primary*
    partitions, hence SHARE is numbered `/dev/mmcblk0p3` and OVERLAY is
    `/dev/mmcblk0p4`
    4. after reboot, `S11share` tries again to detect SHARE as
    `/dev/mmcblk0p7`, but it still does not exist, thus it will attempt to
    create it
    5. `S11share` fails at creating more *primary* partitions, since there
    are already 4, and reboots
    6. infinite loop 😭
    
    So this commit changes `S11share` behaviour to detect if Recalbox boot
    partition is a logical partition. If so, it will create SHARE and
    OVERLAY as logical partitions too (resp. numbered `/dev/mmcblk0p7` and
    `/dev/mmcblk0p8` as expected upon next reboot).
    
    In order to perform this basic change, I had to understand most of what
    `S11share` was doing and it was cryptic, to say the least. So I ended up
    rewriting a good chunk of `S11share`, as well as related scripts
    `recalbox-part.sh` and `recalbox-mount.sh`, hopefully to achieve a
    higher readability (more explicitely named variables, code split in
    functions, etc…).
    
    In the end, we had to make NOOBS create all partitions for us, so this
    commit is kinda useless, but at least, we now have more readable
    `S11share`, `recalbox-share.sh` and `recalbox-mount.sh` ¯\_(ツ)_/¯ (and
    it will support creating SHARE and OVERLAY partitions as logical
    partitions if it ever happens to be required)
    af952374