www.chinaphonearena.com
[Tutorial] How to setup dual boot on MTK - Printable Version

+- www.chinaphonearena.com (https://www.chinaphonearena.com/forum)
+-- Forum: Phone & Tablet Root, Hack and Develop (https://www.chinaphonearena.com/forum/Forum-Phone-Tablet-Root-Hack-and-Develop)
+--- Forum: *Tech support* General Phone & Tablet Root, Hack and Develop Root IMEI NVRAM CWM TWRP BRICKED (https://www.chinaphonearena.com/forum/Forum-Tech-support-General-Phone-Tablet-Root-Hack-and-Develop-Root-IMEI-NVRAM-CWM-TWRP-BRICKED)
+--- Thread: [Tutorial] How to setup dual boot on MTK (/Thread-Tutorial-How-to-setup-dual-boot-on-MTK)

Pages: 1 2 3


How to setup dual boot on MTK - vampirefo - 2014-04-09

This Tutorial is about setting up a dual booting Phone. Why would anyone want to do this?

The reasons are many, to try out new roms, to fix a nonbooting device, to always have a booting device ready when you are ready to use it. To be able to make your data partition are large as you want same with system, even though 1 GB is more than enough for system, data is where apps and person setting are stored.

The data partition is the one people are always filling up, well with this method one could make data as large as their sdcard, example data could be up to 32 GB, depends on what size sdcard you have and what size limit your phone has.

I am using a 16 GB sdcard, My data is 3 GB and system is 1 GB on this sdcard card the rest of the sdcard is fat32 and used just like any normal sdcard would be used. I recommend using a class 10 sdcard, I buy mine at bestbuy cost $17 for a 16 GB Ultra Plus ScanDisk class 10.

Ok before we start I recommend doing five different types of backups, your phone must be rooted and have custom recovery already installed, as well as having adb installed and working.

Most of the work will be done via CMD ie adb command line, this project for newbies might seem time consuming, for more experienced users it won't take that long. I am a Linux guy, so this Tutorial with all be done on Linux, adb commands for Linux and windows are the same, the biggest difference is going to be how windows users partition their sdcard, I am going to recommend the only tool I use and know, it's a Linux tool but it can be used via livecd.

Gparted can be downloaded from here. [Only registered and activated users can see links Click here to register]

Ok let's start with the backups.
1. NexusTrix has posted how to backup via MTK Droid Tools [Only registered and activated users can see links Click here to register]

2. Khonshu has posted how to backup NVRAM [Only registered and activated users can see links Click here to register]

3. Use your Custom recovery and make a backup.

4. Download Online Nandroid Backup and use it to make a backup. [Only registered and activated users can see links Click here to register]

5. Manual backup, this is the method we use to make the dual boot work. *note don't make this backup til I tell you later on in the Tutorial.
Code:
busybox tar -czvf /sdcard/C30_system.tgz /system

busybox tar -czvf /sdcard/C30_data.tgz /data

Number 5 is where everything happens, the magic if you will, we are going to issue adb commands to not only backup the current system and data, we are going to preserve permissions, which means as soon as they are restored they are in full working order just like when first backed up. They will last forever in this state until needed, I recommend also placing a copy on your pc for safe keeping, incase you wipe your sdcard in the future.

Ok you are going to need a calculator and a hex to dec converter, the calculator should be installed on your pc, the hex to dec I use this online one. [Only registered and activated users can see links Click here to register]

first step is to partition your sdcard, I have uploaded two pics one before and one after the partition, The partitioning is done via Gparted, all 3 partitions are primary.

you can make your partitions what ever size you want, I make my data 3 GB and system 1 GB, you decide what size you want yours, you can always at a later point format the sdcard and remake it if the partition size you used doesn't suite you.

I use a sdcard reader to plug the sdcard into the pc, I don't plug the phone itself into the pc during this process I make 3 partitions on my sdcard.
1. Fat32
2. Ext4
3. Ext4

[Image: 29f48xe.png][Image: 2mhykk3.png]

Once you have partitioned your sdcard, put the sdcard into the phone and connect the phone to your pc. We need to get a few thing from the phone now.

open cmd window

Code:
adb remount
*note if this commands fails on your phone you need to use another command after adb shell.

Code:
adb shell
*note you should see # if not, you will then need to type su, also if adb remount failed from above, once you see # type mount -o remount,rw / system

Code:
cat /proc/dumchar_info > /sdcard/dumchar_info.txt

Code:
cat /proc/partitions > /sdcard/partitions.txt

open another cmd window
Code:
adb pull /sdcard/dumchar_info.txt
Code:
adb pull /sdcard//partitions.txt

no close the second cmd window, open partitions.txt with a good text editor not windows notepad.

look for below or something similar, 179 is the target for sdcard, then you want to find the correct partitions in my case mmcblk1p2 and mmcblk1p3 yours should be the same provided all MTK use same partition structure.
Code:
179       96   15558144 mmcblk1
179       97   11363328 mmcblk1p1
179       98    1048576 mmcblk1p2
179       99    3144704 mmcblk1p3

now open /dumchar_info.txt look for bootimg
Code:
bootimg      0x0000000000600000   0x0000000001d80000   2   /dev/block/mmcblk0

copy this info as well as the two partition names from partitions.txt into a new txt file, in new text file you should have
Code:
mmcblk1p2  
mmcblk1p3
bootimg      0x0000000000600000   0x0000000001d80000   2   /dev/block/mmcblk0

and save close all text files for now.

now open calculator, new text file and website [Only registered and activated users can see links Click here to register] time to do some math.

ok from new file copy first hex and paste into Type hex value here box on website then click covert now copy the numbers from Decimal value box into the new text file.

example copy
Code:
0x0000000000600000
to Type hex value here box then copy
Code:
6291456
from Decimal value box to new text file.

repeat for second hex.

So now in new text file you have below keep in mind your numbers on bootimg most likely will be different than mine.

Code:
mmcblk1p2  
mmcblk1p3
bootimg      0x0000000000600000   0x0000000001d80000   2   /dev/block/mmcblk0
6291456
30932992

ok now put the first dec number in calculator and divide by 4096, and repeat for second number copy answer to new text file.

example
Code:
6291456÷4096=1536
30932992÷4096=7552

so now new text file looks similar to below.

Code:
mmcblk1p2  
mmcblk1p3
bootimg      0x0000000000600000   0x0000000001d80000   2   /dev/block/mmcblk0
6291456
30932992
1536
7552

Ok now time to pull boot.img from phone, in cmd window, using my dec numbers, use your own numbers if different than mine.

Code:
dd if=/dev/block/mmcblk0 of=/sdcard/boot.img bs=4096 count=1536 skip=7552

now open another cmd window

Code:
adb pull /sdcard/boot.img

close this cmd window, Now you need tools to extract boot.img and rebuild it.

download [Only registered and activated users can see links Click here to register]

to unpack boot.img open cmd window

Code:
./unpack-MT65xx.pl ./boot.img

go to boot.img-ramdisk folder open default.prop in a text editor

edit first line, change below
Code:
ro.secure=1
to and save
Code:
ro.secure=0

now open init.rc in text editor find and replace all /emmc@android with /dev/block/mmcblk1p2

find and replace all /emmc@usrdata with /dev/block/mmcblk1p3

now save init.rc, now time to repack boot.img

Code:
./repack-MT65xx.pl -boot ./boot.img-kernel.img ./boot.img-ramdisk ./sdcard.img

now make a folder on your sdcard called dual_boot.
Code:
mkdir /storage/sdcard0/dual_boot

open another cmd window and push both boot.img to /storage/sdcard0/dual_boot, during adb push we are renaming boot.img to phone.img

Code:
adb push ./boot.img /storage/sdcard0/dual_boot/phone.img
adb push ./sdcard.img /storage/sdcard0/dual_boot/sdcard.img

now you need to make two scripts just copy and paste both below each script. *note if your dec numbers are different than mine, make sure both scripts reflects your dec numbers.

reboot-sdcard
Code:
#!/system/bin/sh

if busybox test ! -f /storage/sdcard0/dual_boot/sdcard.img; then
    echo no storage/sdcard0/dual_boot/sdcard.img
    exit 1
fi

dd if=/storage/sdcard0/dual_boot/sdcard.img of=/dev/block/mmcblk0 bs=4096 seek=7552
sync; sync; sync

echo rebooting to Sdcard

sleep 2

reboot


reboot-phone
Code:
#!/system/bin/sh

if busybox test ! -f /storage/sdcard0/dual_boot/phone.img; then
    echo no /storage/sdcard0/dual_boot/phone.img
    exit 1
fi

dd if=/storage/sdcard0/dual_boot/phone.img of=/dev/block/mmcblk0 bs=4096 seek=7552
sync; sync; sync

echo rebooting to Phone

sleep 2

reboot

now push to system and chmod

Code:
adb push reboot-phone /system/bin/reboot-phone
adb push reboot-sdcard /system/bin/reboot-sdcard

Code:
chmod 755 /system/bin/reboot-phone
chmod 755 /system/bin/reboot-sdcard

Code:
reboot recovery

now in cwm recovery or another custom recovery

mount
system
data
sdcard

in cmd window you can calls yours something other C30, I have C30 so my back ups are called C30
Code:
adb shell

busybox tar -czvf /sdcard/C30_system.tgz /system

busybox tar -czvf /sdcard/C30_data.tgz /data

once both backups are made, unmount system and data via recovery.

now mount new partitions via adb

Code:
mount -t ext4 /dev/block/mmcblk1p2 /system
mount -t ext4 /dev/block/mmcblk1p3 /data

make sure they are mounted

Code:
busybox df -h

you should see similar to below, mine already has system and data installed yours don't so Used Available Use will be much different than yours, mount points are what's important here.

Code:
busybox df -h
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   231.1M     48.0K    231.1M   0% /dev
/dev/block/mmcblk0p6    123.1M      4.1M    119.0M   3% /cache
/dev/block/mmcblk1p2   1021.4M    509.3M    460.9M  52% /system
/dev/block/mmcblk1p3      3.0G    656.3M      2.2G  23% /data

if mounted correctly, time to install, this will take time, when one finished type command for second one.
Code:
busybox tar -xzvf /sdcard/C30_system.tgz
busybox tar -xzvf /sdcard/C30_data.tgz

Now clean up
Code:
rm -r /cache/*
rm -r /data/dalvik-cache/*

reboot

download and install Android Terminal Emulator [Only registered and activated users can see links Click here to register]

once done time to test dual boot

open Android Terminal Emulator *note you need to give root permission.

Code:
su

reboot-sdcard

to boot from phone

open Android Terminal Emulator

Code:
su

reboot-phone

on each after fully booted up open Android Terminal Emulator

Code:
busybox df -h

this will show you if you are on phone or sdcard look at the system and data mount points and size.

this is from my phone.

Code:
vampirefo@vampirefo-GA-MA78GM-US2H:~/Desktop$ adb shell
root@hct82_wet_jb5:/ # busybox df -h
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   231.1M     52.0K    231.1M   0% /dev
tmpfs                   231.1M         0    231.1M   0% /mnt/secure
tmpfs                   231.1M         0    231.1M   0% /mnt/asec
tmpfs                   231.1M         0    231.1M   0% /mnt/obb
/emmc@android           689.8M    475.1M    214.7M  69% /system
/emmc@usrdata          1008.3M    590.4M    417.9M  59% /data
/emmc@cache             123.1M      4.1M    119.0M   3% /cache
/emmc@protect_f           8.9M      4.1M      4.8M  46% /protect_f
/emmc@protect_s           8.9M      4.1M      4.8M  46% /protect_s
/dev/block/loop0          1.2M      1.2M         0 100% /mnt/cd-rom
/dev/block/vold/179:8
                          1.7G      3.3M      1.7G   0% /storage/sdcard1
/dev/block/vold/179:97
                         10.8G      5.2G      5.6G  48% /storage/sdcard0
/dev/block/vold/179:97
                         10.8G      5.2G      5.6G  48% /mnt/secure/asec

this is from sdcard
Code:
root@hct82_wet_jb5:/ # busybox df -h
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   231.1M     52.0K    231.1M   0% /dev
tmpfs                   231.1M         0    231.1M   0% /mnt/secure
tmpfs                   231.1M         0    231.1M   0% /mnt/asec
tmpfs                   231.1M         0    231.1M   0% /mnt/obb
/dev/block/mmcblk1p2   1021.4M    509.3M    460.9M  52% /system
/dev/block/mmcblk1p3      3.0G    682.0M      2.2G  23% /data
/emmc@cache             123.1M      4.1M    119.0M   3% /cache
/emmc@protect_f           8.9M      4.1M      4.8M  46% /protect_f
/emmc@protect_s           8.9M      4.1M      4.8M  46% /protect_s
/dev/block/loop0          1.2M      1.2M         0 100% /mnt/cd-rom
/dev/block/vold/179:8
                          1.7G      3.3M      1.7G   0% /storage/sdcard1
/dev/block/vold/179:97
                         10.8G      5.2G      5.6G  48% /storage/sdcard0
/dev/block/vold/179:97
                         10.8G      5.2G      5.6G  48% /mnt/secure/asec



RE: How to setup dual boot on MTK - Sniper47 - 2014-04-10

Hi Vampire, awesome tutorial. I'm sure there will be more questions, but to start, could you explain some about busybox. This is already installed on the phone or is part of the ADB directory on PC? Or both.

And, are the two installs sharing any logical storage? Normally with MTK there is phone storage and internal storage

And is there more to come, or this is it for now?


RE: How to setup dual boot on MTK - vampirefo - 2014-04-10




RE: How to setup dual boot on MTK - linr76 - 2014-04-10

this absolutely deserves to be stickied...

great tutorial, thank you!


RE: How to setup dual boot on MTK - Sniper47 - 2014-04-11




RE: How to setup dual boot on MTK - vampirefo - 2014-04-11

(2014-04-11, 16:41)Sniper47 Wrote: [Only registered and activated users can see links Click here to register]

I build my own from source, source can be found here. [Only registered and activated users can see links Click here to register]
I mean. Do the separate installations share the same logical partitions for phone storage?

Busybox is installed on the phone or on PC or both as required by this tutorial?

Is your custom busybox required or standard busybox can do the job?
Busybox is only installed on Phone, any busybox will work for this project, The separate installs don't share settings, each install has it's own settings, install an app or change something on one install wont effect the other install.

Now at first when you copy the data partition over both installs will look the same cause they are, you just cloned your install, but any changes after that point will only be on the one you made the change on.

Example on my Lenovo a2109 tablet, I Run JB from the sdcard and ICS from phone, these are different OS so they can't share same settings.

Another example, you could only install system and not data, you need to make both data and system partition, but just don't
Code:
busybox tar -xzvf /sdcard/C30_data.tgz
only
Code:
busybox tar -xzvf /sdcard/C30_system.tgz,
doing this will make the sdcard install like brand new install it wont have any setting from your other install.


RE: How to setup dual boot on MTK - andreya108 - 2014-04-12

Seems I missed something, but what if cache and dalvik-cache of roms are not compatible?
One rom may mount internal fat, other not.
Or one may be stock and other are custom like miui or lewa?
Or even it can be different android version which also require different radio?


RE: How to setup dual boot on MTK - vampirefo - 2014-04-12

(2014-04-12, 22:18)andreya108 Wrote: Seems I missed something, but what if cache and dalvik-cache of roms are not compatible?
One rom may mount internal fat, other not.
Or one may be stock and other are custom like miui or lewa?
Or even it can be different android version which also require different radio?

You could make another ext4 partition for cache if you need one, I have never had problems with dual boots sharing cache. But if your install requires one, just make it.

So you would have 4 partitions rather than 3, also you need to change the cache mount from phone to sdcard.
dalvik-cache is in data partition, which is not shared with other install.each individual install has it's own, data partition and dalvik-cache, which is in data partition not cache partition.


RE: How to setup dual boot on MTK - SO69 - 2014-04-13

Dear vampirefo... great job!
I started the process and everything went fine thanks to your detailed explanation although I am very unfamiliar to linux. But I stuck on the use of mtk-tools.
I 've download them but I cant use them.
I double click on "mkbootimg.exe" and I see a window trying to open but it finally doesn't.
Should it be a cmd window?
I open a cmd window from the "start" but when I enter [./unpack-MT65xx.pl ./boot.img] it doesn't recognise this command.
So I can't unpack and modify the boot.img.
Can you please give me some help with this because I 've spend all my night trying to find a solution but with no succes. Crying
Thank you in advance.


RE: How to setup dual boot on MTK - vampirefo - 2014-04-13

(2014-04-13, 14:25)SO69 Wrote: Dear vampirefo... great job!
I started the process and everything went fine thanks to your detailed explanation although I am very unfamiliar to linux. But I stuck on the use of mtk-tools.
I 've download them but I cant use them.
I double click on "mkbootimg.exe" and I see a window trying to open but it finally doesn't.
Should it be a cmd window?
I open a cmd window from the "start" but when I enter [./unpack-MT65xx.pl ./boot.img] it doesn't recognise this command.
So I can't unpack and modify the boot.img.
Can you please give me some help with this because I 've spend all my night trying to find a solution but with no succes. Crying
Thank you in advance.
Yes the upacking and packing commands are typed into terminal, below are scripts I use.

Hi, on my pc, ( Linux box) I make scripts to automate the packing and unpacking of boot.img.

below are the two scripts I use. copy and paste each, name one script unpack. the other repack set permission, double click unpack Linux will ask what to do with file select run the boot.img will unpack.

once you have made your change double click repack, Linux will ask what to do with script select run, the new boot.img will be made.



upack
Code:
#!/bin/bash

./unpack-MT65xx.pl ./boot.img

repack
Code:
#!/bin/bash
rm -rf ./boot.img
rp=./repack-MT65xx.pl
name=-boot
kernel=./boot.img-kernel.img
ramdisk=./boot.img-ramdisk
boot=./boot.img
$rp $name $kernel $ramdisk $boot
rm -rf $kernel
rm -rf $ramdisk

On xda, michfood has posted some scripts for windows users, to unpack mtk boot.img. Perhaps these might work for you better.