# 11 eMMC Guide

### Prerequisites <a href="#pre-requisite" id="pre-requisite"></a>

* Full eMMC Backup (boot0/1 and rawnand.bin)
* (Partition Manager) PC
* (Partition Manager) hekate v6.4.0 or later
* (Manual) PC running Linux
* (Manual) GParted, gdisk

### WARNINGS

* Repartitioning, resizing, and flashing your eMMC will destroy your HOS (stock Switch OS) install; you MUST have a backup if you ever intend to use HOS again (this can be achieved with hekate (Tools -> Backup eMMC -> eMMC BOOT0 & BOOT1, eMMC RAW GP)
* We recommend this to advanced users only--the gain is marginal and not worth accidentally nuking your Switch

### Installation (Partition Manager) <a href="#installation" id="installation"></a>

This approach uses hekate's built-in eMMC partition manager, added in hekate v6.4.0. We recommend this solution as it is easy, robust, and officially supported.

1. Follow [installation instructions](https://wiki.switchroot.org/wiki/android/android-11/11-r-setup-guide) up until SD partitioning step (files should be in `switchroot/install` and `switchroot/android`)
2. Adjust `bootloader/android.ini` from installation instructions to include `emmc=1`.
3. Enter hekate's eMMC partition manager by pressing and holding the "Partition SD Card "button (Tools -> Partition SD Card) for 5 seconds
4. Adjust partitions to your liking (we recommend 16GB for Android, though it should be usable with >=8GB)
5. Press Flash Android to flash the files in `switchroot/install/` (the files will be erased after flash)
6. Press "Continue" to reboot into Android recovery

### Installation (Manual) <a href="#installation" id="installation"></a>

This approach does not utilize hekate's built-in eMMC partition manager and is mostly here for legacy documentation and support. We recommend using the above method.

#### eMMC preparation (for Android and Linux alongside HOS on a larger eMMC) <a href="#emmc-preparation-for-android-and-linux-alongside-hos-on-a-larger-emmc" id="emmc-preparation-for-android-and-linux-alongside-hos-on-a-larger-emmc"></a>

1. If you have a new eMMC, install it and write back boot0/1 and the rawnand bin in hekate.
2. Under Linux mount the eMMC with hekate. Deactivate write protect!
3. Check where linux has mounted the eMMC (sdb, sdc ...)
4. Open `gparted` and confirm the resize from the eMMC gpt table.
5. Close gparted.
6. Open Terminal and `sudo gdisk /dev/sdx` (where x is your the device letter)
7. Press x=>s=>20=>v=>w=>y to enlarge the gpt table to 20 entries. (If you also want to do linux on the eMMC you have to enter 24.)
8. Open gparted again.
9. HOS has 11 partitions, Android need 9 partitions we have to create them.
10. Add the 9 partitions and set the file system as deleted.

| Partition             | Name   | Size    |
| --------------------- | ------ | ------- |
| Vendor                | vendor | 1GiB    |
| System                | APP    | 2GiB    |
| Linux Kernel          | LNX    | 32MiB   |
| Recovery (TWRP)       | SOS    | 64MiB   |
| Device Tree Reference | DTB    | 1MiB    |
| Encryption\*          | MDA    | 16MiB   |
| Cache                 | CAC    | 700 MiB |
| Miscellaneous         | MSC    | 3MiB    |
| Userdata              | UDA    | Custom  |

11. If you want to add Linux, add a partition with the label of your choice (e.g.: `SWR-UBU` for Ubuntu Bionic) and 3 dummy partitions with 1mb unformated. In order to have 24 partitions. gdisk cannot create 21 partitions because the sector is filled automatically (multiple of 4) if there are only 21 partitions on the eMMC and not 24 Horizon does not start. The bootloader checks that and Horizon brings up a pink screen.

#### Flashing the eMMC <a href="#flashing-the-emmc" id="flashing-the-emmc"></a>

1. Using `dd` in terminal flash the following (replacing `hekate`'s `Flash Android` step)

**ANDROID 11**

| File            | Label |
| --------------- | ----- |
| `boot.img`      | LNX   |
| `recovery.img`  | SOS   |
| `nx-plat.dtimg` | DTB   |

2. For Linux, merge the install image with `cat l4t.0* > ubuntu.img` and `dd` it to SWR-UBU (replacing `hekate`'s `Flash Linux` step). Refer to [step 3 and 4 here](https://wiki.switchroot.org/wiki/linux/linux-usb-or-emmc-boot#emmc-boot) for more detail.
3. Add the release files (bootfiles, ini, lineage zip, any extra zips)
4. Add `emmc=1` to `bootloader/ini/android.ini`
5. Boot `hekate` -> More Configs -> Switchroot Android 11 while you press VOL +
6. In recovery, flash the lineage zip and any extra zips

**WARNING:** When setting up Android, under no circumstances use the sd card as a memory extension (adopted storage), otherwise it will be formatted. The FAT32 partition will be mounted regardless, so no need.
