[GUIDE][HOWTO] Multi-boot Android systems on Xperia TX

Search This thread

updateing

Senior Member
Aug 25, 2012
489
1,140
Wuhan
Google Pixel C
FIRST OF ALL, we should say thanks to @alvinhochun 's work on porting kexec hardboot patch to Xperia M. His original thread is here: http://forum.xda-developers.com/showthread.php?t=2568151
And @Tasssadar who has ported kexec hardboot patch on MSM chips. Original thread is here: http://forum.xda-developers.com/nexus-4/orig-development/kexec-hardboot-patch-t2472316/post46223952
As for the kernel patch and kexec binary for TX, they are here: http://forum.xda-developers.com/showthread.php?t=2747215

OK let's begin our tour on TX...

0. Disclaimer
This is a rather dangerous hack. I'm not responsible for data loss, broken SD cards, dead internal storage or bricked phones. Try this at your own risk. Proceed only when you know what you are doing.​

1. Requirements
a. ROM with “kexec hardboot” patched kernel. My OmniROM build will do the job. Since Alx31Tse is also using my kernel source for TX, the Carbon builds for TX may be capable of handling this as well. This ROM should be installed into internal storage : just flash it in recovery as usual.​
b. External MicroSD card which is big enough for your ROMs. One ROM takes up ~4GB space.​
c. Some basic knowledge of partitions, device nodes, ramdisk modding(check this thread by letama: http://forum.xda-developers.com/showthread.php?t=2418893).​

2. Partitioning the external sdcard
a. Plan the partitions​

Each ROM need three partitions : system, data and cache. You need at least 1.4GB system + 2GB data + 400MB cache for stock ROMs. The system partition for third-party ROMs can be shrinked to ~900MB. Of course you can set your own data partition size if 2GB does not suit your needs. The space left can be used for storing data just like a normal sdcard.

For example, I'm using a 16GB card and going to install two stock ROMs (9.1.B.1.67 + 9.2.A.0.295). So I have to create at least 6 partitions for them:

1.4GB system for 295
2GB data for 295
400MB cache for 295
1.4GB system for 67
2GB data for 67
400MB cache for 67
There is ~8GB left after all these partitions. This can be used as a normal sdcard. Just create another partition for it.​

b. Go partitioning it!​

Everyone has his own way of doing this. I prefer using a USB card reader and Disk Utility that comes with Ubuntu.

Erase the card and initialize it with GUID Partition Table (GPT). Of course you can use MBR, but I didn't test it. Be careful in the following steps if you choose MBR.

Create the “normal sdcard” partition. In my example, create a 8GB partition here and format it with FAT32. THIS PARTITION SHOULD BE THE FIRST ONE ON THE CARD! Otherwise Android system may not be able to recognize it.

Create the partitions for guest systems. There are no particular order for the partitions. Just make sure you remember their order. DO NOT FORMAT them for now.

In my example:
PART 1: 8GB, FAT32
PART 2: 1.4GB unformatted
PART 3: 2GB unformatted
PART 4: 400MB unformatted
PART 5: 1.4GB unformatted
PART 6: 2GB unformatted
PART 7: 400MB unformatted​

3. Kernel mods for guest systems
For each guest system:
a. Unpack its kernel.​

If you are going to install a full stock ROM, please choose a corresponding kernel with recovery built-in in Android Development section.

If you are going to install a third-party ROM (OmniROM, CM etc) or customized stock ROM (Rockers etc), chances are that their kernels have recovery built-in already and you can proceed.

Now unpack the kernel.

We have zImage(sec0.bin), ramdisk(sec1.bin) now. The rest can be ignored.​

b. Modify the mount entries in fstab (and other files)​

fstab is the file that suggests the real device for the /system, /data and /cache mount points. Modding it will make it possible to mount the partitions other than the ones in internal storage on /system /data and /cache, so that we can separate different systems into different partitions.

Now you have to be clear about “how the partitions on external card will be presented in your phone” (their device nodes). In my example (GPT with 7 partitions):

PART 1: 8GB → /dev/block/mmcblk1p1
PART 2: 1.4GB → /dev/block/mmcblk1p2
PART 3: 2GB → /dev/block/mmcblk1p3
PART 4: 400MB → /dev/block/mmcblk1p4
PART 5: 1.4GB → /dev/block/mmcblk1p5
PART 6: 2GB → /dev/block/mmcblk1p6
PART 7: 400MB → /dev/block/mmcblk1p7

As has been mentioned above, mmcblk1p1 is for normal file storage, p2~p4 is for 295, p5~p7 is for 67.

Files that need modding:
(sec1.bin/sbin/ramdisk.cpio) /fstab, /fstab.qcom, /init.target.rc
(sec1.bin/sbin/ramdisk-recovery.cpio) /fstab, /fstab.qcom, /etc/recovery.fstab, /etc/twrp.fstab

The fstabs are easy to deal with. Just change the block device name for /system /cache and /data to /dev/block/mmcblk1p* accordingly. The init.target.rc has only one line that should be modded. For example,
FOR 9.1.B.1.67 in my example:
ramdisk.cpio/fstab:

/data ext4 /dev/block/mmcblk1p6
/cache ext4 /dev/block/mmcblk1p7
/boot/modem_fs1 raw /dev/block/platform/msm_sdcc.1/by-name/modemst1
/boot/modem_fs2 raw /dev/block/platform/msm_sdcc.1/by-name/modemst2

ramdisk.cpio/fstab.qcom:

/dev/block/mmcblk1p5 /system ext4 ro,barrier=1,discard wait,check
/dev/block/mmcblk1p6 /data ext4 nosuid,nodev,noatime,barrier=1,noauto_da_alloc,discard wait,check,encryptable=footer
/dev/block/mmcblk1p7 /cache ext4 nosuid,nodev,noatime,barrier=1,discard wait,check
/dev/block/platform/msm_sdcc.1/by-name/SDCard /mnt/int_storage ext4 nosuid,nodev,barrier=1,noauto_da_alloc,discard wait,check

ramdisk.cpio/init.target.rc:

(SEARCH FOR /system)

on post-fs
mount ext4 /dev/block/mmcblk1p5 /system ro remount barrier=1

Just do the same for ramdisk-recovery.cpio. For example:

ramdisk-recovery.cpio/etc/recovery.fstab


/boot emmc /dev/block/mmcblk0p4
/system ext4 /dev/block/mmcblk1p5
/cache ext4 /dev/block/mmcblk1p7
/data ext4 /dev/block/mmcblk1p6 length=-16384
/sdcard ext4 /dev/block/mmcblk0p15
/external_sd auto /dev/block/mmcblk1p1 /dev/block/mmcblk1

And replace mmcblk1p5~p7 with p2~p4 then do it all again for 9.2.A.0.295's ramdisk.cpio & ramdisk-recovery.cpio

NOTE: All these fstab and rc files should be rw-r—r-- and owned by root:root. Otherwise the system may fail to boot.

Now repack the ramdisk.cpio, ramdisk-recovery.cpio and then the whole ramdisk.​

4. Installing the guest systems
Take notice of the texts in red. Change them to fit your needs.
a. Preparing the guest systems​
If you are installing full stock ROM (FTF format), you can use Flashtool to dump the system image (Flashtool > Tools > Sin Editor, load system.sin from FTF archive and dump data). Then write the image to the sdcard by “dd if=system.ext4 of=/dev/sdb2“ on the computer.
If you are installing ROMs in ZIP format, you need to modify updater-script and replace all (for 9.1.B.1.67 in my example)
/dev/block/mmcblk0p12 or /dev/block/platform/msm_sdcc.1/by-name/System to /dev/block/mmcblk1p5

/dev/block/mmcblk0p13 or /dev/block/platform/msm_sdcc.1/by-name/Cache to /dev/block/mmcblk1p7

/dev/block/mmcblk0p14 or /dev/block/platform/msm_sdcc.1/by-name/Userdata to /dev/block/mmcblk1p6
And
remove /dev/block/mmcblk0p4 or /dev/block/platform/msm_sdcc.1/by-name/Kernel formatting/writing lines
Then repack the ROM and push it into phone's internal sdcard.​

b. Boot the guest kernel/system​
Remember we have zImage and modded ramdisk for each guest system? adb push them to /data partition. The kexec binary is needed as well. Now you can use the kexec binary(check the beginning of this thread) to boot your guest kernel and then recovery.

For example:

I pushed 295 kernel zImage to /data/boot4.3/zImage-stock, modded ramdisk to /data/boot4.3/initrd-stock, and kexec binary to /data/kexec. Now execute as root:

Code:
        cd /data
        chmod 755 kexec
        busybox sync
        busybox mount -o remount,ro /system
        busybox mount -o remount,ro /cache
        busybox mount -o remount,ro /data
        busybox sync
        ./kexec --load-hardboot [COLOR="Red"]./boot4.3/zImage-stock[/COLOR] –initrd=[COLOR="Red"]./boot4.3/initrd-stock[/COLOR] --mem-min=0x85000000 --command-line="`cat /proc/cmdline`"
        busybox sync
        ./kexec -e # phone reboots and guest kernel (295) starts

NOTE: the guest kernel's cmdline may not be exactly the same as the host one. However, it doesn't matter much. 67 and 295 both boot fine using the same cmdline as OmniROM. Since bootloader will append some parameters to the command line, using guest's sec3 without appending these parameters manually is not a good idea.​

c. Preparing filesystems and installing ROMs in ZIP​
After the phone reboots, press Vol buttons at purple LED to go into recovery. Now you are in the recovery for your guest system (295).

FORMAT (not wipe) /data and /cache there. For ZIP ROMs you need to format /system as well.

Then install the modded ZIP file if needed. You can also flash SuperSU or anything else to this guest system in the recovery (remember to check if there are wrong block device paths in updater-script).

After finishing the installation of one guest system, reboot and you will go into the host ROM. Execute the commands again and specific the next guest system's zImage and ramdisk to boot into the next guest system. Then do the formatting and flashing things as described above.​

5. Boot into guest systems
Once you finish installing all the guest systems, reboot. Then in the host ROM you can execute the commands in Step 4 again to boot into the corresponding guest system. Don't press any key after the reboot. If there's nothing wrong, you will see the bootanimation and then the Android system. Since external sdcards may not be as fast as internal storage, the first boot may take very long time. If you see the bootanimation, just be patient and it will boot up finally.​

===========================================================
I know I can't speak English well and it's hard to make myself clear. So if you feel confused, please post your questions here so that everyone who knows the answer will be able to help.

And if you are skilled in Android things, you can choose your own way to achieve the goal:
Partition the sdcard → Mod fstsb and rcs to mount partitions on sdcard to /system etc → Mod the ROM installation script → Boot into guest recovery to format(initialize) data & cache &system and flash ROM → Boot into the guest Android OS

This is a little bit complicated. But I do hope this will add more fun to our device ;)
 
Last edited:

r3pwn

Inactive Recognized Developer
Jul 11, 2012
1,745
2,046
Lakeland, FL
r3pwn.com
Although this is labeled for the Xperia TX, after reading through everything, it looks like this works on all devices, you just have to change a few things. Good job putting this together! (Even though I don't have an Xperia TX)
 
  • Like
Reactions: updateing

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    FIRST OF ALL, we should say thanks to @alvinhochun 's work on porting kexec hardboot patch to Xperia M. His original thread is here: http://forum.xda-developers.com/showthread.php?t=2568151
    And @Tasssadar who has ported kexec hardboot patch on MSM chips. Original thread is here: http://forum.xda-developers.com/nexus-4/orig-development/kexec-hardboot-patch-t2472316/post46223952
    As for the kernel patch and kexec binary for TX, they are here: http://forum.xda-developers.com/showthread.php?t=2747215

    OK let's begin our tour on TX...

    0. Disclaimer
    This is a rather dangerous hack. I'm not responsible for data loss, broken SD cards, dead internal storage or bricked phones. Try this at your own risk. Proceed only when you know what you are doing.​

    1. Requirements
    a. ROM with “kexec hardboot” patched kernel. My OmniROM build will do the job. Since Alx31Tse is also using my kernel source for TX, the Carbon builds for TX may be capable of handling this as well. This ROM should be installed into internal storage : just flash it in recovery as usual.​
    b. External MicroSD card which is big enough for your ROMs. One ROM takes up ~4GB space.​
    c. Some basic knowledge of partitions, device nodes, ramdisk modding(check this thread by letama: http://forum.xda-developers.com/showthread.php?t=2418893).​

    2. Partitioning the external sdcard
    a. Plan the partitions​

    Each ROM need three partitions : system, data and cache. You need at least 1.4GB system + 2GB data + 400MB cache for stock ROMs. The system partition for third-party ROMs can be shrinked to ~900MB. Of course you can set your own data partition size if 2GB does not suit your needs. The space left can be used for storing data just like a normal sdcard.

    For example, I'm using a 16GB card and going to install two stock ROMs (9.1.B.1.67 + 9.2.A.0.295). So I have to create at least 6 partitions for them:

    1.4GB system for 295
    2GB data for 295
    400MB cache for 295
    1.4GB system for 67
    2GB data for 67
    400MB cache for 67
    There is ~8GB left after all these partitions. This can be used as a normal sdcard. Just create another partition for it.​

    b. Go partitioning it!​

    Everyone has his own way of doing this. I prefer using a USB card reader and Disk Utility that comes with Ubuntu.

    Erase the card and initialize it with GUID Partition Table (GPT). Of course you can use MBR, but I didn't test it. Be careful in the following steps if you choose MBR.

    Create the “normal sdcard” partition. In my example, create a 8GB partition here and format it with FAT32. THIS PARTITION SHOULD BE THE FIRST ONE ON THE CARD! Otherwise Android system may not be able to recognize it.

    Create the partitions for guest systems. There are no particular order for the partitions. Just make sure you remember their order. DO NOT FORMAT them for now.

    In my example:
    PART 1: 8GB, FAT32
    PART 2: 1.4GB unformatted
    PART 3: 2GB unformatted
    PART 4: 400MB unformatted
    PART 5: 1.4GB unformatted
    PART 6: 2GB unformatted
    PART 7: 400MB unformatted​

    3. Kernel mods for guest systems
    For each guest system:
    a. Unpack its kernel.​

    If you are going to install a full stock ROM, please choose a corresponding kernel with recovery built-in in Android Development section.

    If you are going to install a third-party ROM (OmniROM, CM etc) or customized stock ROM (Rockers etc), chances are that their kernels have recovery built-in already and you can proceed.

    Now unpack the kernel.

    We have zImage(sec0.bin), ramdisk(sec1.bin) now. The rest can be ignored.​

    b. Modify the mount entries in fstab (and other files)​

    fstab is the file that suggests the real device for the /system, /data and /cache mount points. Modding it will make it possible to mount the partitions other than the ones in internal storage on /system /data and /cache, so that we can separate different systems into different partitions.

    Now you have to be clear about “how the partitions on external card will be presented in your phone” (their device nodes). In my example (GPT with 7 partitions):

    PART 1: 8GB → /dev/block/mmcblk1p1
    PART 2: 1.4GB → /dev/block/mmcblk1p2
    PART 3: 2GB → /dev/block/mmcblk1p3
    PART 4: 400MB → /dev/block/mmcblk1p4
    PART 5: 1.4GB → /dev/block/mmcblk1p5
    PART 6: 2GB → /dev/block/mmcblk1p6
    PART 7: 400MB → /dev/block/mmcblk1p7

    As has been mentioned above, mmcblk1p1 is for normal file storage, p2~p4 is for 295, p5~p7 is for 67.

    Files that need modding:
    (sec1.bin/sbin/ramdisk.cpio) /fstab, /fstab.qcom, /init.target.rc
    (sec1.bin/sbin/ramdisk-recovery.cpio) /fstab, /fstab.qcom, /etc/recovery.fstab, /etc/twrp.fstab

    The fstabs are easy to deal with. Just change the block device name for /system /cache and /data to /dev/block/mmcblk1p* accordingly. The init.target.rc has only one line that should be modded. For example,
    FOR 9.1.B.1.67 in my example:
    ramdisk.cpio/fstab:

    /data ext4 /dev/block/mmcblk1p6
    /cache ext4 /dev/block/mmcblk1p7
    /boot/modem_fs1 raw /dev/block/platform/msm_sdcc.1/by-name/modemst1
    /boot/modem_fs2 raw /dev/block/platform/msm_sdcc.1/by-name/modemst2

    ramdisk.cpio/fstab.qcom:

    /dev/block/mmcblk1p5 /system ext4 ro,barrier=1,discard wait,check
    /dev/block/mmcblk1p6 /data ext4 nosuid,nodev,noatime,barrier=1,noauto_da_alloc,discard wait,check,encryptable=footer
    /dev/block/mmcblk1p7 /cache ext4 nosuid,nodev,noatime,barrier=1,discard wait,check
    /dev/block/platform/msm_sdcc.1/by-name/SDCard /mnt/int_storage ext4 nosuid,nodev,barrier=1,noauto_da_alloc,discard wait,check

    ramdisk.cpio/init.target.rc:

    (SEARCH FOR /system)

    on post-fs
    mount ext4 /dev/block/mmcblk1p5 /system ro remount barrier=1

    Just do the same for ramdisk-recovery.cpio. For example:

    ramdisk-recovery.cpio/etc/recovery.fstab


    /boot emmc /dev/block/mmcblk0p4
    /system ext4 /dev/block/mmcblk1p5
    /cache ext4 /dev/block/mmcblk1p7
    /data ext4 /dev/block/mmcblk1p6 length=-16384
    /sdcard ext4 /dev/block/mmcblk0p15
    /external_sd auto /dev/block/mmcblk1p1 /dev/block/mmcblk1

    And replace mmcblk1p5~p7 with p2~p4 then do it all again for 9.2.A.0.295's ramdisk.cpio & ramdisk-recovery.cpio

    NOTE: All these fstab and rc files should be rw-r—r-- and owned by root:root. Otherwise the system may fail to boot.

    Now repack the ramdisk.cpio, ramdisk-recovery.cpio and then the whole ramdisk.​

    4. Installing the guest systems
    Take notice of the texts in red. Change them to fit your needs.
    a. Preparing the guest systems​
    If you are installing full stock ROM (FTF format), you can use Flashtool to dump the system image (Flashtool > Tools > Sin Editor, load system.sin from FTF archive and dump data). Then write the image to the sdcard by “dd if=system.ext4 of=/dev/sdb2“ on the computer.
    If you are installing ROMs in ZIP format, you need to modify updater-script and replace all (for 9.1.B.1.67 in my example)
    /dev/block/mmcblk0p12 or /dev/block/platform/msm_sdcc.1/by-name/System to /dev/block/mmcblk1p5

    /dev/block/mmcblk0p13 or /dev/block/platform/msm_sdcc.1/by-name/Cache to /dev/block/mmcblk1p7

    /dev/block/mmcblk0p14 or /dev/block/platform/msm_sdcc.1/by-name/Userdata to /dev/block/mmcblk1p6
    And
    remove /dev/block/mmcblk0p4 or /dev/block/platform/msm_sdcc.1/by-name/Kernel formatting/writing lines
    Then repack the ROM and push it into phone's internal sdcard.​

    b. Boot the guest kernel/system​
    Remember we have zImage and modded ramdisk for each guest system? adb push them to /data partition. The kexec binary is needed as well. Now you can use the kexec binary(check the beginning of this thread) to boot your guest kernel and then recovery.

    For example:

    I pushed 295 kernel zImage to /data/boot4.3/zImage-stock, modded ramdisk to /data/boot4.3/initrd-stock, and kexec binary to /data/kexec. Now execute as root:

    Code:
            cd /data
            chmod 755 kexec
            busybox sync
            busybox mount -o remount,ro /system
            busybox mount -o remount,ro /cache
            busybox mount -o remount,ro /data
            busybox sync
            ./kexec --load-hardboot [COLOR="Red"]./boot4.3/zImage-stock[/COLOR] –initrd=[COLOR="Red"]./boot4.3/initrd-stock[/COLOR] --mem-min=0x85000000 --command-line="`cat /proc/cmdline`"
            busybox sync
            ./kexec -e # phone reboots and guest kernel (295) starts

    NOTE: the guest kernel's cmdline may not be exactly the same as the host one. However, it doesn't matter much. 67 and 295 both boot fine using the same cmdline as OmniROM. Since bootloader will append some parameters to the command line, using guest's sec3 without appending these parameters manually is not a good idea.​

    c. Preparing filesystems and installing ROMs in ZIP​
    After the phone reboots, press Vol buttons at purple LED to go into recovery. Now you are in the recovery for your guest system (295).

    FORMAT (not wipe) /data and /cache there. For ZIP ROMs you need to format /system as well.

    Then install the modded ZIP file if needed. You can also flash SuperSU or anything else to this guest system in the recovery (remember to check if there are wrong block device paths in updater-script).

    After finishing the installation of one guest system, reboot and you will go into the host ROM. Execute the commands again and specific the next guest system's zImage and ramdisk to boot into the next guest system. Then do the formatting and flashing things as described above.​

    5. Boot into guest systems
    Once you finish installing all the guest systems, reboot. Then in the host ROM you can execute the commands in Step 4 again to boot into the corresponding guest system. Don't press any key after the reboot. If there's nothing wrong, you will see the bootanimation and then the Android system. Since external sdcards may not be as fast as internal storage, the first boot may take very long time. If you see the bootanimation, just be patient and it will boot up finally.​

    ===========================================================
    I know I can't speak English well and it's hard to make myself clear. So if you feel confused, please post your questions here so that everyone who knows the answer will be able to help.

    And if you are skilled in Android things, you can choose your own way to achieve the goal:
    Partition the sdcard → Mod fstsb and rcs to mount partitions on sdcard to /system etc → Mod the ROM installation script → Boot into guest recovery to format(initialize) data & cache &system and flash ROM → Boot into the guest Android OS

    This is a little bit complicated. But I do hope this will add more fun to our device ;)
    1
    Although this is labeled for the Xperia TX, after reading through everything, it looks like this works on all devices, you just have to change a few things. Good job putting this together! (Even though I don't have an Xperia TX)
    1
    Although this is labeled for the Xperia TX, after reading through everything, it looks like this works on all devices, you just have to change a few things. Good job putting this together! (Even though I don't have an Xperia TX)

    Yeah, it seems that the guide applies to all devices with patched kernels :)