[HTC One X] Headless96:
How to make your own init.d script​

Hey fellow XDA users!​

I'm creating this thread as I've seen a countless number of times the same question asked (literally hundreds)

'How to I set (_____) on boot?'​

Finally I have come around to answering that question! This thread will allow you to control system/kernel parameters on boot

Now many of the kernel devs around the HOX forums have created some pretty epic kernels with tons of features which can be modified as much as the user wants and now I'll be showing you how to set these parameters on boot without the use of apps! :laugh:

Requirements

Rooted

Busybox

Custom Rom with Init.d Support (Most custom Rom's, check in OP of Rom thread)

A Root File Explorer (We're going to do this through the phone)

Stock ROM does not support init.d

If you're on a stock rom, you can easily add init.d support using Ryuinferno's very very helpful thread!

Enable Init.d Support

Once you've done that, come back and follow the instructions :D

Now to begin, let's look at a typical init.d script

#!/system/bin/sh

#CPU
echo pmc > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

#Smart Dimmer
echo 1 > /sys/devices/tegradc.0/smartdimmer/enable

#Fast Charge
echo 1 > /sys/devices/platform/htc_battery/fast_charge

#S2W
echo 1 > /sys/android_touch/sweep2wake

OK, now to a new user this may seem quite confusing but once broken down it can be easily understood:

#!/system/bin/sh = This is required at the start of every init.d script

echo .... = Sends the command

'<insert value here>' = You can put a value after 'echo' and it will send that value to the file you have shown the path to, e.g. 'echo 1 >...'

>/.... = Specify the path and file in which to change on boot

So for example if I put this in my script:

echo '1' > /sys/devices/system/cpu/cpu0/cpufreq/gpu_voltage

I am changing the file 'gpu_voltage' to 1, allowing gpu voltage to be enabled on boot (currently only XM's & Alex-V's kernel)

Similarly with the command:

echo '0' > /sys/class/leds/button-backlight/auto_bln

I am disabling auto-bln on boot

Hopefully after you've read all of that, you've understood a little more about init.d scripts

Now let's actually create some scripts :cool:

Instructions​

We'll be using a file explorer on Android since Window's editors don't format the text correctly

1. Create a file using your choice of file explorer, I'm using Root Explorer and put it in /system/etc/init.d/

2. Open the file and write the following into it:

#!/system/bin/sh

3. Then choose which file you want to modify on boot and what value you want to change it to, and write the echo command and path into the file

For example: echo interactive > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor - (for interactive governor on boot)

echo 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq - (for 1.2ghz on boot)

Now there's some things to look out for when doing this:

• You need to make sure you're pointing to the file not just folder when entering the path in '> /....'

• You need to make sure you put the spaces in the right places and don't put any spaces in random places

• When entering multiple values you need to put the values in quotation marks like this "....." - so for example if I want to set max GPU speed I would do this:

echo "416 416 416 416 304 304 247 247" > /sys/devices/system/cpu/cpu0/cpufreq/gpu_oc

• Also if you put a '#' in front of the line of text then it ignores that line, as you can see in my example I have a line that says '#CPU'. This is just to tell me I'm making modifications to the CPU and so I put a # in there so that line is ignored (the echo command below it is still carried out)

• You can do all the commands in one script and do as many as you like!

The various parameters that can be controlled are most likely on the OP's of the respective kernel threads (it would be ridiculously long if I were to put them all in this thread)​

4. Once you're done, save and exit the file

5. Then rename it with a number in front, this number will decide which init.d script will run first (lower the number the earlier it's run on boot)

So for example I named my file: 25kerneltweaks

It doesn't really matter what number you put but just make sure there's no other scripts running after which will also change kernel parameters (leave them but just give your script a higher number)

Almost done now!

6. The final thing you have to do is set permissions:

Now you won't be able to use ES File Explorer for this step as it just can't set the right permissions for init.d scripts for some odd reason, preferably use Root Explorer but others should work (except ES)

Set permissions as rwx-rwx-rwx (shown in the image)

If you don't have Root Explorer or a good substitute you could also do this through terminal emulator:

To do that enter this into emulator (press enter after every line)

su
chmod 777 /system/etc/init.d/insertfilenamehere

And permissions should be set

​

And that's pretty much it folks :)

You have successfully created your own init.d script!

Many people prefer this method as you don't require apps to set stuff on boot, now it'll just be done automatically for you :good:

Btw this will work on any android device, so if your a wandering googler (is that even a word :p) searching for a guide like this, it should work on your phone/tablet as long as you fulfill the requirements

Hope you guys found this useful, it's the first thread I've made so sorry if it's a little rough around the edges and

Press thanks if I helped and please rate the thread, I'd greatly appreciate it! :D