MultiROM for the Fairphone 1

MultiROM is a system that makes possible to add several (Linux based) operating systems to your mobile phone (without MultiROM you do not add an operating system, you replace it; in order to install a new operating system you must remove the one already installed). And now it is available for the Fairphone 1 :wink:

Unfortunately, this port of MultiROM for the Fairphone 1 is compatible ONLY with the Fairphone 1 with the original storage layout. Do NOT use it on a Fairphone 1 with the unified storage layout, no matter if it is a Fairphone 1 or a Fairphone 1 (U).

Note, however, that, of the partitions provided by the original storage layout, MultiROM can not use the 13 GiB partition (the large one, the internal SD card, the partition where photos, music and general files are stored), only the 1 GiB partition (the small one, the internal memory, the partition where applications are stored). The free space in that partition is usually not enough to add other operating systems, so you should have an external SD card in your Fairphone 1 in order to use MultiROM (MultiROM also supports USB drives, but their use is less practical, as if an operating system is stored in a USB drive that USB drive must be continuously connected while the operating system is used).

The size of the SD card depends on how many operating systems you want to install and the space available for each one; you can tweak it to your liking, but by default MultiROM requires around 2 GiB for each operating system. Also, the SD card should be ā€œfastā€ (otherwise, working with the operating systems installed on it could be frustrating); in my experience, a class 10 SD card (45MiB/s read, 10 MiB/s write) is enough (albeit slightly slower than the internal memory nevertheless).

Build and install instructions

MultiROM is composed by three elements: a customized version of the Team Win Recovery Project (TWRP) recovery, which is used to install the different operating systems; a MultiROM bootloader, which is the first application run when the device boots and is used to select the operating system to use; and a custom boot image, which stores the kernel of the main operating system, with kexec-hardboot, which is an addition to the Linux kernel that MultiROM needs to perform its magic (when a device boots it always loads the Linux kernel of the main operating system installed in the device; kexec-hardboot makes possible to load a different Linux kernel, thus making possible to start a different operating system).

The custom boot image with kexec-hardboot would not be needed if all the additional operating systems were the same as the main operating system installed in the phone (although the applications installed on them and their data could be totally different). For example, the main operating system could be a system without Google Applications, and an additional operating system could be equal to the main operating system but with the Google Applications installed on it. Or the main operating system could be used for your personal life while an additional operating system could be used only for work-related tasks.

However, if any of the additional operating systems is different from the main operating system then the custom boot image with kexec-hardboot is required. Note that it is required not only in cases like the main operating system being an official Fairphone 1 operating system and the additional operating system being an unofficial CyanogenMod operating system, but also if different versions of the same operating system are being used (for example, if the main operating system is the official Android 4.2 version for the Fairphone 1 and an additional operating system is the official Android 4.4 version for the Fairphone 1).

Unfortunately, if the main operating system is the official Android 4.2 version for the Fairphone 1 (and I assume that it will be), replacing its boot image with the custom boot image has two problems. First, alarms will not work when the device is powered off. And second, although the phone can be charged when it is powered off, the screen will show no progress of the charge and, moreover, switching it off will not be possible.

No matter whether the custom boot image with kexec-hardboot is used or not please note that the operating systems are not really isolated one from each other. Although each operating system uses its own cache, data and system partitions, the rest of partitions (including the external SD card and the internal 13 GiB partition where photos, music and general files are stored) are shared between all the operating systems. That is, even if the operating systems can be different and different applications can be installed in each of them without affecting the others, an application in one operating system could store its data in the exact same place as a different application in another operating system (for example, the photos taken with the camera application of the main operating system could be stored in the same place as the photos taken with the camera application of an additional operating system).

Depending on the behavior of the applications involved and how you expect them to work, the sharing of data could be irrelevant, a minor nuisance or a major problem (for example, if data written by an application when running in an operating system is later overwritten when running another application in a different operating system). But the problem is not limited only to applications; as the Fairphone 1 is a MediaTek device, some MediaTek-specific partitions are used by the operating system itself. The components of the operating system that use those partitions are proprietary software, and their source code is not available. Therefore, I do not know if sharing the partitions between different operating systems is perfectly fine or if it could have terrible consequences for your phone; when using MultiROM on the Fairphone 1 I have not found any problem related to the sharing, but without the source code of the elements that use those partitions it is impossible to tell if it could cause a major poblem or not.

If, despite all this, you still want to try MultiROM in your Fairphone 1, keep reading to know how to build and install it.

Building the custom TWRP recovery is almost the same as building the standard TWRP recovery, except for having to add some MultiROM repositories to the standard ones. The MultiROM bootloader is also built using the Android build system and the same repositories as the custom TWRP recovery. They also support building a special package to install the MultiROM bootloader (and also another one to uninstall it).

On the other hand, creating the custom boot image with kexec-hardboot is, for the most part, a totally separate process. Therefore, there are two sets of build instructions, one for the custom TWRP recovery and the MultiROM installer/uninstaller, and another one for the custom boot image.

In any case, please note that I am publishing these instructions and the different MultiROM elements in the hope that they will be useful, but WITHOUT ANY WARRANTY. I have reviewed the instructions several times, and I think that I have not missed anything, but I could be wrong. In the same way, I have built the different MultiROM elements and used them myself without problems, but if there is any bug or forbidden use that I am not aware of (or I have forgotten to mention) that damages your phone, the data in your phone or whateverā€¦ I am really sorry! But I am not buying you a new Fairphone :stuck_out_tongue:

How to build the custom TWRP recovery and the MultiROM installer/uninstaller

These instructions are a quick reference of the needed steps in a GNU/Linux system. Please refer to the official Android documentation or any of the guides available on the Internet about building Android for further information.

First of all, create a directory to download all the source code and build it. For example, /home/$USER/MultiROM/. Now open a terminal in that directory. All the following commands are expected to be executed in the MultiROM directory.

Get repo, which is the command used in Android to manage the repositories with the source code:

curl https://storage.googleapis.com/git-repo-downloads/repo > repo

And make it executable:

chmod a+x repo

Now initialize the TWRP repositories. Instead of using the full set of OmniROM (the parent project of TWRP, so to speak) repositories you can use a reduced set that contains only those needed to build TWRP (as explained by Dees_Troy, the lead developer of TWRP, in his TWRP compilation guide).

./repo init -u https://github.com/lj50036/platform_manifest_twrp_omni -b twrp-4.4

If you have never used git before that command will fail. You can ignore the failure and continue with the next step (at least, if you want to download the repositories just to build the recovery and MultiROM and you do not intend to develop anything), or you can configure your name and email address. Do not worry, unless you send any change to a public server it will not be used anywhere out of your computer. Set your name and email address as explained in the failure message (that is, executing git config --global user.email "you@example.com" and git config --global user.name ā€œYour Nameā€) and then run again the same ./repo init command as before.

Once repo was initialized, create the file /home/$USER/MultiROM/.repo/local_manifests/multirom.xml and add to it the following contents so repo knows where to get the sources for MultiROM (this will also replace the sources of the original TWRP recovery with the sources of a custom TWRP recovery provided by MultiROM). For now the sources are not got from the official MultiROM repositories, but from my personal copy instead, as I had to modify MultiROM to add support for the Fairphone 1; I sent the changes to the MultiROM author, so in the future it would be possible to use the official repositories too if the changes are included in them:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
    <remote name="multirom" fetch="https://gitlab.com/danxuliu/" />

    <remove-project name="android_bootable_recovery"/>

    <project name="Team-Win-Recovery-Project" path="bootable/recovery" remote="multirom" revision="android-6.0-fp1" />
    <project name="multirom" path="system/extras/multirom" remote="multirom" revision="master-fp1" />
    <project name="libbootimg" path="system/extras/libbootimg" remote="multirom" revision="master-fp1" />
</manifest>

In the same way, create the file /home/$USER/MultiROM/.repo/local_manifests/fairphone_fp1.xml and add to it the following contents so repo knows where to get the sources for the Fairphone 1:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
    <remote name="fairphone" fetch="https://gitlab.com/danxuliu/" />

    <project name="android_device_fairphone_fp1.git" path="device/fairphone/fp1" remote="fairphone" revision="android-4.4" />
    <project name="android_kernel_fairphone_fp1.git" path="kernel/fairphone/fp1" remote="fairphone" revision="mediatek-mt6589-3.4" />
</manifest>

And now tell repo to download all the needed repositories. This will take time and you will need around 14 GBs of space in your hard disk:

./repo sync --current-branch --fetch-submodules

Now that you have the code you can start the build process itself.

First, prepare the build environment.

. build/envsetup.sh

Then, state that you want to build MultiROM for the Fairphone 1, engineering variant (other variants, like the user variant, user, should work, but I have not tested them):

lunch multirom_fp1-eng

Now, build the recovery image. This will take several minutes or even hours, depending on your computer. It will also require around 5 GBs of additional space in your hard disk. The -j4 parameter tells make how many files to build in parallel; it should be set to the number of cores of your CPU (in this example, a quad-core CPU):

make -j4 recoveryimage

Finally, build MultiROM installer and MultiROM uninstaller (which automatically build the MultiROM bootloader), and unpackbootimg (which will be used later to build the custom boot image). This will be much faster and it will require almost no extra space:

make -j4 multirom_zip multirom_uninstaller unpackbootimg

How to install the custom TWRP recovery

Although not strictly needed, the instructions to build the custom boot image are written assuming that you have already installed the custom TWRP recovery. Therefore, we will see how to do that first, and then go back to building the custom boot image.

Remember that the different MultiROM elements are ONLY for the Fairphone 1 with the original storage layout. Do NOT install them on a Fairphone 1 with the unified storage layout, no matter if it is a Fairphone 1 or a Fairphone 1 (U).

The custom TWRP recovery is installed exactly like the normal TWRP recovery. Therefore, please refer to the instructions for the normal TWRP recovery. You just need to take into account that the path /home/$USER/TWRP/ in those instructions is the equivalent to /home/$USER/MultiROM/ here.

How to build the custom boot image

These instructions assume that the current operating system in your device is an official Android 4.2 version from Fairphone (up to the 1.8.7 release, Kola Nut). The resulting boot image is not valid if the device uses a different main operating system (like the official Android 4.4 version from Fairphone), and it may not be valid on a newer release of the official Android 4.2 version from Fairphone (although, at the time of this writing, the 1.8.7 release is the latest one available). It is not valid either for a Fairphone 1 with the unified storage layout... but I think that you knew that already :P

These instructions also assume that you have already built and installed the custom TWRP recovery. Even if building the custom boot image is a separate process, it uses anyway some elements provided by the TWRP repositories, and when interacting with the phone these instructions assume that it was booted in the custom TWRP recovery. Like the previous instructions, these are intended for a GNU/Linux system.

First of all, create a directory to download the source code of the kernel, build it, and then tweak the boot image of the current operating system installed in your phone. For example, /home/$USER/fp1-boot-image/. Now open a terminal in that directory. All the following commands are expected to be executed in the fp1-boot-image directory.

Now, download the source code of the Fairphone 1 kernel with support for kexec-hardboot:

git clone --branch mediatek-mt6589-3.4-kexec-hardboot https://gitlab.com/danxuliu/android_kernel_fairphone_fp1.git

To build the kernel you need a cross compiler (a compiler that builds something that will run on a different platform from the platform of the machine it was built on). This is why you need the repositories for the TWRP recovery; in order to build the custom TWRP recovery a cross compiler is also needed, so it is included in its repositories, and that is the one that you will use here too. To do that, you only need to add to the PATH environment variable (which defines the paths were commands are looked for in the command line) the directory where the cross compiler is (keep reading to see how to do that).

Once the rest of the commands know where to find the cross compiler (if it is a different one, remember to replace /home/$USER/MultiROM in the commands below with the base path where you downloaded the TWRP repositories) it is time to perform the build itself. First, a kernel configuration for the Fairphone 1 is created from a template (this defines what features have to be included in the kernel when built), and then, the build of the kernel is performed. Finally, the kernel modules are all put in the same directory to easily copy them later to the device. Building the kernel is the slowest step of all them, taking several minutes. It will also require around 1.4 GiB of additional space in your hard disk:

export PATH=/home/$USER/MultiROM/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/:$PATH
mkdir android_kernel_fairphone_fp1/out
make -j4 -C android_kernel_fairphone_fp1/kernel O=../out/ ARCH=arm CROSS_COMPILE=arm-linux-androideabi- fp1_defconfig
make -j4 -C android_kernel_fairphone_fp1/kernel O=../out/ ARCH=arm CROSS_COMPILE=arm-linux-androideabi-
make -j4 -C android_kernel_fairphone_fp1/kernel O=../out/ ARCH=arm CROSS_COMPILE=arm-linux-androideabi- INSTALL_MOD_PATH=../out/modules/ INSTALL_MOD_STRIP=1 android_modules_install

A boot image for the Fairphone 1 is composed by two elements: a kernel, that you have just built, and a ramdisk. The ramdisk provides init (plus other additional files that it may need), which is the first program that will be run when the device boots. init takes care of starting the rest of the operating system (for example, it mounts the base partitions where the operating system is stored) and, in the case of Android, the behavior of its init command is defined in several .rc files included also in the ramdisk. The ramdisk included in the official Android 4.2 version from Fairphone is not compatible with MultiROM, so you will have to modify (a copy of) that ramdisk to create a custom boot image usable by MultiROM.

To do that it will be needed to interact with the phone; these are the instructions that assume that you booted in the custom TWRP recovery, so if you had not done that yet it is a good moment to do it. Do not worry, I will wait. Ok, now that you have booted your device in the custom TWRP recovery we can continue (yes, if you are just reading the instructions but not following them that part is awkward :stuck_out_tongue: ).

First of all, extract the current boot image of your device to a regular file. The command below says ā€œConnect to the device through ADB and then copy the first 6291456 bytes from the boot partition to a file called fp1-boot.img-original in the internal SD cardā€:

<path to ADB executable>/adb shell dd if=/dev/bootimg of=/internal_sd/fp1-boot.img-original ibs=1024 count=6144

The ibs=1024 count=6144 part says ā€œread 6144 blocks of 1024 bytes eachā€, which makes 6291456 bytes, the size of the boot partition. Those options are not needed when the phone was booted in the custom TWRP recovery (or any other system using a fixed kernel), but are a must if the phone was booted in the official Fairphone 1 operating system due to the bug in its kernel described in the normal TWRP article. So I included them just in case you, despite all my efforts, did not listen to me about booting in the custom TWRP recovery :stuck_out_tongue:

Once the current boot image was extracted copy the resulting file to your computer (adb pull copies the files to the directory that it is being executed on, so the file will end in /home/$USER/fp1-boot-image/fp1-boot.img-original):

<path to ADB executable>/adb pull -p /internal_sd/fp1-boot.img-original

Now that it is in your computer you can unpack it to get its ramdisk (this will also unpack its kernel and other elements, all prefixed by fp1-boot.img-original, but you can remove them if you like, as they will not be used for anything):

/home/$USER/MultiROM/out/host/linux-x86/bin/unpackbootimg -i fp1-boot.img-original
mv fp1-boot.img-original-ramdisk.gz ramdisk.img-original

A standard Linux ramdisk is just a set of regular files compressed in a single file, similar to a tar.gz or a .zip. However, in MediaTek MT6589 devices (like the Fairphone 1), the ramdisk includes a MediaTek-specific extra header of 512 bytes. That header must be removed:

dd if=ramdisk.img-original of=ramdisk.img-original-headerless ibs=512 skip=1

Removing the header converted the MediaTek ramdisk to a standard Linux ramdisk, thus making possible to decompress it in the standard way:

mkdir ramdisk
cd ramdisk
cat ../ramdisk.img-original-headerless | gzip -d | cpio -i

After decompressing it several files and directories will have been created in /home/$USER/fp1-boot-image/ramdisk. As mentioned above, the ramdisk takes care of mounting the base partitions needed by the operating system to run. MultiROM requires the ramdisk to perform that mounting in a specific (although standard) way to be able to perform its magic of booting on a different operating system, and as you probably guess by nowā€¦ the MediaTek ramdisk does not mount the partitions in the expected way. Thus open /home/$USER/fp1-boot-image/ramdisk/init.rc in your favorite text editor and modify it as follows:

  • Remove the on fs_property:ro.mount.fs=EXT4 block (that is, from the on fs_property:ro.mount.fs=EXT4 line, included, to the on fs_property:ro.mount.fs=UBIFS line, not included).
  • Add the following block just below on fs: ``` write /proc/bootprof "INIT:eMMC:Mount_START"
    mount_all /fstab.mt6589
    
    mkdir /system/secro 0600 system system
    # RIL need to do this before the folder /system changed to read only
    chown radio system /system/etc/ril
    chmod 0770 /system/etc/ril
    chmod 0444 /system/etc/ril/oper.lis
    # Wifi thermal need to chmod before system is changed to read only
    chown root system /system/etc/throttle.sh
    chmod 0750 /system/etc/throttle.sh
    
    mount ext4 /dev/block/mmcblk0p5 /system noatime ro remount wait
    
    mount ext4 /emmc@sec_ro /system/secro ro wait
    
    write /proc/bootprof "INIT:eMMC:Mount_END"
    
    You may have noticed that it is basically a reduced version of what you have just removed. The part where some permissions are changed was kept (although that should have been done during the installation of the operating system instead of at each boot, but that is a different matter), but not the part where the file systems are checked and, if needed, repaired. MultiROM mounts the base partitions (<em>cache</em>, <em>data</em> and <em>system</em>) before handing over control to <em>init</em> (when MultiROM is installed its bootloader becomes the first program to be run instead of the original <em>init</em>), so it is no longer possible to check and repair them before mounting.
    
    Unfortunately, MultiROM does not explicitly check and repair them either. However, if MultiROM tried to mount a corrupt file system it should fail; that would prevent the system from booting up, but at least it will not corrupt the file system even more. In that situation the problem could be solved from the recovery, as TWRP provides an option to repair damaged file systems (although in a rather obscure place, if you ask me: <em>Wipe->Advanced Wipe->Fs options</em>), and also a command line (<em>Advanced->Terminal Command</em>) from which you could manually run <em>e2fsck</em>. However, this is all untested theory; in practice I have never found that problem.</li>
    </ul>
    
    Now delete <em>/home/$USER/fp1-boot-image/ramdisk/fstab</em>.
    
    And finally create <em>/home/$USER/fp1-boot-image/ramdisk/fstab.mt6589</em> with the following contents:
    

    /dev/block/mmcblk0p6 /cache ext4 nosuid,nodev,noatime,discard wait,check,nonremovable
    /dev/block/mmcblk0p7 /data ext4 nosuid,nodev,noatime,discard wait,check,nonremovable
    /dev/block/mmcblk0p5 /system ext4 noatime,discard wait,check,nonremovable

    
    Once you have done all that go back to the terminal to generate a new ramdisk (I assume that you are using the same terminal in which you executed the previous commands, and thus its current directory is <em>/home/$USER/fp1-boot-image/ramdisk</em>):
    

    find . | cpio -o -H newc | gzip > ā€¦/ramdisk.img-headerless
    cd ā€¦

    
    Finally, the kernel with support for kexec-hardboot that you built before and the ramdisk with the tweaked mounting that you have just generated have to be assembled in the final boot image. Neither the kernel nor the ramdisk includes the special MediaTek header, so the boot image can not be created by directly calling the standard <em>mkbootimg</em> from Android; instead, you must use the MediaTek wrapper that I developed for the Fairphone 1:
    

    cp android_kernel_fairphone_fp1/out/arch/arm/boot/zImage kernel-headerless
    /home/$USER/MultiROM/device/fairphone/fp1/mkbootimg_mtk.py --kernel kernel-headerless --ramdisk ramdisk.img-headerless --wrapped_mkbootimg /home/$USER/MultiROM/out/host/linux-x86/bin/mkbootimg --output fp1-boot.img-multirom

    
    Done! :)
    
    
    
    <h2>How to install the custom boot image</h2>
    First of all, do a backup of boot and system. You will need this to easily go back to the state of your operating system before installing the custom boot image, either because you are no longer interested in MultiROM... or because something went wrong when installing it (that should not happen... but just in case ;) ).
    
    Yes, yes, I have said it already, I am very repetitive, you are going to cry if you read it another time, but still: <strong>do NOT install the custom boot image if you are using a different operating system (like the official Android 4.4 version from Fairphone) or if you are using a Fairphone with the unified storage layout</strong>. See? It was not so bad :P
    
    Also, remember than once you have installed the custom boot image, even if you do not install MultiROM, alarms will not work when the device is switched off (so do not switch off your phone at night if you do not want to get late to work), and, while it will be possible to charge the phone when switched off, no progress will be reported and the screen will be always switched on (so do not let your phone to discharge, and charge it always when switched on).
    
    Before installing any boot image it is always better to ensure that it will fit inside the boot partition (and it should when following these instructions, but better safe than sorry). The size of the <em>fp1-boot.img-multirom</em> file must be less than (or equal to) 6291456 bytes. Check that the size of the file is smaller, for example, by running <em>wc -c fp1-boot.img-multirom</em>.
    
    If it has a valid size first copy it to your device. For example, in your internal SD card:
    

    /adb push -p fp1-boot.img-multirom /internal_sd/fp1-boot.img-multirom

    
    And now that it is in your device, copy it to the boot partition (in this case it is not needed to set the amount of bytes to copy; it will stop when it reaches the end of the file):
    

    /adb shell dd if=/internal_sd/fp1-boot.img-multirom of=/dev/bootimg

    
    The installation is not yet complete, though. When the kernel was built some of its features were included in modules instead of in the main kernel file that is part of the boot image, so those modules must be installed too to the appropriate location.
    
    To do that, first enable the write permissions for the <em>system</em> partition in TWRP. It can be done in the <em>Mount</em> entry in the main menu of the custom TWRP recovery, unticking <em>Only mount system read-only</em> and then ticking <em>System</em> in the list of partitions.
    
    Once the <em>system</em> partition is mounted the modules can be copied with the following command:
    

    find android_kernel_fairphone_fp1/out/modules/lib/modules -name ā€œ*.koā€ -execdir /adb push -p {} /system/lib/modules/{} ;

    
    Also ensure that the modules have the appropriate permissions (read-write for root, read for anyone else):
    

    /adb shell chmod 644 /system/lib/modules/*.ko

    
    Remember to tick again <em>Only mount system read-only</em> when all the modules have been copied and their permissions are the right ones (the partition is protected against writting for a good reason ;) ).
    
    Ok, you have finished installing the custom boot image. STOP RIGHT HERE. Before doing anything else, reboot your phone (<em>Reboot</em> entry in the main menu of the custom TWRP recovery, and then <em>System</em>). It should boot normally, into your normal Android system, as MultiROM has not been installed yet. Ensure that before going any further. Seriously, do it. You do not want to accidentally mess the recovery and then find that your main system does not boot either ;)
    
    Once you have checked that your main system still works as expected you can (if you want) delete the boot images copied to your internal SD card and finally install MultiROM.
    
    But before that, a note: you should not update your main operating system while the custom boot image is installed. However, if you do, you will need to create another one based on the newer official boot image; do NOT install again the previous one (well, in practice it will probably be valid anyway as there are typically not a lot of changes in the ramdisk files between releases, but just in case). You will have to re-install MultiROM too for its bootloader to be injected in the newer custom boot image.
    
    
    
    <h2>How to install MultiROM</h2>
    Installing MultiROM is the easiest part of this process. Just copy the installer package to the phone, tell TWRP where to find it and that is it. There is just one importante consideration: you must install it after installing the custom boot image, as part of MultiROM is installed to the boot partition.
    
    So, if you have already installed the custom boot image, copy the MultiROM installer (<em>/home/$USER/MultiROM/out/target/product/fp1/multirom.zip</em>) to your phone. It does not matter how you do it; if you have booted to TWRP you can copy it with the following command:
    
    

    /adb push -p /home/$USER/MultiROM/out/target/product/fp1/multirom.zip /internal_sd/multirom.zip

    
    Now, in your phone, tap <em>Install</em> in the main menu of the custom TWRP recovery, select <em>multirom.zip</em> and then at the bottom of the screen swipe to install. The installer copies the needed files to <em>/data/media/0/multirom</em> and also modifies the boot partition as needed for the MultiROM bootloader to be the first application to run when the phone boots. If you now reboot to system you should see the MultiROM bootloader; let it boot to your main operating system (<em>Internal</em>, in MultiROM terminology) to ensure that everything works as expected. Then you can reboot to recovery again to add an additional operating system.
3 Likes

(This should have been part of the original post, but it was over the character limit)

Using MultiROM

The custom TWRP recovery is (almost) the same as the normal TWRP recovery, but for some fixes not included yet in the custom one, a SD card partitioner not included due to space constraints and a different visual appearance. Therefore, same considerations/problems as with the normal TWRP recovery apply: NEVER install an official Fairphone 1 update through TWRP, and NEVER update your system through the Fairphone Updater app when the recovery installed in the recovery partition is TWRP.

While I said that MultiROM is composed by three elements that is not exactly true. There is a fourth element, MultiROM Manager, which is an Android app to manage MultiROM. However, I have not tested it, so I strongly recommend you to use only the custom TWRP recovery for MultiROM management on the Fairphone 1.

Adding an additional operating system (ROM, in MultiROM terminology) and performing any other MultiROM management task is done through the MultiROM entry in the main menu of the custom TWRP recovery.

As already explained, ROMs should be added in the external SD card, not in the internal memory. Therefore, after tapping on Add ROM you should select the rather cryptic /dev/block/mmcblk1p1 location.

The main way to add an Android ROM is with its .zip update file. For example, after building Android 5.0 for the Fairphone 1 (or the 4.2, 4.3 and 4.4 versions also available in those same repositories), you just have to copy cm_fp1-ota-<random letters and numbers>.zip to your phone (typically to the internal SD card) and then install it through the MultiROM section of TWRP. You can even skip copying it to your phone and serve it directly through ADB by using the sideload option.

Unfortunately, as stated above, you can not install an official Fairphone 1 update, neither as the main system nor as an additional operating system in the MultiROM section of TWRP. You can, however, install a backup of your main operating system made with TWRP as an additional operating system, even if the main one is an official Fairphone 1 operating system. To do that you must use a backup that includes at least the system partition, and you must ensure that the backups of all the partitions will fit inside the sizes that MultiROM will use for them.

Be very careful if you install it from a backup, though; as it would be a fully working system, including telephony, this may make a mess in the MediaTek-specific partitions and you may end needing to restore your IMEI or things like thatā€¦ I have tested it and, although telephony did not work in the backup, I had no problems in the main operating system (but from being slower to connect to the telephony network after introducing the PIN). However, while researching the behavior of some MediaTek-specific elements I realized how brittle they were and it would not surprise me at all if using an additional operating system installed from a backup wrecked the main operating system. You have been warned :wink: (Ironically, not having support for the telephony system in the Android 5.0 version is in this case a good thing, as it is safe to use).

Besides additional Android operating systems, MultiROM also supports additional generic Linux based operating systems. In this later case they have to be installed through a special package built specifically for MultiROM. It is not ready to be released yet, but I have been working on porting certain Linux based operating system to the Fairphone 1; even if it is just partial support (like the Android 5.0 version), I think that it would be a nice touch, if you know what I mean :wink:

In any case, MultiROM installs each additional operating system on its own subdirectory of the multirom-fp1 directory of the external SD card (as that is the location selected to install the ROM to); the partitions of your main operating system will be left untouched. Moreover, when the multirom-fp1 directory belongs to a partition that uses the FAT file system (like the external SD card), MultiROM will use a disk image for each partition of the additional operating system, so each one will be just a single file (disk images are special files that internally act as a partition, but externally are just regular files, like a spreadsheet or a video).

A word of caution, though: it has happened to me that, when using an additional operating system, it suddenly failed due to being unable to read from the external SD card. Probably one of its disk images got corrupted or something like that, as I simply deleted the disk images, installed the ROM again, and everything went back to normal; yes, I should have investigated instead why it happened and how to fix the problemā€¦ but I did not, so I do not know if the data could be recovered in that situation or not, sorry :stuck_out_tongue: So, if you have something important stored in one of the additional operating systems, always keep a backup of it (which is an advice that could be applied not only to MultiROM, but to any use of a smartphone or computer).

Adding large ROMs

If you intend to add an Android ROM whose .zip is larger than 200 MiB (which is the case for my Android 5.0 version) or a Linux based ROM whose .mrom file is larger than 400 MiB there is a "little" problem: the installation process will fill "all" the RAM memory and the device will reboot (well, it is not exactly all the RAM memory, but the tmpfs file system (which is backed by the RAM memory) mounted on /tmp... but anyway, it will reboot without finishing the installation).

The solution? Trick the custom TWRP recovery to work on disk instead of on RAM memory. When a file system is mounted on a directory the file system is attached to that directory, and the contents of the file system become the contents of the directory; any other previous content in the directory is simply hidden until the file system is unmounted. Mounts can be stacked, so several file systems can be mounted on the same directory, and the contents of the directory will be the contents of the latest file system mounted and not unmounted yet. You can do just that: mount a disk-backed file system on /tmp to hide the original tmpfs; this way files will be created on the disk, lefting the original tmpfs, and therefore the RAM memory, untouched.

For the disk-backed file system a single disk image file stored in the internal or external SD card can be used. Supposing that you want to use the internal SD card and that you have 1 GiB free you can create it through ADB on the custom TWRP recovery with the following command (the name of the file is irrelevant, just ensure that it does not exist before running the command):

<path to ADB executable>/adb shell make_ext4fs -l 1000M /internal_sd/tmp.img

Now that the disk image was created it is simply a matter of mounting it on /tmp:

<path to ADB executable>/adb shell mount -o loop /internal_sd/tmp.img /tmp

Once mounted it will appear too in the MultiROM locations as /dev/block/loop0, but it does not matter; just keep using /dev/block/mmcblk1p1 as explained above.

When you have finished using the disk image (that is, when the installation of the additional operating system has finished) you can unmount and remove it to free the space from your SD card:

<path to ADB executable>/adb shell unmount /tmp && rm /internal_sd/tmp.img

Uninstalling MultiROM and the custom boot image

In the same way that installing MultiROM had to be done after installing the custom boot image, uninstalling MultiROM must be done before uninstalling the custom boot image.

To uninstall MultiROM you have to install its uninstaller. I know, it sounds odd :slight_smile: It is the same process as with the installer package, but this time with the uninstaller package. First, copy the MultiROM uninstaller (/home/$USER/MultiROM/out/target/product/fp1/multirom_uninstaller.zip) to your phone. It does not matter how you do it; if you have booted to TWRP you can copy it with the following command:

<path to ADB executable>/adb push -p /home/$USER/MultiROM/out/target/product/fp1/multirom_uninstaller.zip /internal_sd/multirom_uninstaller.zip

Now, in your phone, tap Install in the main menu of the custom TWRP recovery, select multirom_uninstaller.zip and then at the bottom of the screen swipe to install. The uninstaller removes the MultiROM files from /data/media/0/multirom and also modifies the boot partition to remove the MultiROM bootloader (so now the phone will boot directly in the main operating system). Note, however, that the additional operating systems installed on the multirom-fp1 directory of the external SD card will not be automatically removed; you will have to manually delete the subdirectories of multirom-fp1 (or even the multirom-fp1 directory altogether), or delete the installed ROMs using the custom TWRP recovery before uninstalling MultiROM.

Even if the phone boots directly in the main operating system the boot image is still the custom boot image, and it still has the already explained problems (no alarms and unresponsive charger mode). To restore the original boot image simply go back to the main menu of the custom TWRP recovery and restore the backup of the boot and system partitions you made (because you made it when I told you to, didnā€™t you? :wink: ).

Questions and answers

MultiROM wiki says that devices with a separate internal partition in /sdcard are not supported. Yet you claim that it can be used only with the original storage layout. What is going on here?

Well, the fact is that MultiROM can indeed be used on devices with a separate internal partition in /sdcard. However, MultiROM can not use that partition. Those devices with a separate internal partition in /sdcard usually have a small /data partition, which is the one that uses MultiROM (the internal memory), and most space is reserved for the /sdcard partition (like in the Fairphone 1 with the original storage layout, in which /data has 1 GiB and /sdcard has 13 GiB). Therefore, although MultiROM can be used in the device, an external storage device must be used to store the additional operating systems.

Using an external USB drive would be possible, although not very practical, as it must be connected all the time while the additional operating system is used. The best option is to use an external SD cardā€¦ even if the MultiROM wiki says that they are not supported due to how slow and awful they are. Well, in my experience, a class 10 SD card (45MiB/s read, 10 MiB/s write) works fine; it is not as fast as the internal memory (and it is specially noticeable during the boot of additional operating systems), but it is not the end of the world either :wink:

In conclusion: MultiROM works best on devices with a large /data partition, but it works too on devices with an internal /sdcard partition storing the ROMs on a external SD card, even if there are several things to take into consideration and its use is not as smooth as in the first case.

Would it be possible to isolate all the partitions instead of just cache, data and system?

Isolating the internal 13 GiB partition (where photos, music and general files are stored) would be relatively easy. Adding support for Fairphone 1 with the unified storage layout (and updating the device to use that storage layout) would be enough (and the proper way to use MultiROM, as explained above), because with the unified storage layout there is no internal 13 GiB partition (it is fused with the internal memory, the data partition, which is already isolated).

On the other hand, isolating the external SD card and, more importantly, the MediaTek-specific partitions would require deep changes in MultiROM (and maybe even in the kernels of the operating systems used, specially for the MediaTek-specific partitions, although I have not given it much thought). Another approach would be to still share those partitions, but use the kernels to limit the write access to those partitions only to components known to be safe. Unfortunately, this comes back again to the problem explained in the Android 5.0 article of not having the source code of the MediaTek-specific components, and without that source code it is not possible to ensure that allowing certain component to write to the MediaTek-specific partitions will not cause a major problem (although, again, in my use of MultiROM I have not found any).

After installing an additional operating system I found that I installed it by mistake in the internal memory... but it works! What has happened?

Well, I have never said that you could not install them in the internal memory ;) (and if I did please tell me because it is a leftover from a previous draft :P ). It is indeed possible to install additional operating systems in the internal memory, but you must take into account that then the applications of your main operating system, its data, the additional operating system, its applications and its data will all have to fit in the same partition. A little crowded for just 1 GiB, specially if you take into account that only the base files of an Android system takes around 350 MiB and on the first boot up to 100 MiB of data could be generated.

In any case, if you have enough free space in your internal memory and you install an additional operating system there you may want to know that it will end inside /data/media/0/multirom/roms/ and that, unlike those installed in the external SD card, uninstalling MultiROM will delete the additional operating systems installed in the internal memory.

This article is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. For the MultiROM license please check the source files themselves; those written by me are typically licensed under the GNU General Public License version 3 or later, but in some cases I had to use a different license (for example, in the case of kernel patches they have to be licensed under the GNU General Public License version 2).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.