FORUMS

Dual-Boot: SD Card & Internal ROM by Modifying Initramfs

32 posts
Thanks Meter: 27
 
Post Reply Email Thread
HI there! Just wanna share about things I've done some time ago..

Background...
I'm interested with ROM development & testing, but.. Ace 2 is my only primary phone which I really need for school things, poking friends *woah* and.. etc. Actually, I can make a CWM backup, flash the ROM and restore the backup after testing. But... seriously! It takes quite lot of time and... yeah.. since I'm testing ROM, I'll keep flashing & reflashing my phone and I get a little worried about its internal memory if I do it too often. So, I decided to make something that let me boot new ROM which I flash on the SD card & switch back to the previous ROM with just a simple reboot.. Yeay!

How it works?
I accomplished my goal by using modified initramfs which run after the kernel initialization and before any of Android system get loaded. It will mount 2nd partition of the SD card. If it find a file named enable_sdboot inside, it will decompress SD ROM's ramdisk.cpio which is stored in that partition, then boot the SD ROM. It will also delete enable_sdboot file immediately after checking, so internal ROM will get booted in next reboot.

Important notes:
  • SD ROM's ramdisk.cpio must contains modified fstab & some of .rc files, so it won't touch the internal ROM.
  • Kernel modules are placed on initramfs (/lib/modules), so it'll be easier to change ROMs or the kernel itself.
  • Limitations: because initramfs is compiled with the kernel, so internal & SD ROM will boot using same kernel.

Preparations

Prepare the Kernel
If you want to use stock ROM (codina) as ur internal ROM & CWM as ur recovery, you can use my precompiled kernel: codina-ace2nutzer-sdboot-stock-unsigned.zip which you can flash via CWM. If you use other internal ROM, you have to compile the kernel by yourself. If you're building Android ROMs, you can add my repo: nieltg/codina-initramfs-sdboot to your local manifest and read this guide. You can also take a look at this repo: nieltg/android_device_samsung_codina as an example.

If you build an out-of-tree kernel, you can follow these steps:
  • Create a folder named codinaramfs_dir in your kernel source.
  • Extract my initramfs intermediate: codina-sdboot-intermediates.zip to folder you've just created.
  • Replace boot.cpio with ur internal ROM ramdisk, so you can boot into it. You can also replace recovery.cpio with recovery system you would like to use.
  • Configure ur kernel & execute scripts/config --file .config --set-str CONFIG_INITRAMFS_SOURCE codinaramfs_dir/initramfs.list.
    NOTE: .config is generated in output directory after configuring. If you change the output directory, you should modify the command before executing.
  • Compile and execute make INSTALL_MOD_PATH=codinaramfs_dir/modules modules_install to put modules in codinaramfs_dir/modules.
  • Modify codinaramfs_dir/initramfs.list to include all kernel modules in codinaramfs_dir/modules.
    NOTE: I've specified the details in codinaramfs_dir/initramfs.list itself.
  • Then, recompile ur kernel.

Prepare an SD ROM & ur Device
You have to repartition ur SD card to store ur SD ROM. You also have to modify any ROM you want to install into ur SD card. ROM in SD card should not touch internal ROM. It should work independently. So, there are some modifications you must apply. There are things which you must ensure:
  • Any flashable zip you apply for the SD ROM extracts to SD partitions instead of internal.
  • Kernel is not going to be replaced after flashing any flashable zip.
  • SD ROM mounts appropriate SD partitions instead of internal partitions.
  • SD & internal ROM look for kernel modules in /lib/modules.

You can read this guide to prepare an SD ROM & ur device, to be exact, ur SD card.

----------

Well.. this is not good enough. You have to understand Linux, shell commands, compilation process, etc to apply this idea correctly. But of course if you're interested, you can help me improve this. Sorry for my English, I'm still studying. And like usual, I'm not responsible if you brick your phone, void your warranty, or any other pain or suffering you may feel as result of applying my idea. You do it all at your own risk!

Thanks to: @ace2nutzer for ur kernel, @Rox & @jereksel for the CWM I took from ur repo, @ishtiaque9 for ur support, everyone who interested with my idea & everyone..
So, anyone interested with my idea?
The Following 10 Users Say Thank You to nieltg For This Useful Post: [ View ] Gift nieltg Ad-Free
25th March 2015, 09:08 PM |#2  
Senior Member
Flag Offenburg
Thanks Meter: 204
 
Donate to Me
More
Seems great to run cm11 and cm12 at the same time
3rd April 2015, 04:53 PM |#3  
ace2nutzer's Avatar
Recognized Developer
Flag Cologne
Thanks Meter: 4,131
 
Donate to Me
More
Thumbs up
Very grateful idea !!

Good that i've a sd 32gb Class 10 card.. so i can test finally CM12 from sdcard ... very nice job !
5th April 2015, 01:35 PM |#4  
OP Member
Flag Jakarta
Thanks Meter: 27
 
More
I'm glad to know my idea is being helpful!

@ace2nutzer woow! that's really big!
Actually, I'm using 2 Gb SD card which speed is 2x slower than the internal memory.. (tested using dd)
Quite slow.. but at least, it works.. but now i'm confused.. Is it slow because of the SD or because of my build? hahahaha
5th April 2015, 02:29 PM |#5  
ace2nutzer's Avatar
Recognized Developer
Flag Cologne
Thanks Meter: 4,131
 
Donate to Me
More
Quote:
Originally Posted by nieltg

I'm glad to know my idea is being helpful!

@ace2nutzer woow! that's really big!
Actually, I'm using 2 Gb SD card which speed is 2x slower than the internal memory.. (tested using dd)
Quite slow.. but at least, it works.. but now i'm confused.. Is it slow because of the SD or because of my build? hahahaha

Depends on class of sdcard.. Mine is class 10 = 10mb/s write speed. Read is as usual faster.. For me: 15 - 20 mb/s.

So u've probably only class 4 or 6.

The emmc in the Phone is class 10.

But of course a kernel can make it a bit faster or slower.. Depends on used config.

With my latest build + read_ahead_kb @ 512kb (writed on ramdisk on device_tunables) i've on ext. Sd card + emmc approxx. 12mb/s write speed

BTW: our Phone supports also 64gb cards.. And maybe even more...
5th April 2015, 02:31 PM |#6  
Member
Thanks Meter: 45
 
More
This is a great idea ! I also need a dual boot stock / carbon (stock ROM includes eap sim and some other things I need)
What changes have to be made to use it on codinap (NFC) ?

Sent from my GT-I8160P using XDA Free mobile app
6th April 2015, 12:25 PM |#7  
shoxieJESUS's Avatar
Senior Member
Flag Vitebsk
Thanks Meter: 102
 
More
Really good idea, i think need to make an app, which can switch roms.
Maybe this sources will be usefull.
6th April 2015, 03:26 PM |#8  
OP Member
Flag Jakarta
Thanks Meter: 27
 
More
Quote:
Originally Posted by ace2nutzer

Depends on class of sdcard.. Mine is class 10 = 10mb/s write speed. Read is as usual faster.. For me: 15 - 20 mb/s.
So u've probably only class 4 or 6.
The emmc in the Phone is class 10.
But of course a kernel can make it a bit faster or slower.. Depends on used config.
With my latest build + read_ahead_kb @ 512kb (writed on ramdisk on device_tunables) i've on ext. Sd card + emmc approxx. 12mb/s write speed
BTW: our Phone supports also 64gb cards.. And maybe even more...

Hey.. I found something weird! I'm testing my storage with dd if=/dev/full of=tmp.file bs=1024576 count=10 in my cm-12 (sdboot) & I get:
  • 7.5 Mb/s in /storage/sdcard1 (SD card)
  • 27.55 Mb/s in mmcblk1p3 (SD card data partition)
  • 85.47 Mb/s in mmcblk0p5 (internal data partition)

Hmm.. maybe the kernel caching mechanism that make it really fast?
Btw: I'm using ur kernel (commit d67aa9f) with audit enabled & sdboot modification

Quote:
Originally Posted by Mavireck

This is a great idea ! I also need a dual boot stock / carbon (stock ROM includes eap sim and some other things I need)
What changes have to be made to use it on codinap (NFC) ?

You should compile a kernel by yourself..
If you develop ROMs, you can include my repo in ur local manifests, modify boot.img (you can extract files from ur stock ROM) & compile to get an sdboot kernel.
If you're building out-of-tree kernel, I'm going to write a guide for it in the first post..

Quote:
Originally Posted by Kirya12347

Really good idea, i think need to make an app, which can switch roms.
Maybe this sources will be usefull.

Hmm.. actually, I'm not really sure about that..
If you use this sdboot idea, all you have to do is write a file named enable_sdboot in 2nd partition of ur SD card to switch ROM.
For now, I'm using Terminal Emulator for that.. but it'll be nice to have a simple app which can do that in a single tap..
6th April 2015, 05:13 PM |#9  
shoxieJESUS's Avatar
Senior Member
Flag Vitebsk
Thanks Meter: 102
 
More
@nieltg
Why modified kernel not in archive. I download it without any expansion.
P.S. Sorry for bad eng.
6th April 2015, 11:13 PM |#10  
OP Member
Flag Jakarta
Thanks Meter: 27
 
More
Quote:
Originally Posted by Kirya12347

@nieltg
Why modified kernel not in archive. I download it without any expansion.
P.S. Sorry for bad eng.

Actually, I just need to modify its initramfs, but initramfs is compiled with the kernel in codina.
So, I have to recompile the kernel to modify the initramfs.. Hmm.. what archive? Could you tell me more specific, please?
7th April 2015, 05:56 AM |#11  
shoxieJESUS's Avatar
Senior Member
Flag Vitebsk
Thanks Meter: 102
 
More
Quote:
Originally Posted by nieltg

Actually, I just need to modify its initramfs, but initramfs is compiled with the kernel in codina.
So, I have to recompile the kernel to modify the initramfs.. Hmm.. what archive? Could you tell me more specific, please?

I mean kernel isn't in flashable zip. It look , for exapmple, like init.d script, without any expansion
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes