[Android General] dreccon:
A lot of users around here like to try out different kinds of ROMs on their devices. It is advisable though, to always keep a backup of a stable (usually stock) ROM on your SD card. The truth is that it is very time-consuming to have to backup and restore ROMs in recovery just to boot to a new ROM for a few hours, run some tests and then go back to the stable one. It is also true that AOSP based ROMs may not support special features of certain devices (e.g. 3D displays and cameras or FM tuners), so a stock-based ROM must always be handy in case you need those features. This is why Dual-Boot can be useful. It allows people to switch between two ROMs almost as quickly as a simple reboot.

I have followed these guidelines to create Dual-Boot on four different phones and

I suppose

that the same method can be used for any phone.

The idea is to keep any stable ROM as primary and install an AOSP-based JB (4.1) or newer ROM on the SD-card.

Prerequisites:

A) You need to fully unlock your device (Root, Bootloader unlock, S-Off or whatever else your device has that may prevent you from flashing partitions).

B) You need to find a suitable way to unpack and repack your boot.img. Different ways are available for different devices. I can only suggest those that I have tested for mine.

C) You need to have a working updated busybox.

D) A ROM zip file to install onto the SD card. This ROM

must NOT be using Aroma Installer

.

Steps:

1. First you need to figure out the locations and sizes of your system, data, cache and boot partitions (you can use Partition Table from Play Store).

2. Create three additional partitions at the end of your SD card with the sizes you found. You can either use AParted on your phone or MiniTool and a card adapter on your PC. The partitions must be all primary and formatted to ext4.

(HINT1: If you use AParted, you probably want go hit "Decline" on the agreement, otherwise it will install adware junk)

(HINT2: You may want to create a larger Data partition, so that you have more space to install apps)

(HINT3: If you can convert ZIPs using DBootRecovery from 2nd post, then do it and jump to step 7)

3. Now you have to unzip the ROM file you want to install, browse to /META-INF/com/google/android, find the updater-script and edit all lines that contain mmcblk0ps (where s is your internal system partition number) to mmcblk1p2 (your new SD-system partition). Some ROM zips (like MIUI) also install stuff to the data partition, so be careful and change the respective lines from mmcblk1pd (where d is the number of your internal data partition) to mmcblk1p3.

4. You also need to unpack the boot.img, find the fstab.nick in the ramdisk (nick is the nickname of your device) and edit the sysyem, data and cache mountpoints to /dev/block/mmcblk1p2, 3 and 4 accordingly.

In some ROMs, the fstab. file plays no important role. In this case you must search inside files ending in .rc in the RamDisk for lines that have to do with the system, data and cache partitions. For example, in HTC One SV stock-based ROMs, you must change emmc@system with /dev/block/mmcblk1p2. Data and cache also follow this pattern.

5. If you need to flash GApps, then you must also modify that updater-script by changing the line run_program("/sbin/busybox","mount","/system"); into mount("ext4","EMMC","/dev/block/mmcblk1p2","/system");

Any other add-on you may want to flash must first be edited as described in steps 4 & 5.

6. Pack and zip everything back and reboot to recovery.

7. Make a backup of your current ROM and flash your modified zip(s).

When you reboot, your device should load your secondary ROM.

To switch back to the primary ROM you need to reflash your primary kernel (from the backup you took). Use dd if=path/backup.boot.img of=/dev/block/mmcblk0pb (where b is your boot partition) and reboot.

To boot back to your secondary ROM, just use the above command to flash the boot.img extracted from your modified ROM.zip. This process can now be done automatically using SwitchROM.sh from 2nd post

If you don't like scripts or terminal commands, another way to flash your boot images is Flashify.

If for any reason your 2nd ROM doesn't boot (e.g you haven't found the right method to pack your boot.img), you can advanced-restore just your primary boot.img from your backup in recovery. This way you'll be able to boot back to your primary ROM which is otherwise unaffected by the procedure.

In order to complete step 4, these links may be a good start:

i) These tools by Modding.MyMind work on my HTC.

ii) These ones by michfood work on my HTC but only unpack my LG boot.img

iii) and this one by berni987654321 packs my LG boot.img (download dualboot_tool.zip at the end of 1st post).

Don't forget to hit "Thanks" on those pages too.

Important:

- Be extra careful if your secondary ROM supports OTA updates which are applied through recovery. Only download but NEVER apply them before you tweak the zips as described above. Otherwise they will overwrite your primary ROM!

- Actually, every zip you want to flash to your secondary ROM must be edited first, otherwise it will flash to your primary.

- You can only use your regular custom recovery to flash edited zips to your secondary partitions. You can't use it to backup, restore or wipe them. Those functions will only affect the primary ROM. For this reason, I have created the DBoot Recovery script. For more info, read on to the second post.

Special thanks to [MENTION=4516732]berni987654321[/MENTION] from whom I learned almost everything there is to know about Dual-Boot. This guide is based on his work.