[Epic 4G Android Development] Rodderik:
Dual Boot Support

DualBoot Helper APP is now on the market! (See bottom of this post for more info)

DISCLAIMER: I am not responsible for anything, ever. It is not my fault if you do not read. I do not explain things because I enjoy banging on the keyboard. If you do not read this entire post before jumping in then do not expect me or anyone else to be much help. By following this guide and any links YOU assume all responsibility for your device and anything that happens with it.

What is it?

Dual booting allows you to run two separate roms on your device at one time. It is done by intercepting the mount points during the startup of the device. This is accomplished by checking the sdcard for a specifically named file when the kernel first loads and uses the appropriate files to boot with the correct partitions. Reading from the sdcard is slower than reading from the internal memory of the phone so the speed of your sdcard will drastically determine the speed any rom runs. On the same note a rom flashed to the sdcard will take longer than usual on the first boot.

What does it do for me?

Running two separate roms has many uses for just about everyone. Users can use dual booting to try different roms, themes, apps, modifications, or anything while keeping their existing installation intact. The uses are just about endless. Besides testing different roms, this allows the user try these things and make sure they are compatible and stable before pushing the changes to their internal memory. Rom developers have all of the above options plus a few. Rom developers can additionally use dual booting to test builds of their roms without fear of soft bricking their device. For advanced users, you can mount the partitions of the other rom (be it sdcard or internal) and fix bad apk files or messed up files. The options really are limitless!

What do I need?

Sdcard 2GB or larger

Dual boot compatible kernel

Other things I should know...

*The kernel MUST support BOTH roms you flash. Unfortunately this means you can NOT mix froyo and gingerbread roms. Make sure you know what the kernel supports before you flash anything!

*If you compare roms, benchmarks will hold no value due to the sdcard being so much slower than internal memory.

*Faster sdcards will perform better than slower ones. Note: the stock 16GB sdcard is a class 2 which simply classifies it's minimum speed. A higher class sdcard will more than likely perform faster but the class rating is a minimum and not a maximum. It is entirely possible that a certain class 2 card can out perform a different class 6 card. Keep this in mind when researching to buy a new faster sdcard. More info in this post.

*First boot takes longer than usual. Up to 15 minutes! Please wait until the rom boots and the initial media scanner is done before you judge usability.

*Using a rom from the sdcard will cause the sdcard to wear faster. This is due to many more reads and writes of data than normal. The Epic simply does not have the internal capacity to run dual roms on the NAND. That being said the sdcard is our next option. While it may reduce the over all life of the sdcard keep in mind there are other android devices like the Nook Color and the other Galaxy S phones that have internal sdcards running the Android operating system. My personal opinion with is with other devices running off internal sdcards and with the price of sdcards getting cheaper and cheaper it was worth it to explore this option for the Epic.

Ok ok, so how do I get started?

I am going to break the steps down into sections. Please read everything to ensure you understand what all is involved in getting everything working. I recommend making a backup in Clockwork Mod and saving it to your PC before you even get started.

Section 1 - Setting up the environment

Step 1. Flash a compatible kernel (Kernel developers, PM me if you add my dual boot support to your kernel and I will update the list below) Remember you can NOT mix a eclair, froyo, or gingerbread roms and the kernel MUST support both roms!

Currently compatible kernels:

Genocide 2.0 Supported Roms: EC05, EB13, and DK28

Section 2 - Preparing sdcard

Important information!!!! This will destroy ALL data on your sdcard so if you lose pictures of your dog, cwm backups, nudies of your spouse, etc then you can't blame me. BACKUP YOUR SDCARD!

The easy way:

Reboot into recovery mode with a program like Rom Manager, Quick Boot, or type 'reboot recovery' from a terminal. (NOT 3-finger boot to recovery...this will NOT work)

The easy way WILL erase your sdcard with NO confirmation....you have been warned!

Choose one of the following flashable zips to automatically partition your sdcard

DualBoot_Partition_RFS.zip

DualBoot_Partition_EXT4.zip

The manual way:

Reboot into recovery mode with a program like Rom Manager, Quick Boot, or type 'adb reboot recovery' from a command line. (adb commands assume you have a working install of the Android SDK)

While in recovery issue the following commands:

adb shell
cd /sbin
./dbpart.sh --help

I put many hours into the partitioning script to make it as simple to use as possible. Simply follow program usage instructions.

Section 3 - Preparing a rom

Since we have blank partitions on the sdcard we need to populate them with data. There are multiple ways to accomplish this and you can choose which solution best suits your needs. I am not going to cover ALL methods here but enough to suffice any likely scenario needed.

The dd method will clone your current setup to the sdcard (these commands may take up to 15 minutes)

The easy way:

Flash this dd script: DualBoot_Clone_to_sdcard.zip

The manual way:

adb shell
dd if=/dev/block/stl9 of=/dev/block/mmcblk0p2
dd if=/dev/block/stl10 of=/dev/block/mmcblk0p3
dd if=/dev/block/stl11 of=/dev/block/mmcblk0p4

Preparation is complete. Please skip down to booting from sdcard.

The flash method is for flashing a new rom to the sdcard.

The easy way:

There is no sure fire easy way just yet. Stay tuned though.

The manual way:

This method is not that difficult so there is no need to be intimidated by it. It requires editing a few lines of the script that Clockwork Mod executes when flashing a rom or addon. For this example I am going to use a file named epicrom.zip but you can use any name you wish.

Step 1. On your PC, open epicrom.zip (I recommend using a program like 7zip)

Step 2. Navigate to the META_INF\com\google\android\ folder.

Step 3. Drag the file updater-script out of the zip to your desktop.

Step 4. Open the updater-script file with a text editor such as notepad (I recommend notepad++ or textpad)

Step 5. Change every instance of /dev/block/stl9 to /dev/block/mmcblk0p2

Step 6. Change every instance of /dev/block/stl10 to /dev/block/mmcblk0p3

Step 7. Change every instance of /dev/block/stl11 to /dev/block/mmcblk0p4

Step 8. Delete the entire line for any lines that contain /dev/block/bml7 or /dev/block/stl7 to disable flashing another kernel and breaking dual boot support.

Step 9. Save the file and drag and drop it back into epicrom.zip and let it replace the old one.

Note: If you get a status 6 or some other error when trying to flash it is likely you made a typo or your text editor did no save the updater-script file correctly. Recommended action is to correct the typo and/or use one of the recommended text editors note in Step 4.

Section 4 - Flashing to sdcard

Flashing a rom from this point is the same as you usually do. Put the modified rom on your sdcard and flash with Clockwork Mod like usual. I recommend doing a backup in Clockwork Mod BEFORE you flash in case you messed anything up by accident and end up flashing over internal memory when you meant to flash to the sdcard.

Section 5 - Booting sdcard

To boot from the sdcard place a file in the root of your sdcard called 'bootsdcard'. If you named it correctly upon reboot, the kernel will load the rom from the sdcard and not internal memory.

To boot back into internal memory simply remove this file from your sdcard and reboot.

You can switch back and forth using this method. If the file is there it boots sdcard, if the file is not there it boots normally. Pretty simple right?

Section 6 - Other flashables (not roms)

Themes, addons, and anything else that is flashable with Clockwork Mod must be modified in the same fashion as the rom. Use the same procedure documented in Section 3, The flash method.

Kernel Developers:

If you would like to add dual boot support to your kernel please refer to this commit: https://github.com/Rodderik/Genocide-Kernel/commit/a5dfd9f369ae4f2c90c1e7fc7d8995f88f72bd01

I will update this section if I push any specific changes to dual booting.

Now with an APP!

DualBoot Helper

VenumX coded up an APK to work with Clockwork Mod to run the scripts.

http://xdaforums.com/showthread.php?p=15486144#post15486144

Questions, concerns, gripes, or complaints can be left in this thread. If you need to report any problems please be as detailed as possible.