Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[MOD][MultiBoot]Image Rom Boot under Custom Kernel

OP dlhxr

24th August 2014, 06:19 PM   |  #1  
dlhxr's Avatar
OP Senior Member
Flag Shenzhen
Thanks Meter: 114
 
292 posts
Join Date:Joined: May 2011
More
Just join the OnePlus One group yesterday from Galaxy Nexus and start porting something in Galaxy Nexus threads into OnePlus One.

Image Rom Boot under Custom Kernel


CONTENTS:

1.Introduction
2.Image Creation
3.Kernel Modification
4.Zip Modification
5.Switch Roms
6.Wipe Data
7.Acknowledgement
8.Most Frequently Asked Questions
Introduction
1.Similar to MultiROM, but without kexec-hardboot patch support and makes no change to your original rom.
2.Boot your rom from image files.
Code:
/data/media/rom/system.img      as    system partition
/data/media/rom/data.img        as    data partition
/data/media/rom/cache.img       as    cache partition
3.Use recovery zip file to switch roms.

Image Creation
Create images and then put them into /data/media/rom/
1.Use dd command to create images. E.g. create a image with size 500M and with name 500.img
Code:
dd if=/dev/zero bs=1M count=500 >> 500.img
mkfs.ext4 500.img
I suggest 800M for system partition, 1000M for data partition and 50M for cache partition.
Here are some pre-created images with different sizes.
IMGs.zip
2. Rename the images to system.img, data.img and cache.img and put them into our phone /data/media/rom/

Kennel Modification
AutoModification Script (Default image location: /rdata/media/rom/default/)
Auto-Modification.7z

1.Unzip boot.img from rom zip file.
2.Download mkboot tool by xiaolu to unpack the boot.img and get the ramdisk.
3.Put boot.img and tool files into the same directory.
4.Use following command to unpack.
Code:
./mkboot boot.img output
5.Get into output/ramdisk and we need to modify fstab.bacon and init.bacon.rc.
6.Find fstab.bacon and commnent the system, cache mounting line and modify data mounting line.
Code:
#/dev/block/platform/msm_sdcc.1/by-name/system       /system         ext4    ro,barrier=1                                                    wait
/dev/block/platform/msm_sdcc.1/by-name/userdata     /rdata           ext4    noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer,length=-16384
#/dev/block/platform/msm_sdcc.1/by-name/cache        /cache          ext4    noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,journal_async_commit,errors=panic wait,check
7.Find init.bacon.rc.
The on fs part. Add following line before mount_all ./fstab.bacon.
Code:
mkdir /rdata 0771 system system
Add following lines after mount_all ./fstab.bacon.
Code:
exec /sbin/busybox mount -t ext4 -o ro /rdata/media/rom/system.img /system
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/data.img /data
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/cache.img /cache
Then modify the sdcard simulation line to share the same sdcard directory.
Find # virtual sdcard daemon running as media_rw (1023) and add replace /data/media by /rdata/media
Code:
# virtual sdcard daemon running as media_rw (1023)
service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /rdata/media /mnt/shell/emulated
    class late_start
8.Extract the busybox binary from attachment to output/ramdisk/sbin/
busybox.7z
9.Repack the kernel with modified ramdisk.
Code:
./mkboot output new_boot.img
10.Pack boot.img into a zip file for recovery or we can just flash boot.img using fastboot.
Zip Modification
AutoModification Script (Default image location: /rdata/media/rom/default/)
Auto-Modification.7z
Attention: AutoModification Script may not be compatible to all roms

We need to modify the rom zip file in order to install rom into images. Just modify updater-script.

1.Add following lines below the first line. assert(getprop("ro.product.device") == "bacon" || getprop("ro.build.product") == "bacon");
Code:
unmount("system");
unmount("data");
unmount("cache");
run_program("/sbin/mkdir", "/rdata");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/rdata");
Replace the following line
Code:
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");
by
Code:
run_program("/sbin/losetup", "/dev/block/loop1", "/rdata/media/rom/system.img");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/system");
Replace the following lines
Code:
format("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "0", "/system");
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");
by
Code:
run_program("/sbin/losetup", "/dev/block/loop1", "/rdata/media/rom/system.img");
run_program("/sbin/mke2fs", "-T", "ext4", "/dev/block/loop1");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/system");
Replace the following line
Code:
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/data");
by
Code:
run_program("/sbin/losetup", "/dev/block/loop2", "/realdata/media/rom/data.img");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop2", "/data");
Replace the following line (not include the lines you add at first.)
Code:
unmount("data");
by
Code:
run_program("/sbin/umount", "-d", "/data");
Replace the following line (not include the lines you add at first.)
Code:
unmount("system");
by
Code:
run_program("/sbin/umount", "-d", "/system");
Delete the following line
Code:
package_extract_file("boot.img", "/dev/block/platform/omap/omap_hsmmc.0/by-name/boot");
Add the following line in the end
Code:
run_program("/sbin/umount", "/rdata");
Last edited by dlhxr; 25th August 2014 at 07:56 PM.
The Following 4 Users Say Thank You to dlhxr For This Useful Post: [ View ]
24th August 2014, 06:19 PM   |  #2  
dlhxr's Avatar
OP Senior Member
Flag Shenzhen
Thanks Meter: 114
 
292 posts
Join Date:Joined: May 2011
More
Switch Roms
Just flash different boot.img to switch different roms.
Fastboot or recovery are both ok. Here is an example for recovery zip file.

1.updater-script in Install_2nd_kernel.zip
Code:
assert(getprop("ro.product.device") == "bacon" || getprop("ro.build.product") == "bacon" || 
       getprop("ro.product.device") == "A0001" || getprop("ro.build.product") == "A0001" || abort("This package is for \"bacon,A0001\" devices; this is a \"" + getprop("ro.product.device") + "\"."););
ui_print("Backup the Kernel in the Fisrt Rom");
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/data");
run_program("/sbin/busybox", "rm", "-rf", "/data/media/rom/1st.img");
run_program("/sbin/busybox", "dd", "if=/dev/block/platform/msm_sdcc.1/by-name/boot", "of=/data/media/rom/1st.img");
ui_print("Install Kernel");
package_extract_file("boot.img", "/dev/block/platform/msm_sdcc.1/by-name/boot");
ui_print("Done!");
2.updater-script in Restore_1st_kernel
Code:
assert(getprop("ro.product.device") == "bacon" || getprop("ro.build.product") == "bacon" || 
       getprop("ro.product.device") == "A0001" || getprop("ro.build.product") == "A0001" || abort("This package is for \"bacon,A0001\" devices; this is a \"" + getprop("ro.product.device") + "\"."););
ui_print("Restore the Kernel for the Fisrt Rom from Backup");
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/data");
run_program("/sbin/busybox", "dd", "bs=4096", "if=/data/media/rom/1st.img", "of=/dev/block/platform/msm_sdcc.1/by-name/boot");
ui_print("Done!");
Wipe Data
Use zip files under recovery to wipe data. E.g. wipe system+wipe data+wipe cache
Code:
assert(getprop("ro.product.device") == "bacon" || getprop("ro.build.product") == "bacon" || 
       getprop("ro.product.device") == "A0001" || getprop("ro.build.product") == "A0001" || abort("This package is for \"bacon,A0001\" devices; this is a \"" + getprop("ro.product.device") + "\"."););
ui_print("Wiping data...");
unmount("/data");
run_program("/sbin/mkdir", "/realdata");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/realdata");
run_program("/sbin/losetup", "/dev/block/loop1", "/realdata/media/rom/data.img");
run_program("/sbin/mke2fs", "-T", "ext4", "/dev/block/loop1");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/data");
run_program("/sbin/umount", "-d", "/data");
ui_print("Wiping cache...");
unmount("/cache");
run_program("/sbin/losetup", "/dev/block/loop1", "/realdata/media/rom/cache.img");
run_program("/sbin/mke2fs", "-T", "ext4", "/dev/block/loop1");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/cache");
run_program("/sbin/umount", "-d", "/cache");
ui_print("Wiping system...");
unmount("/system");
run_program("/sbin/losetup", "/dev/block/loop1", "/realdata/media/rom/system.img");
run_program("/sbin/mke2fs", "-T", "ext4", "/dev/block/loop1");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/system");
run_program("/sbin/umount", "-d", "/system");
run_program("/sbin/umount", "/realdata");
Last edited by dlhxr; 24th August 2014 at 07:02 PM.
The Following User Says Thank You to dlhxr For This Useful Post: [ View ]
24th August 2014, 06:22 PM   |  #3  
dlhxr's Avatar
OP Senior Member
Flag Shenzhen
Thanks Meter: 114
 
292 posts
Join Date:Joined: May 2011
More
Acknowledgement
xiaolu for his updated compiled mkboot files.
twistedumbrella for doing galaxy nexus version together with me and his help.
crayon for his busybox mount way to support HTC DHD multiboot, which inspired me a lot!
Most Frequently Asked Questions
To be updated.
Last edited by dlhxr; 24th August 2014 at 07:01 PM.
The Following 2 Users Say Thank You to dlhxr For This Useful Post: [ View ]
24th August 2014, 07:30 PM   |  #4  
bud77's Avatar
Senior Member
Flag Near Paris
Thanks Meter: 462
 
1,050 posts
Join Date:Joined: Jun 2011
Donate to Me
More
That's so much more complicated than multirom ... And this needs a custom kernel too

What are the benefits ?
The Following User Says Thank You to bud77 For This Useful Post: [ View ]
25th August 2014, 10:09 AM   |  #5  
dlhxr's Avatar
OP Senior Member
Flag Shenzhen
Thanks Meter: 114
 
292 posts
Join Date:Joined: May 2011
More
Quote:
Originally Posted by bud77

That's so much more complicated than multirom ... And this needs a custom kernel too

What are the benefits ?

It is complicated. The thread is how I realize the process and it is for developers. Developer for other phones can port it to their devices.
Actually, the process for MultiROM is even more complicated.

I am writing something to simplify it. Just like what MultiROM did.
e.g.
1. A rom switcher and image creation apk. Not very difficult to realize.
2. Linux script to modify kernels and updater-script. (Already done. Look at the first post.)
3. Something else which benefits the simplification.

Benefits:
1. It use images for system, data, cache partitions, which is cleaner.
2. It do not mess up the first rom and we need no modification to the first rom.
3. It does not need kexec support. (I think kexec is just to realize the rom selection when booting, but not very sure.)
4. It is compatible to all roms.

However, the project may not be used by many people But it worth trying it and sharing to others.
The Following 3 Users Say Thank You to dlhxr For This Useful Post: [ View ]
25th August 2014, 10:30 AM   |  #6  
Junior Member
Thanks Meter: 0
 
17 posts
Join Date:Joined: Aug 2014
seems a bit long winded to me, I'll stick to multiROM
25th August 2014, 04:41 PM   |  #7  
droidrev71's Avatar
Senior Member
Thanks Meter: 159
 
825 posts
Join Date:Joined: Sep 2010
More
Quote:
Originally Posted by rocker1904

seems a bit long winded to me, I'll stick to multiROM

little bit of a backhanded comment!?!?!..unreal! if you would have read up he's going to simplify it.
31st August 2014, 09:18 PM   |  #8  
Recognized Contributor
Flag Aachen
Thanks Meter: 968
 
2,470 posts
Join Date:Joined: Apr 2012
More
@dlhxr... Is it possible to multiboot 4.4 based ROMS with 4.3 based ones with this? It is the only feature I miss from Multirom, so maybe I'll give this a go!
1st September 2014, 11:47 AM   |  #9  
dlhxr's Avatar
OP Senior Member
Flag Shenzhen
Thanks Meter: 114
 
292 posts
Join Date:Joined: May 2011
More
Quote:
Originally Posted by dansou901

@dlhxr... Is it possible to multiboot 4.4 based ROMS with 4.3 based ones with this? It is the only feature I miss from Multirom, so maybe I'll give this a go!

definitely.

All roms are supportted only if you know well about my modification~

I successfully modified color os based on 4.3 in to image boot, even though the kernel of color os is a little complicated than everyone imagin

The Following User Says Thank You to dlhxr For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes