Dual Boot do B2G e Android no SGS2

Warning: Esse procedimento não funciona mais. Ele somente funciona com Android 4 (Ice Cream Sandwich) e Siyah Kernel v 5.0.1. Em versões posteriores não funcionará. Considere esse guia arquivado, e use-o sob seu próprio risco.

If you want to test B2G from time to time but continue using Android as your main OS and you have a Samsung Galaxy S2, you can choose to install B2G in a separate partition (which is already present on the phone) and choose where to boot into when your device starts.


In order to dual boot Android and B2G, you have to meet these prerequisites:

  • You have to have built B2G for the Galaxy S2
  • You have to download the Siyah kernel v. 5.0.1 for the Galaxy S2
  • You need the tool simg2img, that you get automatically if you build B2G following the guide on MDN
  • You need the heimdall tool, best if version 1.3.1 as you may encounter problems with version 1.3.2

One-time operations

There are several operations to do in order to get a working dual boot. The following ones need to be done the first time only.

In order to use heimdall without requiring root access, you should create a file called android.rules (the portion of the name before the .rules extension is arbitrary) and place it in /etc/udev/rules.d. The file should contain a line line the following:

SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"

In order to activate this rule, you should restart udev:

sudo service udev restart

and then unplug and replug in the phone. The above rule will also allow adb to access the SGS2 without requiring root privlidges.

Flashing the Siyah kernel

The Siyah kernel is mandatory for the dual boot, because it is this kernel that manages it. Once you have downloaded and decompressed the tar file, you'll be left with a file named zImage. In order to flash it on your phone you have to follow these steps:

  1. Switch off your phone
  2. Reboot in download mode (press together volume down + home + power buttons and then, when asked, volume up button)
  3. Use heimdall to flash the kernel with the following command (your phone needs to be connected to your PC):
    heimdall flash --kernel /path/to/zImage

Once the kernel is flashed the phone will reboot.

Preparing the B2G rom environment

Once you've installed the Siyah kernel, it's time to use its functions to prepare the environment to install your B2G image in the secondary partition. Follow these steps:

  1. Switch off your phone
  2. Reboot in recovery mode (press together volume up + home + power buttons)
  3. In the CWMR Touch interface, go to dual-boot options -> Wipe 2ndROM data/cache -> Yes - Wipe. This operation will take some time

Once the operation is finished, select Go Back and then reboot system now to reboot your phone. If you check, inside the internal SD card of your phone you'll now have a .secondrom directory with inside two files named cache.img and data.img.

B2G update operations

The following operations need to be done every time you build a new version of B2G.

In order to simplify command line instructions, it's advised to copy all needed files in a same folder of your choice. These are the files that need to be copied inside the folder:

  • simg2img, found in B2G/out/target/product/galaxys2/system/bin/
  • system.img, found in B2G/out/target/product/galaxys2/
  • userdata.img, found in B2G/out/target/product/galaxys2/

Once you have all the files in one place, do the following:

  1. Create a data.img file out of the sparse file userdata.img. You can do it with the following command:
    simg2img userdata.img data.img
  2. Put the data.img file on your phone's .secondrom folder. You can do this either by enabling file storage mode on your phone and connecting it to your PC or, if you have USB Debug active, you can use adb:
    adb push /path/to/data.img /sdcard/.secondrom/data.img
  3. Switch off your phone
  4. Reboot in download mode (press together volume down + home + power buttons and then, when asked, volume up button)
  5. Use heimdall to flash B2G firmware inside the second partition:
    heimdall flash --hidden system.img

Once the flash is finished, your phone will reboot and at boot time you can boot into your second rom (the B2G one) by pressing the home button during the bootloader countdown. If everything has gone right, once you've finished booting B2G you'll have a black screen on your phone. You now have to install Gaia.

Note: Depending on how you want to test B2G, you may not want to put a new data.img file on the phone every time you update B2G, as it will wipe all of your preferences, installed applications and in general pretty much everything you've done while using B2G.

Boot operations

The following operations need to be done every time you boot inside B2G.

Unfortunately, there's no simple way to put Gaia inside the system.img B2G image, and it get lost when you switch off your phone, so you'll need to install Gaia again every time you boot inside B2G. To install Gaia, type the following on a console after you've booted your phone inside B2G (so you have a black screen) and have connected your phone to your PC:

cd B2G/gaia
GAIA_DOMAIN=foo.org make install-gaia

After the upload of Gaia is completed, on your phone's screen the B2G interface will appear.