FORUMS
Remove All Ads from XDA

[GUIDELINES] Dual-Boot on (theoretically) any Android device

1,314 posts
Thanks Meter: 1,025
 
By dreccon, Senior Member on 7th March 2014, 02:25 PM
Post Reply Email Thread
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.


Quote:

WARNING: If you are not familiar with the way Android works, you can easily brick your device by flashing the wrong partition. I won't assume responsibility if you do and I can't offer support since I cannot possibly own all the devices this guide may be applicable to. If you don't fully understand these guidelines, then stay away. If you still want to try, remember, you are on your own! Questions, suggestions and remarks should be properly posted in the thread for everyone to read. Take no ofense, I will not reply to PMs.



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 [email protected] 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 @berni987654321 from whom I learned almost everything there is to know about Dual-Boot. This guide is based on his work.
The Following 16 Users Say Thank You to dreccon For This Useful Post: [ View ] Gift dreccon Ad-Free
 
 
7th March 2014, 02:27 PM |#2  
DBoot Recovery Tools
Here are the scripts I promised.


Initial Setup

1. In order to use the scripts, you need to have partitioned your SD card the way I described in the previous post.
2. Download the zip from the link at the end of this post, unzip it and copy the DualBoot folder to the root of your SD card.
3. Install Script Manager from Play Store
4. Install (or update) Busybox

Inside the Dual Boot folder you will find two scripts and some more folders. Please do not change anything there. Just use ScriptManager to run the scripts. Their usage is explained below.




DBootRecovery.sh

Purpose: Manage your secondary ROM.
This tool is designed to run on the primary ROM, but some major functions are also available on the secondary.



1st run

Open ScriptManager, browse to the DualBoot folder and tap on DBootRecovery.sh. At the top of the screen that follows, select the first two icons (Fav and SU). I also prefer to enable the Wklock icon (it has to be enabled in settings first). Then you can hit Run.
When you run the script for the first time, it will try to read the /proc/emmc file (if it exists on your system) in order to determine your normal partitions. If the file exists, it will present you the data, so you can accept or reject them. If it doesn't exist, it will ask you to enter your partition numbers manually. In both cases, the data will be exported to a new file (part.ini) in the DualBoot folder and you will not be asked again.



The main screen

The top two lines are important. After a selection you made completes and returns to the main screen, the first two lines will inform you of its success or if any errors occurred.



Main menu

1. Backup ROM2
This option will create a backup of your secondary ROM. It will actually create images of your secondary system (mmcblk1p2) and data (mmcblk1p3) partitions. Those two will be saved in the backup folder inside DualBoot. Be careful, a new backup will overwrite the old one. If you want to keep an old backup, make sure you move or rename it.

2. Restore ROM2
This option will flash the images you took with option 1 back to their respective secondary partitions. It will only be available while you are on your primary ROM (you don't really expect to flash a partition while it's being used).

3. Convert ZIPs
This tool wil automatically do all the edits described in the 1st post to all ZIPs it can find in the OriginalZIPs folder. It is based on @Modding.MyMind's binaries [point (i) in 1st post]. If they don't work for you, you will see an error message. The original ZIPs will be kept intact and the edited ones will be created in the DBootZIPs folder. It is not certain that it will function equally well on all devices/ROMs, so before you flash your edited ZIPs, please check that they were edited correctly. This tool will NOT flash ZIPs. It will only convert them, so they can be flashed as secondary ROMs using your regular custom recovery. The tool will also put boot2.img in the img folder for use with the Switch ROM function. If you are on your primary ROM, it will also backup your current boot partition into a boot1.img in the img folder.

4. Advanced options
After selecting this, you will be taken to another menu where you can find more options. Most of them are not available while on your secondary ROM.

9. Switch ROM
This does the same as the individual SwitchROM.sh script. Read below.

0. Exit
I have decided not to explain this option.



Advanced menu

1. Wipe System2
2. Wipe Data2
3. Wipe Cache2
4. Wipe Dalvik2

These options just do to the secondary ROM what their name implies. They will only be available while on your primary ROM. If you want to factory-reset your secondary ROM, just wipe your Data2 and Cache2. When you flash new addons, it is advised to wipe Cache2 and Dalvik2. You can also wipe everything if you want to clean-install a completely new ROM.

5. Update binaries
Whenever Modding.MyMind updates his binaries, download and put them in your DualBoot/bin folder. Then, use this option to update existing binaries in your /system/bin folder.

0. Main Menu
Returns to the previous menu




SwitchROM.sh

The name is self-explanatory. This tool can only function if it finds the files boot1.img and boot2.img inside the DualBoot/img folder. These files will be automatically generated when you convert a ROM zip (using option 3). Alternatively, if you know what you are doing, you can create and put them there yourself.
Tap it in Script Manager and again select the first two icons (Fav and SU) and Run. It will automatically detect the current ROM, flash the boot image of the other one and prompt you to reboot. Use your Power-Menu and reboot your device. Your device will now boot to the other ROM.
In previous versions of this script for the LG Optimus 3D, I had included a reboot command. The reason why I am not using it any more is that the device would turn off abruptly and not "shutdown" the way it does when selecting it from the Power-Menu.





DOWNLOAD:
Get the latest version from here.





TROUBLESHOOTING:
If, while converting a zip, the script gives you an error that yourboot.img is incompatible, then either you have an encrypted header, or you have a truly incompatible boot.img! In any case, visit [Without PC] Unpack, Edit, Repack boot.img to read how to deal with encrypted headers, or to download the latest boot_manipulation.zip





Changelog:

13.03.2014 Initial upload of ZipEditor and SwitchROM.

17.03.2014 Updated ZipEditor to support the conversion of HTC-OneSV ROMs (AOSP and Stock based). Thanks to Modding.MyMind for assisting.

23.03.2014 First upload of DBootRecovery. The ZipEditor is now contained in it. If you are wondering about the v3.0, previous versions were device specific (only for the LG-P920). This is the first one for use on any Android.

21.06.2014 Version 3.1: Added support for the new LG P920 KitKat ROM. Fixed a bug where Dalvik2 cache would not be properly wiped. Changed a few minor details for better script operation.
The Following 10 Users Say Thank You to dreccon For This Useful Post: [ View ] Gift dreccon Ad-Free
Modding.MyMind
9th March 2014, 04:15 PM |#3  
Guest
Thanks Meter: 0
 
More
Very insightful bro. Thanks for the share. I will definitely try this out. This may be my motivation to work on my Port Rom again. Was getting tired of wiping, flashing, wiping, flashing.... Was a nuisance and I unfortunately only have one device for my current model. This will be really useful to me in the future. Huge thanks again for letting me know about this thread.

Sent from my C525c using Tapatalk
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
Modding.MyMind
9th March 2014, 09:44 PM |#4  
Guest
Thanks Meter: 0
 
More
Hey, getting ready to do this now with a 2gig. Using it as a test run lol. Anyways, to confirm, you leave the first part as is, meaning, fat 32, but add three additional parts to make a total of four partitions within the sdcard. So for example, part 1 (fat32), part 2-4 (ext4) which those would be the system, data, and cache. I'm confident that is how it is done, but wanted to clarify. Will do it now and check back for a reply later lol. Meanwhile, this has also given me a couple of dev ideas

Sent from my C525c using Tapatalk
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
9th March 2014, 09:45 PM |#5  
russellvone's Avatar
Senior Member
Flag Gilmer
Thanks Meter: 852
 
Donate to Me
More
Aww snap! Lol
The Following 2 Users Say Thank You to russellvone For This Useful Post: [ View ] Gift russellvone Ad-Free
9th March 2014, 09:54 PM |#6  
Quote:
Originally Posted by Modding.MyMind

Hey, getting ready to do this now with a 2gig. Using it as a test run lol. Anyways, to confirm, you leave the first part as is, meaning, fat 32, but add three additional parts to make a total of four partitions within the sdcard. So for example, part 1 (fat32), part 2-4 (ext4) which those would be the system, data, and cache. I'm confident that is how it is done, but wanted to clarify. Will do it now and check back for a reply later lol. Meanwhile, this has also given me a couple of dev ideas

Sent from my C525c using Tapatalk

Trust your confidence. You are right!

If you have a large card and use MiniTool, you can "shrink" your main partition to make room for the additional three. This way it won't be wiped.

Sent from the 3rd dimension!
The Following 3 Users Say Thank You to dreccon For This Useful Post: [ View ] Gift dreccon Ad-Free
Modding.MyMind
9th March 2014, 09:58 PM |#7  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by dreccon

Trust your confidence. You are right!

Sent from the 3rd dimension!

Outstanding, just finished partitioning it. Will tackle the boot.img now.

Sent from my C525c using Tapatalk
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
9th March 2014, 10:03 PM |#8  
One additional piece of info. Be extra careful if your secondary ROM supports OTA updates which are applied from recovery. Only download but NEVER apply them before you tweak the zips. Otherwise they will overwrite your primary ROM!

Sent from the 3rd dimension!
The Following 3 Users Say Thank You to dreccon For This Useful Post: [ View ] Gift dreccon Ad-Free
Modding.MyMind
9th March 2014, 10:35 PM |#9  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by dreccon

One additional piece of info. Be extra careful if your secondary ROM supports OTA updates which are applied from recovery. Only download but NEVER apply them before you tweak the zips. Otherwise they will overwrite your primary ROM!

Sent from the 3rd dimension!

Not unless I make a change with the recovery lol

Anyways, I am still messing with my boot.img the fstab file for my device doesn't contain a list of mount points.

This is really the only thing it has as far as partitions are listed:

Code:
userdata/dataext4noatime,nosuid,nodev,noauto_da_alloc,discardencryptable=extra
Sent from my C525c using Tapatalk
9th March 2014, 10:39 PM |#10  
russellvone's Avatar
Senior Member
Flag Gilmer
Thanks Meter: 852
 
Donate to Me
More
Here's HTC OneSV K2_CL recovery.fstab

# mount pointfstypedevice[device2]
/boot emmc/dev/block/mmcblk0p20
/cacheext4/dev/block/mmcblk0p36
/dataext4/dev/block/mmcblk0p37
/devlogext4/dev/block/mmcblk0p25
/miscemmc/dev/block/mmcblk0p22
/int_sdvfat/dev/block/mmcblk0p38
/recoveryemmc/dev/block/mmcblk0p21
/sdcardvfat/dev/block/mmcblk1p1 /dev/block/mmcblk1
/systemext4/dev/block/mmcblk0p35
The Following 3 Users Say Thank You to russellvone For This Useful Post: [ View ] Gift russellvone Ad-Free
Modding.MyMind
9th March 2014, 10:41 PM |#11  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by russellvone

Here's recovery.fstab

# mount pointfstypedevice[device2]
/boot emmc/dev/block/mmcblk0p20
/cacheext4/dev/block/mmcblk0p36
/dataext4/dev/block/mmcblk0p37
/devlogext4/dev/block/mmcblk0p25
/miscemmc/dev/block/mmcblk0p22
/int_sdvfat/dev/block/mmcblk0p38
/recoveryemmc/dev/block/mmcblk0p21
/sdcardvfat/dev/block/mmcblk1p1 /dev/block/mmcblk1
/systemext4/dev/block/mmcblk0p35

Thanks bro, i was actually trying to remember where that file was at haha.

Sent from my C525c using Tapatalk
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes