[Samsung Epic 4G Touch] kobridge:
How to run init.d scripts on Boot- 4/26/12

Before starting this guide, I'd like to say "thanks to many Devs" on this forum.

[Update] sfhub just added init.d support function into his auto root tool at http://xdaforums.com/showthread.php?t=1342728

If your kernel does not support init.d, then use his tool to add init.d support without flashing a new kernel.

Just in case you only want to have a script which invoke the init.d scripts, check the second post in this thread.

4/29/12 sfhub improved his auto root tool to support some other kernels, those are enabling init.d through different .xc files.

Stock kernels and some repacked kernels are supporting init.d scripts through init.xc and/or install-recovery.sh but some other repacked kernels are supporting init.d scripts running through different .xc files. So, sfhub made some modification on his script. Because he's adding a new install-recovery.sh file into /system/etc folder, if there's a existing install-recovery.sh file at the same location, the existing install-recovery.sh file will be replaced by his previous version of Auto Root Tool. To prevent the replacing existing install-recovery.sh file with his same named install-recovery.sh file which supports the init.d scripts, his tool now creates a copy of old file and create a new one. Old install-recovery.sh file will be named as install-recovery-orig.sh.

If you just want to simply enable init.d support without using sfhub's tool, then download the new-install-recovery.zip file from my second post and unzip it. If there's any existing install-recovery.sh file and it's not related to init.d support, then rename it to install-recovery-orig.sh and move the unzipped file to same directory (/system/etc). Assign the file permission 550 (r_xr_x___). New install-recovry.sh file will execute the init.d scripts (if it's there) and old install-recovery-orig.sh (if it's there) during the boot.

4/30/12 I've modified his install-recovery.sh file (new-install-recovery.zip, attached) to use the default busybox command. If you don't have busybox installed on your phone, you will also need to download attached busybox.zip and unzip, place into /system/xbin folder with permission 755.

Update2 I'm uploading my tweaks again. Based on my test, this tweak works much better and extended my battery life a lot more. In this battery tweak, the max cpu speed would set to 1000000, but normally it would run with 800000 or less. Based on my test, this works great and no fc, no random reboot. If you really want to extend your battery life, then test your battery life with this tweaks. (tweak file is attached in second post). My test was done under FD19 and FD24 Stock Roms

Update3 Found that Camera app kept freezing, fc, and made system reboot if max CPU frequency is set to under 1Ghz. So because of this app, had to keep max cpu speed to 1Ghz when the phone is in awake mode. Uploading new tweak files.

Upon his tools update, my guide in here would be only for some limited people who just want to test the scripts or want to selectively run the scripts during the boot. For example, if you have 10 scripts in init.d and just want to selectively run from those, you can use SManager.

Issue: /system/etc/init.d scripts does not run automatically during the boot

Details:

Rogue Repacked Kernels are started supporting init.d scripts during the boot and many custom roms are now including the scripts in /system/etc/init.d. But usually repacked kernel is not ready when the new rom comes out and we need to use old version of repacked kernel to get the init.d support.

How to test: (only applicable to the phones having Repacked Kernel and supporting init.d scripts. For the stock kernel, I’ll explain it later how to run it during the reboot)

It seems like Rogue Repacked kernel allows the init.d script running thru /init.rc. init.rc file is part of bootimage and this file is over-written everytime when the system reboots. So, editing this file is not possible. Only the way editing this file would be by extracting bootimage and making modification, repact the kernel image.

Running the init.d script from init.rc is,

(FD02)

# Run init.d scripts

service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d

class main

user root

group shell

oneshot

(before FD02)

# Run init.d scripts

service sysinit /system/bin/logwrapper /sbin/run-parts /system/etc/init.d

class main

user root

group shell

oneshot

So, if you are not sure whether a script in /system/etc/init.d is running on boot, you can simple add a script into this directory.

Create a script using text editor in root explorer (don’t use ES File Explorer to edit the file). The character set used in es file explorer causes a problem to run the script. This is very important thing to remember. Even syntax and everything looks correct but the script would not run if it includes some hidden character which is not supported by shell. Be sure to use the editor supported by the shell.

Example)

Create a file 0test into /system/etc/init.d

#!/system/bin/sh

touch /data/local/tmp/initd_test.txt

echo "Hello Android" > /data/local/tmp/initd_test.txt

File permission is 755.

If there’s some scripts in /system/etc/init.d, then backup those files to your sdcard for later use. Sometimes, it’s hard to find the script running result and that’s the reason why I’m testing it by simply writing a file.

If you are done with creating a file, reboot your phone and go to the /data/local/temp directory.

If the initd_test.txt file is there and content is “Hello Android”, then it means that any other scripts in the init.d directory will be executed during the boot and you don’t need to follow this guide any more.

Workaround to run the init.d scripts during the boot:

This workaround is nothing to do with Repacked or stock kernel. In another words, this workaround would work on both repacked and stock kernel.

[Update] Again, if you don't need to test the scripts and only want to run someone else's tested script, then you can simply use sfhub's auto root tool to add the init.d support option.

What you need:

Download Script Manager – Smanager app from Google play store (it’s free) and install it.

https://play.google.com/store/apps/details?id=os.tools.scriptmanager&hl=en

You must have busybox installed and have su permission.

Steps to test the existing scripts:

1. run Script Manager and open 0test script. Click the su icon and run.

2. SManager will show the ‘exit code’ and any messages from the script. Be sure that you got the exit code ‘0’.

3. Go to the directory /data/local/temp and check if file is create and has ‘Hello Android” in it.

SManager is a great tool to verify the script syntax or any errors during the run. So if you have any init.d scripts, you can test those scripts before you start to run during the boot (this may prevent any boot loop or any issue).

How to run the scripts during the boot using SManager:

Steps to run the scripts during the boot:

1. Test the scripts out completely before start to run on boot.

2. From the SManager tool, select su and boot icon. Exit the application and reboot the phone.

3. If you did not change the SManger config, then you will see the SManager log after the boot. Check if everything is fine. If the scripts run OK many times without any issue, then you can uncheck the option showing SManager log after the boot.

This tool is great because you can run the scripts on both stock and repacked kernel. Also, you don’t need to put the scripts into /system/etc/init.d. You can place those files in any locations.

Using this tool, currently I’m running Calk’s init.d tweaks without any problems.

Calk’s tweaks are included in his FD02 Rom.

My current phone is

D710 + FD19 Stock Kernel + FD19 Rom + FD19 Modem with init.d scripts running

** This is an initial version and I’m going to add some more stuff in this thread. If you like this info and if this info is helpful for you in any way, please leave your feedback and consider to buy me a beer! **:D:D

** Because of sfhub's great job, it seems like I'm done in here. I hope you had enough information that you wanted **