[MOD][MultiBoot]Image Rom Boot under Custom Kernel - ONE Android Development

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.
View attachment 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/)
View attachment 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:
[COLOR="Red"]#[/COLOR]/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,barrier=1 wait
/dev/block/platform/msm_sdcc.1/by-name/userdata /[COLOR="Red"]r[/COLOR]data ext4 noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer,length=-16384
[COLOR="Red"]#[/COLOR]/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 /[COLOR="Red"]r[/COLOR]data/media /mnt/shell/emulated
class late_start
8.Extract the busybox binary from attachment to output/ramdisk/sbin/
View attachment 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/)
View attachment 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");

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");

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.

That's so much more complicated than multirom ... And this needs a custom kernel too
What are the benefits ?

bud77 said:
That's so much more complicated than multirom ... And this needs a custom kernel too
What are the benefits ?
Click to expand...
Click to collapse
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.

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

rocker1904 said:
seems a bit long winded to me, I'll stick to multiROM
Click to expand...
Click to collapse
little bit of a backhanded comment!?!?!..unreal! if you would have read up he's going to simplify it.

@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!

dansou901 said:
@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!
Click to expand...
Click to collapse
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

Related

Flashable zip help

I decided to give this a try.
Its a very simple flash and I guess an easy beginner task.
All I'm doing is adding S_opener.ogg to the notifications directory.
It's not in FJs AOSP rom and I just want to flash it after flashing his updates.
I found a tool that makes creating the zip pretty easy AFAIK
http://forum.xda-developers.com/showthread.php?t=1248486
I want to mount the system, copy the file, unmount.
The default script is below.
I have three questions before I create and flash this....don't wanna brick it
1)What's our mount point?
2)On the extract directory, can I use the parent like it is or do I have to specify by drilling down? (/system/media/audio/notifications)
3)Does it unmount? Is that part of the extract command?
THANKS!
Here's the script:
ui_print("Preparing to update");
# mounting system as r/w - ATTENTION - set the the mount point
# to the proper for your device! Example mountr command is
# mounting system for Samsung GT-I5800 aka Galaxy 3
mount("/dev/block/stl6", "system", "/system", "rw");
ui_print("Copying....");
# copy system content to the system directory on your device
package_extract_dir("system", "/system");
ui_print("Done! You can reboot your system now!");
Cool project. Good luck.
Yea. I thought it would be a cool way to get a better idea of what it takes for these developers.
Any developers able to lend me a hand here?
I think my questions are clear....
I'd appreciate it.
Thanks!
Why not team up with Jessooca. She wants to learn too. Plus I think she will get more attention than you.
1) I find it easiest to use the "busybox" mount
-- this will always be compatible with just about any custom ROM. (no need to know the mount partition)
2) Yes, just use the parent directory
3) No, it doesn't unmount automatically (not that it really needs to anyway)
If copying system apps, you can also save some time by wiping dalvik-cache and rebooting right here in the script.
Here is a generic script good for just about anything you might want to throw into system/
Code:
ui_print("Updating System...");
show_progress(0.1, 0);
ui_print(" ");
run_program("/sbin/busybox", "mount", "/system");
package_extract_dir("system", "/system");
run_program("/sbin/busybox", "umount", "/system");
ui_print(" ");
ui_print("Wiping Cache & Rebooting...");
run_program("/sbin/busybox", "mount", "/data");
delete_recursive("/data/dalvik-cache");
run_program("/sbin/busybox", "umount", "/data");
run_program("/sbin/reboot");
Hope this is helpful for you
Thanks! I found busy box in xbin. I also looked at fjs rom script and that's what he uses. I'll give it a shot
Sent from my SAMSUNG-SGH-I717 using xda premium
Bummer. I feel like I'm so close...
I have flashed three times and luckily no side effects but the file isn't there....
sbin doesn't have busybox in it but system/xbin does
So I did this:
Code:
ui_print("Preparing to update");
ui_print("Updating System...");
show_progress(0.1, 0);
ui_print("Coying Opener Notification");
run_program("/system/xbin/busybox", "mount", "/system");
package_extract_dir("system", "/system");
run_program("/system/xbin/busybox", "umount", "/system");
ui_print(" ");
ui_print("Done! You can reboot your system now!");
And that doesn't work either...
The cool thing is that I'm learning quite a bit with all these failures
That's why I chose a 'simple' task
Tried this to but it didn't work.
It flashed and said it went but the file isn't there....
Guess I'll try again tomorrow.
Code:
ui_print("Preparing to update");
ui_print("Updating System...");
show_progress(0.1, 0);
mount("/dev/block/mmcblk0p24", "system", "/system");
ui_print("Copying files Opener Notification");
package_extract_dir("system", "/system");
unmount("/system");
ui_print("Done! You can reboot your system now!");
You see /system/xbin/busybox while booted normally; however
when booted in recovery it sees /sbin -- trust me on this.
If you still want to use standard partition mounting try this:
Code:
mount("ext4", "EMMC", "/dev/block/mmcblk0p24", "/system");
Thanks for your help on this. I'll try sbin today. I trust ya
I did try that string but it threw an error and said I had four variables and it only wanted three.
Sent from my SAMSUNG-SGH-I717 using xda premium
hmm yeah well I just plucked that one out of a ROM installer
the /sbin/busybox mount has worked well for me over lots of zip and lots of different ROMs
Yep, that did it! Thanks
My first successful zip
Now to figure out how to make that the default notification.
It looks like it's in the build.prop but I haven't searched enough on xda yet.
I found the default notification for the ROM in build.prop but can't find where the current default notification is.
Is that in a file similar to build.prop?

Clear data and system in updater-script w/o clearing sdcard?

Every time I flash a ROM I'm playing with, using the clear data options I added, it clears the sdcard too?
I'm using this code with the AROMA installer:
Code:
# Clear Data
if file_getprop("/tmp/aroma/clear.prop","selected.1") == "1"
then
ui_print("@Wiping Data...");
delete_recursive("/system");
delete_recursive("/data");
delete_recursive("/preload");
endif;
ui_print("@Clearing Cache and Dalvik...");
delete_recursive("/cache");
delete_recursive("/data/dalvik-cache");
delete_recursive("/dalvik/dalvik-cache");
The only instance of format I have is here:
Code:
format("ext4", "EMMC", "/dev/block/mmcblk0p9", "0");
mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p12", "/data");
mount("ext4", "EMMC", "/dev/block/mmcblk0p7", "/cache");
run_program("/sbin/mount", "/dev/block/mmcblk0p12", "/dalvik");
run_program("/sbin/busybox", "mount", "/sdcard");
Which is confusing me a lot
Bump
Can someone please shed some sort of light as to why this deletes the contents of the SD card?
Is it possible to clear system and data within an updater-script WITHOUT killing my internal sd card?
I think its the
Code:
delete_recursive("/preload");
line thats doing it - i don't have that line, neither do any of the other Roms updater scripts that ive looked at
Remove it and see what happens
MattBooth said:
Every time I flash a ROM I'm playing with, using the clear data options I added, it clears the sdcard too?
I'm using this code with the AROMA installer:
Code:
# Clear Data
if file_getprop("/tmp/aroma/clear.prop","selected.1") == "1"
then
ui_print("@Wiping Data...");
delete_recursive("/system");
delete_recursive("/data");
delete_recursive("/preload");
endif;
ui_print("@Clearing Cache and Dalvik...");
delete_recursive("/cache");
delete_recursive("/data/dalvik-cache");
delete_recursive("/dalvik/dalvik-cache");
The only instance of format I have is here:
Code:
format("ext4", "EMMC", "/dev/block/mmcblk0p9", "0");
mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p12", "/data");
mount("ext4", "EMMC", "/dev/block/mmcblk0p7", "/cache");
run_program("/sbin/mount", "/dev/block/mmcblk0p12", "/dalvik");
run_program("/sbin/busybox", "mount", "/sdcard");
Which is confusing me a lot
Click to expand...
Click to collapse
Such an old thread, just trying my luck.
How were you able to run the function "delete_recursive" in updater-script?
I dont see it as part of the official functions list.
Nikil07 said:
How were you able to run the function "delete_recursive" in updater-script?
I dont see it as part of the official functions list.
Click to expand...
Click to collapse
Write such a function at your own
Syntax
delete_recursive <file-or-dir1> [... <file-or-dirN>]
Example
Code:
delete_recursive()
{
for d in "[email protected]"; do rm -rf "$d" 2>/dev/null; done
}
jwoegerbauer said:
Write such a function at your own
Syntax
delete_recursive <file-or-dir1> [... <file-or-dirN>]
Example
Code:
delete_recursive()
{
for d in "[email protected]"; do rm -rf "$d" 2>/dev/null; done
}
Click to expand...
Click to collapse
Hey, thanks for the response.
But how will I be able to run these functions as part of the updater-script?
And also, regular unix commands like ls, rm are not available in recovery.
1. You add these lines of code to the very beginning of the updater script, but after the line #!/sbin/sh or similar one
2. Recovery ( at least the Stock Recovery ) merely is a menu what offers you some options, it's not an Android terminal

[Q] [RECOVERY][ZIP]script lines for copy, move, rename files.

So as I see in a flashable zip there is:
META-INF\com\google\android\
where you have updater-script.
Mine contains this:
ui_print("text_to_write");
run_program("/sbin/busybox", "mount", "/cache");
run_program("/sbin/busybox", "mount", "/data");
run_program("/sbin/busybox", "mount", "/system");
ui_print("");
package_extract_dir("cache", "/cache");
package_extract_dir("data", "/data");
package_extract_dir("system", "/system");
unmount("/cache");unmount("/data");
unmount("/system");
ok, basically this mounts the cache, data, system partition.
Now I want to do something like:
got a file in /system/media/sounds/ui/lock.ogg
I want it to rename it to /system/media/sounds/ui/lock.ogg.back
as I searched the forum, I need to run a bash script, something like:
for file in *.html; do
mv "$file" "`basename $file .html`.txt"
or simply
mv Lock Lock_old
now my question
what to write in update script to rename these files before copying the actual files.
What to write in the the update-script to run the bash.
as I understand I should paste a new line
run_program("/sbin/busybox", "mount", "/system");
ui_print(""); <-right here the script line
package_extract_dir("cache", "/cache");
the main goal is this:
copy for example Lock.ogg to system/media/ui/
but before copying rename the existing Lock.ogg to Lock.ogg.back or Lock_old.ogg.
Please help

[Q] [EDIFY] Why is this wrong (found in CM12 build)?

Why won't updater-binary mount /system? TWRP doesn't give me any helpful errors, apart from:
Code:
unable to mount /system
Here is the code:
Code:
mount("ext4", "EMMC", "/dev/block/platform/dw_mmc/by-name/FACTORYFS", "/system", "");
Older versions of Android worked with this:
Code:
mount("ext4", "EMMC", "/dev/block/platform/dw_mmc/by-name/FACTORYFS", "/system");
But it still gives the same error.
Any help appreciated.
P.S. what's the last argument for?

OTA Script to delete a file

I have a custom device with a custom ROM and I need to be able to delete some files given a certain scenario. I have a script that should delete wpa_supplicant.conf file. The script runs but the file isn't deleted. Here is my script:
show_progress(0.500000, 0);
mount("ext4", "EMMC", "/dev/block/platform/mtk-msdc.0/11230000.msdc0/by-name/userdata", "/data");
delete("/data/misc/wifi/wpa_supplicant.conf");
show_progress(0.100000, 0);
unmount("/data");
-Steve

Categories

Resources