[Galaxy Ace II Android Development] ChronoMonochrome:
Dual Boot

Hi everybody!

Some time ago I've started implementing dual boot support to this kernel, and recently finished with its first version. Although implementation is similar to this, it isn't same. Unfortunately, my oritinal idea with using image files on external sdcard instead of partitions has failed. Following method allows to install second ROM on the phone using internal sdcard.

First of all, I'm not responsible if you somehow bricked your phone using this manual, do it on your own risk. Secondly, this feature is experimental, there are some possible combinations that won't allow boot one or both ROMs.

Some technical information

I've modified CWM ReParted installer to repart internal sdcard so that there're two more partitions for a second ROM. /dev/block/mmcblk0p9 (orig. HIDDEN) used as /system, and /dev/block/mmcblk0p11 (Fota on stock) as /data (for second ROM). Obviously, stock won't boot with this. However, second ROM also can be installed on external sdcard, but this is UNTESTED by me. In this case you don't need to flash this modified ReParted installer, but you should repart your external sdcard manually. Also you should specify needed partitions in fstab (read below).

Limitations

As was already mentioned, you can't use stock as main ROM, if you are intending to repart your internal sdcard. Moreover, also not possible to use CM12.1 along with CM11, because CM11's ramdisk doesn't have some modifications needed to use SELinux(using build R2.22.6 with selinux on CM11 will cause bootloop).

Now about sizes of partitions, after repartition:

cache - 10000kb, both system partitions - 620000 kb, data (/dev/block/mmcblk0p5) - 1246465 kb and /dev/block/mmcblk0p11 - 1246566 kb, /sdcard - 100000kb.

Installation

Disclaimer!

This manual haven't been updated since a long time ago, proceed with the care and only if you are sure what you do!

1) manually create folders /ramdisk/ROM/data and /ramdisk/ROM/system. These are mount points for non-primary ROM.

2) modify /ramdisk/fstab like so:

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK
# Data partition must be located at the bottom for supporting device encryption

#<src> <mnt_point> <type> <mnt_flags and options>
/dev/block/mmcblk0p3 /system ext4 ro,noatime,errors=panic wait
/dev/block/mmcblk0p2 /modemfs ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p4 /cache ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p7 /efs ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p9 /ramdisk/ROM/system ext4 noatime wait
/dev/block/mmcblk0p11 /ramdisk/ROM/data ext4 noatime wait
/dev/block/mmcblk0p5 /data ext4 noatime,nosuid,nodev,discard,noauto_da_alloc,errors=panic wait,check,encryptable=/efs/metadata

# Vold managed volumes
/devices/sdi2/mmc_host/mmc0/mmc0 auto auto defaults voldmanaged=sdcard0:8,nonremovable,noemulatedsd
/devices/sdi0/mmc_host/mmc1/mmc1 auto auto defaults voldmanaged=sdcard1:auto

# Recovery
/dev/block/mmcblk0p15 /boot emmc defaults recoveryonly

(you should add lines with /dev/block/mmcblk0p9 and /dev/block/mmcblk0p11, appropriately specifying the file system - ext4 or f2fs)

Now copy this file to /ramdisk/fstab1 and modify like that:

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK
# Data partition must be located at the bottom for supporting device encryption

#<src> <mnt_point> <type> <mnt_flags and options>
/dev/block/mmcblk0p9 /system ext4 ro,noatime,errors=panic wait
/dev/block/mmcblk0p2 /modemfs ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p4 /cache ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p7 /efs ext4 noatime,nosuid,nodev,errors=panic wait,check
/dev/block/mmcblk0p3 /ramdisk/ROM/system ext4 noatime wait
/dev/block/mmcblk0p5 /ramdisk/ROM/data ext4 noatime wait
/dev/block/mmcblk0p11 /data ext4 noatime,nosuid,nodev,discard,noauto_da_alloc,errors=panic wait,check,encryptable=/efs/metadata

# Vold managed volumes
/devices/sdi2/mmc_host/mmc0/mmc0 auto auto defaults voldmanaged=sdcard0:8,nonremovable,noemulatedsd
/devices/sdi0/mmc_host/mmc1/mmc1 auto auto defaults voldmanaged=sdcard1:auto

# Recovery
/dev/block/mmcblk0p15 /boot emmc defaults recoveryonly

(just change partitions number so, that /dev/block/mmcblk0p9 mounts to /system, and /dev/block/mmcblk0p11 - /data)

3) now create script /ramdisk/switch.sh with following content:

#!/system/xbin/bash

mv /ramdisk/fstab /ramdisk/fstab2
mv /ramdisk/fstab1 /ramdisk/fstab
mv /ramdisk/fstab2 /ramdisk/fstab1
mv /ramdisk/boot.cpio.gz /ramdisk/boot.cpio.gz2
mv /ramdisk/boot.cpio.gz1 /ramdisk/boot.cpio.gz
mv /ramdisk/boot.cpio.gz2 /ramdisk/boot.cpio.gz1

Give it 755 permissions.

3) before you installed second ROM, extract appropriate ramdisk from kernel installer for it (for instance, for CM11 use osfiles/4.4.x/4.4.x.cpio.gz) instead, choose the appropriate ramdisk file from https://github.com/ChronoMonochrome/android_build_chrono_kernel/tree/master/osfiles and put it in /ramdisk/boot.cpio.gz1

4) now time to reboot to recovery, first install this recovery(philz 6): http://xda.mister-freeze.eu/XDA-files/ChronoMonochrome/DualBoot/philz.cpio.gz

You have to put it in /ramdisk/recovery.cpio.gz (backup your previous recovery if needed) and reboot to recovery. This is needed to allow recovery recognize our custom partitions, when booted to second ROM. Furthermore, it also will now recognize partitions of second ROM.

5) now backup your ROM and data on /sdcard. Just take it as usual repartition, that you do by method, described in CWM ReParted topic.

Then flash installer to repart your internal sdcard: http://xda.mister-freeze.eu/XDA-files/ChronoMonochrome/DualBoot/CWM_ReParted_DualBoot.zip

It'll take some time. Don't pay attention on any messages printed in recovery. Partitions /cache, /data and /system will be formatted to ext4 automatically, you have only format /sdcard as vfat.

5) you can restore your ROM now.

6) connect phone to the PC via adb, and use script above to swap fstab and ramdisk:

/ramdisk/switch.sh

7) reboot to recovery. Firstly make sure that fstab has been swapped correctly, mount /system and type

mount | grep "/system"

to make sure that /dev/block/mmcblk0p9 mounted to it.

8) if so, you can restore any CWM backup that you did before, to install second ROM(use custom restore and don't restore /boot partition). If you didn't any, you should manually edit updater_script, replacing /dev/block/mmcblk0p3 with /dev/block/mmcblk0p9, wherever it used (I haven't tested it too).

9) finally, you can boot to second ROM. Use /ramdisk/switch.sh again to reboot to another ROM.

How to remove second ROM and use usual, non-dualboot partition scheme?

Just flash CWM ReParted zip from its topic or flash stock with pit file via odin.

This is still work in progress, and there is remained some work to do, such as make kernel installer aware about our modifications to fstab (otherwise, any kernel installation will override it) or write simple app to make switching between ROM easier.