[HTC Pico (Explorer)] thewisenerd:
Everyone's a newbie (unless they remain to stay a n00b). Anyways, let's get back to on-topic.

So... How does these files in

/system/init.d/<insert-script-name>

cause the reverse-mount?

For this, we look back, into the init.rc and init.pico.rc files :D

If you'd read this, https://android.googlesource.com/platform/system/core/+/master/init/readme.txt, you'd find that the Android Init Language gives you an "exec" command for running apps/scripts. So, you should have gotten the hint by now ;)

So, open up init.rc and search for any "exec" command. I can just make it easier, but I want you to find any "exec" call that runs processes from /system/*.

OFC, I'd be telling the answer below, but I want you to find it too ;)

So, here's the key. You're likely to find lines as the same as, or similar to below lines:

# Run sysinit
exec /system/bin/sysinit

in any one of the *.rc files (mostly init.rc or init.pico.rc).

So, lets take a look at this file.

Below is the above file (/system/bin/sysinit) from CM10.2, weekly 9 :D

#!/system/bin/sh

export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
/system/bin/logwrapper /system/xbin/run-parts /system/etc/init.d

So, what's this, exactly?

Linux users would be familiar with the PATH variable name ;)

And, logwrapper? Here's standard help:

Usage: logwrapper [-d] BINARY [ARGS ...]

Forks and executes BINARY ARGS, redirecting stdout and stderr to
the Android logging system. Tag is set to BINARY, priority is
always LOG_INFO.

-d: Causes logwrapper to SIGSEGV when BINARY terminates
fault address is set to the status of wait()

So, its going to execute a binary file, but which?

The next "argument" reads "/system/xbin/run-parts"

Again, here's standard help:

BusyBox v1.20.2-cm9 bionic (2012-11-18 13:31 +0100) multi-call binary.

Usage: run-parts [-t] [-l] [-a ARG] [-u MASK] DIRECTORY

Run a bunch of scripts in DIRECTORY

-t	Print what would be run, but don't actually run anything
-a ARG	Pass ARG as argument for every program
-u MASK	Set the umask to MASK before running every program
-l	Print names of all matching files even if they are not executable

So, run a bunch of scripts in a directory?

That pretty much explains why the next "argument" follows as "/system/etc/init.d ".

So, that's how init.d works :cyclops:

============================================================================================================

Now, moving on to memory increasing scripts (oh! I hate that slang)

Anyways, so, we found out that during the boot, the init.rc file is calling the /system/bin/sysinit file. If you'd notice, a few lines "above",

Here's something from http://www.kpbird.com/2012/11/in-depth-android-boot-sequence-process.html

Below is the sequence of android booting. Note that until all these processes are completed, you still see the boot logo. So, if your phone's struck at green htc screen, then, any one of this processes is.. hung.

on early-init:

Set init and its forked children's oom_adj.

Set the security context for the init process.

on init

setup the global environment

Create cgroup mount point for cpu accounting and many other things...

on fs

mount mtd partitions

on post-fs

change permissions of system directories

on post-fs-data

change permission of /data folders and sub folders

on boot

basic network init ,Memory Management ,etc

service servicemanager

start system manager to manage all native services like location, audio, shared preference etc..

service zygote

start zygote as app_process

So, the "/system/bin/sysinit" runs at the "boot" service. Also, it is run by the bootloader. So, it has full access to the root file system that the ramdisk creates. Now, to be noted: the "boot" service runs after the "fs" service, evidently, because else, you wouldn't be able to access the "/system/bin/sysinit" otherwise.

So, the "sysinit" script runs, running all the files from /system/etc/init.d with the help of busybox :D

That's about it ;)

But, how does the reverse-mounting take place!?

Let me take the example of the simplest reverse mounting script I've ever found: int2ext. I've seen the mounts2sd script, and think its bloated, IMO, because why have a 1000+ lines script, when a script with >40 lines can do it :angel: ) (no offense). For me, just placing script, setting permissions, rebooting should increase the memory of my device. No roundabout stuff.

So, I'd be explaining how int2ext works, below:

Note: before you proceed, you'd have noticed that the sysinit file set the PATH variable. Its the location for all the accessible binary files. (if you don't understand this, using linux might help you understand this better ;) ) This is similar to the PATH variable in windows too.. This just tells the system where to look for executable binary files/programs.

So, here's a very minimal int2ext script (modified to make this post smaller):

The purple lines ("Royal Blue" according to XDA), are the lines of code. Rest are my comments.

Credits go to original file, got from here: https://github.com/croniccorey/cronmod-scripts/blob/master/int2ext%20scripts/INT2EXT

the comments should explain almost everything...

This script, is almost flawless. Couldn't find any bugs in it. Does what would have been done by changing the mount point in the "on fs" part, where it mounts the file system.

An added advantage is that this can be put into use any time you want... Example, you use your phone, internal memory gets filled up, just put this script in /system/etc/init.d, and set permissions, and reboot! voila! memory increased!

Note: reversing this can't be done by just deleting the script. an appropriate script that moves back user data to internal partitions may be needed.

Also note:

You can always tweak this command:

busybox mount -o noatime,nodiratime,nosuid,nodev /dev/block/mmcblk0p2 /data;

for better performance. Check my config, in post 8 or so... 1'st page..

You should've also guessed why we set permissions to executable, by now... Else, the file wouldn't be able to "execute" :p

P.S. Adding a few lines to init.rc should make it possible to have no permission change, but, that can wait for another day...