FORUMS
Remove All Ads from XDA

[GUIDE] How To Make An Init.d Script (Noob Friendly)

1,056 posts
Thanks Meter: 2,100
 
Post Reply Email Thread
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!

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

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

Code:
#!/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

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)
Code:
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

Btw this will work on any android device, so if your a wandering googler (is that even a word ) 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!
The Following 77 Users Say Thank You to Headless96 For This Useful Post: [ View ] Gift Headless96 Ad-Free
16th June 2013, 07:07 PM |#2  
DeeZZ_NuuZZ's Avatar
Senior Member
Flag Hanover
Thanks Meter: 4,519
 
Donate to Me
More
now all who have this questions can make their own script every time they ask if somebody else can do -.- ... good guide mate i always do that with smanager :P but some ppl are then confused ._.
The Following User Says Thank You to DeeZZ_NuuZZ For This Useful Post: [ View ] Gift DeeZZ_NuuZZ Ad-Free
16th June 2013, 08:44 PM |#3  
Headless96's Avatar
OP Senior Member
Cardiff
Thanks Meter: 2,100
 
More
Quote:
Originally Posted by One-X-master

now all who have this questions can make their own script every time they ask if somebody else can do -.- ... good guide mate i always do that with smanager :P but some ppl are then confused ._.

Haha thanks man!

I actually only made it because I seen you reply to someone who was asking about scripts on Xmister's thread and I thought 'Damn I'm tired of these questions'

But yeah hopefully people find this useful :thumbup:

Sent from my :tank:
The Following 3 Users Say Thank You to Headless96 For This Useful Post: [ View ] Gift Headless96 Ad-Free
16th June 2013, 09:33 PM |#4  
DeeZZ_NuuZZ's Avatar
Senior Member
Flag Hanover
Thanks Meter: 4,519
 
Donate to Me
More
Quote:
Originally Posted by Headless_monkeyhunta96

Haha thanks man!

I actually only made it because I seen you reply to someone who was asking about scripts on Xmister's thread and I thought 'Damn I'm tired of these questions'

But yeah hopefully people find this useful

Sent from my :tank:

then you know how i'm tired of these questions i hate those simple questions which even are mentioned and also asked in google...i searched in google and found really MANY of those question, for example for scripts etc which are really easy....why not even try in google play? i searched a long time ago...and i found smanager...one of the easiest way to make scripts
The Following User Says Thank You to DeeZZ_NuuZZ For This Useful Post: [ View ] Gift DeeZZ_NuuZZ Ad-Free
19th June 2013, 09:46 AM |#5  
csec's Avatar
Senior Member
Thanks Meter: 685
 
More
Thanks, man. This was really needed.
May I add a link to this in my thread?
The Following User Says Thank You to csec For This Useful Post: [ View ] Gift csec Ad-Free
19th June 2013, 10:23 AM |#6  
Headless96's Avatar
OP Senior Member
Cardiff
Thanks Meter: 2,100
 
More
Quote:
Originally Posted by csec

Thanks, man. This was really needed.
May I add a link to this in my thread?

Yeah sure man

Sent from my :tank:
The Following 2 Users Say Thank You to Headless96 For This Useful Post: [ View ] Gift Headless96 Ad-Free
19th June 2013, 08:56 PM |#7  
Junior Member
Thanks Meter: 1
 
More
Thanks for this thread man!

Was really useful since I didn't like using apps to set my stuff on boot but didn't know how to do it with scripts
The Following User Says Thank You to Rahman2012 For This Useful Post: [ View ] Gift Rahman2012 Ad-Free
21st June 2013, 05:40 PM |#9  
Senior Member
Flag Leek
Thanks Meter: 638
 
Donate to Me
More
Great Guide, well written and presented.

Not for me as I don't program, but great guide non the less !
The Following User Says Thank You to Wilks3y For This Useful Post: [ View ] Gift Wilks3y Ad-Free
23rd June 2013, 05:11 PM |#10  
Headless96's Avatar
OP Senior Member
Cardiff
Thanks Meter: 2,100
 
More
Quote:
Originally Posted by Rahman2012

Thanks for this thread man!

Was really useful since I didn't like using apps to set my stuff on boot but didn't know how to do it with scripts





Quote:
Originally Posted by matt95

Really good guide



Quote:
Originally Posted by Wilks3y

Great Guide, well written and presented.

Not for me as I don't program, but great guide non the less !

Thanks guys!

Means a lot..


Sent from my :tank:
The Following 4 Users Say Thank You to Headless96 For This Useful Post: [ View ] Gift Headless96 Ad-Free
Post Reply Subscribe to Thread

Tags
guide, how to, how to make an init.d script, init.d

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

Advanced Search
Display Modes