[Guide] [Dec.15] How to Tweak and Mod Android Using Init.d Scripts

Search This thread

lucius.zen

Senior Member
Sep 16, 2012
464
482
34
Halifax
Hello my fellow Android enthusiasts,

There are many apps that can be used to tweak kernel settings. However, I am a reductionist at heart and prefer to break things down to their essential parts. This guide was written for those who want to be rid of apps that dig into their kernel at every boot. It is a simple guide to writing init.d scripts that the average user should be able to implement.

Happy Tweaking,

Lucius

PS......ITS A CELEBRATION, *****ES!!!!!!!:victory:


Basics:
The android boot sequence is divided into 3 parts.

1) First stage bootloader
2) Kernel loads and prepares hardware
3) User space programs load - this is where init.d scripts are invoked

Init.d scripts execute commands as if they were entered into a terminal. These commands modify the value of parameters that influence our devices behaviour. They are much more flexible than tweaking apps and give end users the ability to tweak and optimize their device as they see fit. They are small, fast, clean... and awesome.


Requirements:
See my guide to modding and optimization for instructions on how to unlock, install TWRP, root, and install custom ROMs/kernels - http://xdaforums.com/showthread.php?t=2232715

Unlocked: Needed to install custom recovery.

Custom Recovery: Needed to install custom ROMs and custom kernels.

Root Permissions: Needed to access /system partition - enabled when most custom ROMs are installed

Init.d Support: Needed to run init.d scripts at boot - enabled in every custom ROM/kernel I have come across.

Scripting Tool: Text editor or script manager - I use Android Tuner to create/test a script and AntTek File Explorer Ex's built in text editor to edit a script.

Root File Manager: I use AntTek Explorer Ex, it reminds me of my old linux setup, its very functional but clean as hell. Also has a built-in text editor.


Step #1: Acquire a Scripting Tool
I use Android Tuner for script creating/testing. You could also use a text editor. AntTek Explorer Ex has a built in text editor that works well. You could also use Notepad++, its a free linux based text editor. Just avoid windows-based editors, they leave extra spaces and invisible characters when enter is pressed.


Step #2: Begin Your Script
To create a script open your text editor or select "create new script" within the "script manager" in Android Tuner. Put your cursor at the very top left corner to begin writing. The first line of a script must invoke a compatible shell that will execute the script, which in our case is the following:

#!/system/bin/sh

Once this line is typed simply hit enter to start a new line. I usually put an empty line after the first line as it makes things easier to see. Extra lines for spacing purposes are fine so long as they are completely empty.

NOTE - Android tuner automatically appends the above line to the beginning of all scripts. It will not be displayed in the script creator but can be found in the final script you save.

TIP - Do not add spaces at the end of a line. Syntax must be exact.

TIP - Adding a "#" to the front of the line instructs the shell to avoid this line, which is essential for writing notes and keeping scripts organized.


Step #3: Write Your Tweaks
Now we can start writing tweaks. If written correctly each line that you enter will execute a command that changes a kernel or system level parameter. This seems daunting at first but it is really quite easy. Once you are finished typing a line simply hit enter to begin the next line. Here is an example of an executable command so you know what we are talking about going forward.

echo "SmartAssv2" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

NOTE - For some examples of useful tweaks see my guide to tweaking and optimization - http://xdaforums.com/showthread.php?t=2232715

GENERAL FORMAT:
The tweaks that we are interested in typically begin by identifying the value to be written to the desired parameter:

echo "parameter value" >

The new parameter value is always followed by the directory tree locating the parameter of interest:

/sys/devices/system/cpu/cpu0/cpufreq/parameter file

In order to create:

echo "700" > /sys/devices/system/cpu/cpu0/cpufreq/gpu_oc

CPU/GPU TWEAKS:
To familiarize yourself with how tweaking is done I would start by opening up the following directory in your file manager:

/sys/devices/system/cpu/cpu0/cpufreq/

This is where cpu parameters, and often gpu parameters, are located. These files/parameters determine how our kernel controls our CPU. To modify our CPU's behaviour these parameters are modified at boot utilizing init.d scripts. Familiarize yourself with these files, open them up with a text editor - it's entirely safe so long as you don't start changing values. If the name of a parameter isn't self-explanatory, opening it up and examining the value it holds will typically explain its purpose. Here are some common parameters that are useful to know.

scaling_available_freq - lists the frequencies available to the cpu
scaling_available_governors - lists the cpu governors available for use
scaling_governor - sets the cpu governor
scaling_max_freq - sets the max freq
scaling_min_freq - sets the min freq
UV_mV_table - sets the voltage table for the cpu

GOVERNOR TWEAKS:
The CPU governor determines how our CPU behaves in response to changes in workload. Changing the governor will impact how our CPU scales through the freq steps available to our CPU. This has a significant impact on the time our CPU spends at different frequency steps, which influences efficiency, performance, battery life, and stability. For more info about the various governors available in android see post #1 at the following link - http://xdaforums.com/showthread.php?t=1369817

Tweakable governor parameters are located in:

sys/devices/system/cpu/cpufreq/

Various interactive governor parameters can be accessed, such as:

go_hispeed_load - Go to hispeed_freq when cpu load at or above this value
hispeed_freq - freq to bump to once go_hispeed_load is passed
min_sample_time - minimum amount of time that can be spent at a frequency before scaling down
timer_rate - the interactive governor checks cpu load at regular intervals to determine whether frequencies should be increased when it comes out of idle. If the cpu is busy between exiting idle and the timer firing we assume the cpu is underpowered and ramp frequency up

HOTPLUG CONFIG:
The hotplug config in Hundsbuah's Kernel allows you to control how CPU cores are brought online as threads are processed. A thread is the smallest sequence of instructions that can be managed independently by a process scheduler. Threads are contained within a process. A process is the execution of instructions contained within a program. On a single processor system multi-threading (multitasking) is generally implemented by transmitting/sending signals over a common signal path; the processor switches between different threads. This switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. If the CPU is overloaded and a thread is queued up by the process scheduler then lag/stuttering is likely to occur because thread switching does not occur quickly enough to be hidden from the user. On a multi-core system threads can be truly concurrent, with every processor or core executing a separate thread simultaneously, which decreases the potential for lag/stuttering. If core 1 is busy processing a thread and another thread is queued up by the process scheduler we want an additional core to become active so that core 1 does not have to switch between threads. However, we also do not want to bring cores online needlessly. If a core is able to process multiple threads fast enough such that switching is unnoticeable then it would be inefficient to bring another core online. The hotplug config can be found in the following location:

/sys/kernel/rt_config/rt_config

I/O TWEAKS:
The I/O scheduler handles read/write requests from memory (RAM and storage). The I/O scheduler we use can significantly impact I/O (read/write) performance. For more info about the various I/O schedulers available in android see post #4 in the following thread - http://xdaforums.com/showthread.php?t=1369817

The location of the I/O scheduler is:

/sys/block/mmcblk0/queue/scheduler
/sys/block/mmcblk1/queue/scheduler

Use the follIng lines to change the I/O scheduler:

echo "sio" > /sys/block/mmcblk0/queue/scheduler
echo "sio" > /sys/block/mmcblk1/queue/scheduler

KERNEL MODULES:
A kernel module is a file containing code that extends the functionality of our kernel. Modules allow our kernel to communicate with different types of hardware (ex - bluetooth), utilize various file systems (ex - NTFS), or system calls (ex - frandom.ko). Kernels do not automatically come with all available modules, loading only the most essential modules can reduce a kernels footprint and potentially improve performance. Simultaneously, loading improved modules can improve performance in some cases (ex - frandom.ko). For more info about various kernel modules see post #3 in the following thread - http://xdaforums.com/showthread.php?t=1369817

NOTE - You cannot download and load kernel modules from the internet. They need to be compiled for kernel you are using.

To make a kernel module available make sure /system is mounted as rewritable, rather than read-only (see step #5 for further instructions). Copy the module .ko file (ex - tntfs.ko) to the following location:

/system/lib/modules

To check what modules are loaded at boot enter the following command in a terminal:

lsmod

To load a kernel module at boot add the following line to your init.d script:

insmod /system/lib/modules/module name

To unload a kernel module at boot add the following line to your script

rmmod module name

SYSCTL TWEAKS:
This section is currently under construction, more tweaks will be posted once I find them. Sysctl is an interface that is used to examine and dynamically change parameters within a linux based OS.

To change the TCP Congestion Algorithm add the following line to your script:

/system/xbin/sysctl -w net.ipv4.tcp_congestion_control=westwood

NOTE - For a brief explanation of TCP/IP protocols and network congestion algorithms see the following post - http://xdaforums.com/showpost.php?p=48088128&postcount=1884

FINISHING YOUR SCRIPT:
Once all your tweaks are written go through the entire script and make sure syntax is exact - no extra spaces or characters. Save your first script as w/e you want (ill explain naming later) just make sure it doesn't have a file extension. I'm talking total absence of file extensions. WHOA! WHAT! WTF YO!

NOTE - Android Tuner saves scripts by default in the "at" folder in "sdcard0"

Example Script:
Code:
#!/system/bin/sh

#CPU Tweaks
echo "1350 1320 1280 1240 1200 1150 1100 1050 1000 950 900 860 820 780 750 720 700" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table

#Governor Tweaks
echo "40000" > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time 

#SD Tweaks
echo "vr" > /sys/block/mmcblk0/queue/scheduler
echo "vr" > /sys/block/mmcblk1/queue/scheduler

#Module Tweaks
insmod /system/lib/modules/ frandom.ko
rmmod tntfs.ko
rmmod texfat.ko


Step #4: Test Your Script
You can test your script using a root terminal shell (Android Tuner has a terminal). Open a terminal, type "su", and hit enter (or select the box beside "su" in AT). This will give you the ability to run commands as root. To test your script enter the following command:

sh directory of your script

EXAMPLE - sh /storage/sdcard0/at/scripts/01ZenKernelTweaks

Check the files that correspond to the tweaked parameters to see if the script worked. If the values were correctly modified then you have officially finished writing your first working init.d script.


Step #5: Enable Your Script
First, open your file manager, go to your root directory, and remount your /system partition as RW instead of RO. This is typically done by long-pressing the /system folder (ex - AntTek Explorer), file manager settings (ex - esFile Explorer), or through the overflow menu. Once the /system is mounted as RW we can move our script to the init.d folder and change our scripts permissions. The init.d folder is located here:

/system/etc/init.d

The name of your script determines the order in which it is executed. The first two characters determine the order of execution. The ordering is as follows - numbers from 0-99, then letters from A-Z. The first two letters of a script's name are typically numbers between 0-99, this is the standard method of script naming that most developers/tweakers use. Set the name of your script so that it is executed in the order that you wish. Mine is set to execute first because I want to get kernel tweaks done as early as possible.

Once you have named your script long-press it and select "Change Permissions" (or however this is done in your file manager). Give User, Group, and Other read, write, and execute permissions.

Your init.d script will now optimize your tablet quickly and efficiently at every boot. Don't get out of your chair too fast....Before doing anything else, I suggest revelling in your awesome new-found abilities for a significant period of time. Pat yourself on the back. Start referring to yourself as "a boss" if you like. You deserve it.


CAUTION:
Although init.d scripts are easy to make, a bad script may cause boot looping. However, a bad script does not necessarily = boot looping. I have yet to cause a boot loop and I have written many scripts that did not work. Everything typically boots normally, the bad lines in the script are simply not applied. Before enabling your script I strongly suggest taking a Nandroid backup in TWRP. To do so boot into TWRP and select "Backup" from the home screen. This will allow you to restore your entire system, which is done via the "Restore" tool in TWRP.

NOTE - Do not enable scripts to run at boot in a program like Android Tuner or others similar to it. If the script is bad it will cause boot looping because the app will keep trying to run it. If you put the script in the init.d folder and enable it yourself you will avoid this issue.


SUGGESTION:
If you want more examples of tweaks that can help you optimize your tablet see my guide to tweaking and optimization. It fills any gaps in this guide and contains many useful resources. You can find it here - http://xdaforums.com/showthread.php?t=2232715
 
Last edited:

lucius.zen

Senior Member
Sep 16, 2012
464
482
34
Halifax
I accidentally stated in Step #3 that "Android saves scripts by default in the 'at' folder in your internal storage"....However, I meant to write "Android Tuner saves scripts...". Changed the OP, just wanted to make sure anyone who has read it already isnt like "WTF ZEN! Where is my damn script! Derpa a derrrr".
 
  • Like
Reactions: bmlarson

_that

Recognized Developer / Inactive RC
Oct 2, 2012
4,821
4,211
How-To Write Init.d Scripts for the tf700

Great tutorial!

The number, or letter, at the beggining of the init.d script determines its order of sexecution, beginning at 1 or A, and going up to 99 or Z.

The universal convention is to use a numeric prefix from 00 to 99, but in reality the name can be anything and the scripts are simply executed in alphanumeric order - digits come before "A". I recommend using two-digit prefixes as intended.

Code:
#!/system/bin/sh

#CPU Tweaks
echo "1300 1200 1150 1125 1112 1100 1087 1075 1050 1037 1025 1012 987 975 962 950 925 912 900 887 875 862 850 837 825 812 800 775 762 750 737 725 712 700 687 675 650 637 625 600" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table

Note that the UV_mV_table has a completely different format when reading or writing the file - one reason why I hate this interface. But it's the "standard" that was established by whoever hacked the first implementation, and user mode apps expect it like this.

Although init.d scripts are easy to make, you can potentially cause boot looping, please proceed with caution.

To repair this, boot into recovery, connect via adb shell, and do the following:

(if needed:)
mount -o remount,rw /system

chmod 0666 /system/etc/init.d/50myevilscript

This will remove "execute" permissions for the script, which will effectively disable it.
 

TunedFish

Senior Member
Aug 13, 2010
222
58
Say I tested and am currently using 10 scripts, how do I create a .zip recovery file so I can flash/install the scripts at once, every time I reflash or factory reset my rom?
 

SynnyG

Senior Member
Jan 14, 2013
878
707
Strasbourg
Thanks for your awesome tuto ! But I've a question concerning the gpu governor: it's possible to set this governor with command line too ?
 

lucius.zen

Senior Member
Sep 16, 2012
464
482
34
Halifax
@lucius.zen

It is a nice write up and great tutorial. I am enjoy reading it and keep up the good work... :good:

@LetMeKnow

Thanks a lot dude very much appreciated, makes me miss contributing to xda. I made a lot of promises and left too much work unfinished. I haven't been on for 6 months because I have been dealing with some pretty serious mental health issues. Apparently I am mildly schizophrenic with comorbid anxiety and attention issues. Been super fun times lol. Hoping to get back in the game this holiday season, would be sweet to share some tweaking/optimization ideas, I havent had much of a chance to check out your tweaks but I have heard great things.

All the best,

Lucius
 

LetMeKnow

Senior Member
Jun 17, 2013
1,686
699
Portland, Oregon
@LetMeKnow

Thanks a lot dude very much appreciated, makes me miss contributing to xda. I made a lot of promises and left too much work unfinished. I haven't been on for 6 months because I have been dealing with some pretty serious mental health issues. Apparently I am mildly schizophrenic with comorbid anxiety and attention issues. Been super fun times lol. Hoping to get back in the game this holiday season, would be sweet to share some tweaking/optimization ideas, I havent had much of a chance to check out your tweaks but I have heard great things.

All the best,

Lucius

Thanks for a kind word...:) It sounds like that you need to take of yourself a little better before worrying about the contributing to xda. You do a lot for the community already and hope you will get very soon. Please let me know whenever you have time to talk about tweaks and more than happy to share what I know.

Cheers and get well,
LMK
 
  • Like
Reactions: awilson77584

00shakey00

Member
Apr 22, 2013
13
1
Missing Files

Hi,

Using the guide I came up with the following script:
Code:
#!/system/bin/sh

#CPU Tweaks
echo "1350 1320 1280 1240 1200 1150 1100 1050 1000 950 900 860 820 780 750 720 700" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table
echo "20000" > /sys/devices/system/cpu/cpufreq/interactive/timer_rate
echo "1900000" > /sys/devices/system/cpu/cpufreq/interactive/max_boost
echo "1900000" > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
echo "85" > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
echo "85" > /sys/devices/system/cpu/cpufreq/interactive/go_maxspeed_load
echo "40000" > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time

but I received an error for hispeed_freq and go_hispeed_load claiming "No such file or directory". When I checked the /sys/devices/system/cpu/cpufreq/interactive/ directory, the two files are missing. Are they supposed to be present on the TF700?

Thanks
 

lucius.zen

Senior Member
Sep 16, 2012
464
482
34
Halifax
Hi,

Using the guide I came up with the following script:
Code:
#!/system/bin/sh

#CPU Tweaks
echo "1350 1320 1280 1240 1200 1150 1100 1050 1000 950 900 860 820 780 750 720 700" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table
echo "20000" > /sys/devices/system/cpu/cpufreq/interactive/timer_rate
echo "1900000" > /sys/devices/system/cpu/cpufreq/interactive/max_boost
echo "1900000" > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
echo "85" > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
echo "85" > /sys/devices/system/cpu/cpufreq/interactive/go_maxspeed_load
echo "40000" > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time

but I received an error for hispeed_freq and go_hispeed_load claiming "No such file or directory". When I checked the /sys/devices/system/cpu/cpufreq/interactive/ directory, the two files are missing. Are they supposed to be present on the TF700?

Thanks

Everything looks good in the script. Not sure why those parameters are missing. What kernel are you using?
 
  • Like
Reactions: mikmock

graphdarnell

Senior Member
Jan 25, 2012
713
159
@LetMeKnow

Thanks a lot dude very much appreciated, makes me miss contributing to xda. I made a lot of promises and left too much work unfinished. I haven't been on for 6 months because I have been dealing with some pretty serious mental health issues. Apparently I am mildly schizophrenic with comorbid anxiety and attention issues... Lucius

Forgive the digression, I couldn't help wondering: I don't mean to slight the condition in any way, but zen couldn't tackle it so you had to go the physical route?
 

Thibor69

Senior Member
Sorry I am having trouble understanding what you are asking. Are you wondering if I medication is more effective than meditation?

Here we go off topic already ... but just had to throw in my 2 cents. I have many conditions that have been treated for 30+ years (I am in my 50's) I had Chronic Severe OCD that was almost debilitating in my mid 20's. I also have A.D.H.D. (A.D.D) along with boughts of narcolepsy and severe panic attacks (were I end up on the floor or in the ER) anyways, I am a mess or I use to be. I did ALL the drugs Adderall (Amphetamine, Dextroamphetamine Mixed Salts) / Ritalin / Zoloft / bupropion / Xanax all at MAX DOSE. They all relieved some of the systems, but caused other issues to arise (addiction being one). I got into TD and Zen Yoga 10 years ago. 90% of my symptoms went away the first year, and I only take medication for my high cholesterol now. I feel great and work 10 to 13 hours a day. What this has to do with Init.d scripts .... *shrug* .... Pharmaceuticals just suck .

Now back to the Init.d scripting. Great job on the guide !! if this is not pinned it should be !!

Thank you for creating it.
Thibor69
 
  • Like
Reactions: _that

lucius.zen

Senior Member
Sep 16, 2012
464
482
34
Halifax
Here we go off topic already ... but just had to throw in my 2 cents. I have many conditions that have been treated for 30+ years (I am in my 50's) I had Chronic Severe OCD that was almost debilitating in my mid 20's. I also have A.D.H.D. (A.D.D) along with boughts of narcolepsy and severe panic attacks (were I end up on the floor or in the ER) anyways, I am a mess or I use to be. I did ALL the drugs Adderall (Amphetamine, Dextroamphetamine Mixed Salts) / Ritalin / Zoloft / bupropion / Xanax all at MAX DOSE. They all relieved some of the systems, but caused other issues to arise (addiction being one). I got into TD and Zen Yoga 10 years ago. 90% of my symptoms went away the first year, and I only take medication for my high cholesterol now. I feel great and work 10 to 13 hours a day. What this has to do with Init.d scripts .... *shrug* .... Pharmaceuticals just suck .

Now back to the Init.d scripting. Great job on the guide !! if this is not pinned it should be !!

Thank you for creating it.
Thibor69

Thanks dude! They tried to prescribe me an antipsychotic for my schizophrenia but I try to avoide pharmaceuticals. I agree that meditation, yoga/exercise work really well, as does tailoring my diet, etc. Glad things are going well for you now.

All the best,

Lucius
 

graphdarnell

Senior Member
Jan 25, 2012
713
159
Sorry I am having trouble understanding what you are asking. Are you wondering if I medication is more effective than meditation?

Actually I was asking if Zen would not suffice that you need to take medication. I don't see that drugs would do anything other than suppressing symptoms. Nothing is done about the root-cause, and that's how they get you hooked for life.

My own experience is that body is a reflection of mind and vice versa. The dichotomy is simply false. However, given the ingrained ruts one needs to obliterate, diet for the body must be watched as much as mediation must be practiced for mental well-being. You ever studied Oshawa? Much more than just a regime, the way I see it.

Sorry, I won't digress any further.
 

iZLeeP

Senior Member
Jan 23, 2014
528
151
Manila
The name of your script determines the order in which it is executed. The first two characters determine the order of execution. The ordering is as follows - numbers from 0-99, then letters from A-Z. The first two letters of a script's name are typically numbers between 0-99, this is the standard method of script naming that most developers/tweakers use. Set the name of your script so that it is executed in the order that you wish. Mine is set to execute first because I want to get kernel tweaks done as early as possible.

Great guide, thanks for the tutorial. One question, regarding the order of execution of scripts, does it matter if two or more scripts share the same prefix (1st 2 characters), for example 99SuperCharger and 99Supersudaemon, and 98KickAssKernelizer and 98Fly-On, 94engineflush and 94governor, and etc.? I combine scripts from different devs by editing their code to arrest any conflicts when they get executed, though, I don't change the script's name. Never had any problems, just curious on the sequencing of init.d scripts.
 

sbdags

Inactive Recognized Contributor
Jun 24, 2007
12,753
15,558
Kenilworth, Coventry
OnePlus 9 Pro
Great guide, thanks for the tutorial. One question, regarding the order of execution of scripts, does it matter if two or more scripts share the same prefix (1st 2 characters), for example 99SuperCharger and 99Supersudaemon, and 98KickAssKernelizer and 98Fly-On, 94engineflush and 94governor, and etc.? I combine scripts from different devs by editing their code to arrest any conflicts when they get executed, though, I don't change the script's name. Never had any problems, just curious on the sequencing of init.d scripts.

No it doesn't as they get executed alphabetically but it looks a mess and there is little room for ordering. ;)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 92
    Hello my fellow Android enthusiasts,

    There are many apps that can be used to tweak kernel settings. However, I am a reductionist at heart and prefer to break things down to their essential parts. This guide was written for those who want to be rid of apps that dig into their kernel at every boot. It is a simple guide to writing init.d scripts that the average user should be able to implement.

    Happy Tweaking,

    Lucius

    PS......ITS A CELEBRATION, *****ES!!!!!!!:victory:


    Basics:
    The android boot sequence is divided into 3 parts.

    1) First stage bootloader
    2) Kernel loads and prepares hardware
    3) User space programs load - this is where init.d scripts are invoked

    Init.d scripts execute commands as if they were entered into a terminal. These commands modify the value of parameters that influence our devices behaviour. They are much more flexible than tweaking apps and give end users the ability to tweak and optimize their device as they see fit. They are small, fast, clean... and awesome.


    Requirements:
    See my guide to modding and optimization for instructions on how to unlock, install TWRP, root, and install custom ROMs/kernels - http://xdaforums.com/showthread.php?t=2232715

    Unlocked: Needed to install custom recovery.

    Custom Recovery: Needed to install custom ROMs and custom kernels.

    Root Permissions: Needed to access /system partition - enabled when most custom ROMs are installed

    Init.d Support: Needed to run init.d scripts at boot - enabled in every custom ROM/kernel I have come across.

    Scripting Tool: Text editor or script manager - I use Android Tuner to create/test a script and AntTek File Explorer Ex's built in text editor to edit a script.

    Root File Manager: I use AntTek Explorer Ex, it reminds me of my old linux setup, its very functional but clean as hell. Also has a built-in text editor.


    Step #1: Acquire a Scripting Tool
    I use Android Tuner for script creating/testing. You could also use a text editor. AntTek Explorer Ex has a built in text editor that works well. You could also use Notepad++, its a free linux based text editor. Just avoid windows-based editors, they leave extra spaces and invisible characters when enter is pressed.


    Step #2: Begin Your Script
    To create a script open your text editor or select "create new script" within the "script manager" in Android Tuner. Put your cursor at the very top left corner to begin writing. The first line of a script must invoke a compatible shell that will execute the script, which in our case is the following:

    #!/system/bin/sh

    Once this line is typed simply hit enter to start a new line. I usually put an empty line after the first line as it makes things easier to see. Extra lines for spacing purposes are fine so long as they are completely empty.

    NOTE - Android tuner automatically appends the above line to the beginning of all scripts. It will not be displayed in the script creator but can be found in the final script you save.

    TIP - Do not add spaces at the end of a line. Syntax must be exact.

    TIP - Adding a "#" to the front of the line instructs the shell to avoid this line, which is essential for writing notes and keeping scripts organized.


    Step #3: Write Your Tweaks
    Now we can start writing tweaks. If written correctly each line that you enter will execute a command that changes a kernel or system level parameter. This seems daunting at first but it is really quite easy. Once you are finished typing a line simply hit enter to begin the next line. Here is an example of an executable command so you know what we are talking about going forward.

    echo "SmartAssv2" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

    NOTE - For some examples of useful tweaks see my guide to tweaking and optimization - http://xdaforums.com/showthread.php?t=2232715

    GENERAL FORMAT:
    The tweaks that we are interested in typically begin by identifying the value to be written to the desired parameter:

    echo "parameter value" >

    The new parameter value is always followed by the directory tree locating the parameter of interest:

    /sys/devices/system/cpu/cpu0/cpufreq/parameter file

    In order to create:

    echo "700" > /sys/devices/system/cpu/cpu0/cpufreq/gpu_oc

    CPU/GPU TWEAKS:
    To familiarize yourself with how tweaking is done I would start by opening up the following directory in your file manager:

    /sys/devices/system/cpu/cpu0/cpufreq/

    This is where cpu parameters, and often gpu parameters, are located. These files/parameters determine how our kernel controls our CPU. To modify our CPU's behaviour these parameters are modified at boot utilizing init.d scripts. Familiarize yourself with these files, open them up with a text editor - it's entirely safe so long as you don't start changing values. If the name of a parameter isn't self-explanatory, opening it up and examining the value it holds will typically explain its purpose. Here are some common parameters that are useful to know.

    scaling_available_freq - lists the frequencies available to the cpu
    scaling_available_governors - lists the cpu governors available for use
    scaling_governor - sets the cpu governor
    scaling_max_freq - sets the max freq
    scaling_min_freq - sets the min freq
    UV_mV_table - sets the voltage table for the cpu

    GOVERNOR TWEAKS:
    The CPU governor determines how our CPU behaves in response to changes in workload. Changing the governor will impact how our CPU scales through the freq steps available to our CPU. This has a significant impact on the time our CPU spends at different frequency steps, which influences efficiency, performance, battery life, and stability. For more info about the various governors available in android see post #1 at the following link - http://xdaforums.com/showthread.php?t=1369817

    Tweakable governor parameters are located in:

    sys/devices/system/cpu/cpufreq/

    Various interactive governor parameters can be accessed, such as:

    go_hispeed_load - Go to hispeed_freq when cpu load at or above this value
    hispeed_freq - freq to bump to once go_hispeed_load is passed
    min_sample_time - minimum amount of time that can be spent at a frequency before scaling down
    timer_rate - the interactive governor checks cpu load at regular intervals to determine whether frequencies should be increased when it comes out of idle. If the cpu is busy between exiting idle and the timer firing we assume the cpu is underpowered and ramp frequency up

    HOTPLUG CONFIG:
    The hotplug config in Hundsbuah's Kernel allows you to control how CPU cores are brought online as threads are processed. A thread is the smallest sequence of instructions that can be managed independently by a process scheduler. Threads are contained within a process. A process is the execution of instructions contained within a program. On a single processor system multi-threading (multitasking) is generally implemented by transmitting/sending signals over a common signal path; the processor switches between different threads. This switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. If the CPU is overloaded and a thread is queued up by the process scheduler then lag/stuttering is likely to occur because thread switching does not occur quickly enough to be hidden from the user. On a multi-core system threads can be truly concurrent, with every processor or core executing a separate thread simultaneously, which decreases the potential for lag/stuttering. If core 1 is busy processing a thread and another thread is queued up by the process scheduler we want an additional core to become active so that core 1 does not have to switch between threads. However, we also do not want to bring cores online needlessly. If a core is able to process multiple threads fast enough such that switching is unnoticeable then it would be inefficient to bring another core online. The hotplug config can be found in the following location:

    /sys/kernel/rt_config/rt_config

    I/O TWEAKS:
    The I/O scheduler handles read/write requests from memory (RAM and storage). The I/O scheduler we use can significantly impact I/O (read/write) performance. For more info about the various I/O schedulers available in android see post #4 in the following thread - http://xdaforums.com/showthread.php?t=1369817

    The location of the I/O scheduler is:

    /sys/block/mmcblk0/queue/scheduler
    /sys/block/mmcblk1/queue/scheduler

    Use the follIng lines to change the I/O scheduler:

    echo "sio" > /sys/block/mmcblk0/queue/scheduler
    echo "sio" > /sys/block/mmcblk1/queue/scheduler

    KERNEL MODULES:
    A kernel module is a file containing code that extends the functionality of our kernel. Modules allow our kernel to communicate with different types of hardware (ex - bluetooth), utilize various file systems (ex - NTFS), or system calls (ex - frandom.ko). Kernels do not automatically come with all available modules, loading only the most essential modules can reduce a kernels footprint and potentially improve performance. Simultaneously, loading improved modules can improve performance in some cases (ex - frandom.ko). For more info about various kernel modules see post #3 in the following thread - http://xdaforums.com/showthread.php?t=1369817

    NOTE - You cannot download and load kernel modules from the internet. They need to be compiled for kernel you are using.

    To make a kernel module available make sure /system is mounted as rewritable, rather than read-only (see step #5 for further instructions). Copy the module .ko file (ex - tntfs.ko) to the following location:

    /system/lib/modules

    To check what modules are loaded at boot enter the following command in a terminal:

    lsmod

    To load a kernel module at boot add the following line to your init.d script:

    insmod /system/lib/modules/module name

    To unload a kernel module at boot add the following line to your script

    rmmod module name

    SYSCTL TWEAKS:
    This section is currently under construction, more tweaks will be posted once I find them. Sysctl is an interface that is used to examine and dynamically change parameters within a linux based OS.

    To change the TCP Congestion Algorithm add the following line to your script:

    /system/xbin/sysctl -w net.ipv4.tcp_congestion_control=westwood

    NOTE - For a brief explanation of TCP/IP protocols and network congestion algorithms see the following post - http://xdaforums.com/showpost.php?p=48088128&postcount=1884

    FINISHING YOUR SCRIPT:
    Once all your tweaks are written go through the entire script and make sure syntax is exact - no extra spaces or characters. Save your first script as w/e you want (ill explain naming later) just make sure it doesn't have a file extension. I'm talking total absence of file extensions. WHOA! WHAT! WTF YO!

    NOTE - Android Tuner saves scripts by default in the "at" folder in "sdcard0"

    Example Script:
    Code:
    #!/system/bin/sh
    
    #CPU Tweaks
    echo "1350 1320 1280 1240 1200 1150 1100 1050 1000 950 900 860 820 780 750 720 700" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table
    
    #Governor Tweaks
    echo "40000" > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time 
    
    #SD Tweaks
    echo "vr" > /sys/block/mmcblk0/queue/scheduler
    echo "vr" > /sys/block/mmcblk1/queue/scheduler
    
    #Module Tweaks
    insmod /system/lib/modules/ frandom.ko
    rmmod tntfs.ko
    rmmod texfat.ko


    Step #4: Test Your Script
    You can test your script using a root terminal shell (Android Tuner has a terminal). Open a terminal, type "su", and hit enter (or select the box beside "su" in AT). This will give you the ability to run commands as root. To test your script enter the following command:

    sh directory of your script

    EXAMPLE - sh /storage/sdcard0/at/scripts/01ZenKernelTweaks

    Check the files that correspond to the tweaked parameters to see if the script worked. If the values were correctly modified then you have officially finished writing your first working init.d script.


    Step #5: Enable Your Script
    First, open your file manager, go to your root directory, and remount your /system partition as RW instead of RO. This is typically done by long-pressing the /system folder (ex - AntTek Explorer), file manager settings (ex - esFile Explorer), or through the overflow menu. Once the /system is mounted as RW we can move our script to the init.d folder and change our scripts permissions. The init.d folder is located here:

    /system/etc/init.d

    The name of your script determines the order in which it is executed. The first two characters determine the order of execution. The ordering is as follows - numbers from 0-99, then letters from A-Z. The first two letters of a script's name are typically numbers between 0-99, this is the standard method of script naming that most developers/tweakers use. Set the name of your script so that it is executed in the order that you wish. Mine is set to execute first because I want to get kernel tweaks done as early as possible.

    Once you have named your script long-press it and select "Change Permissions" (or however this is done in your file manager). Give User, Group, and Other read, write, and execute permissions.

    Your init.d script will now optimize your tablet quickly and efficiently at every boot. Don't get out of your chair too fast....Before doing anything else, I suggest revelling in your awesome new-found abilities for a significant period of time. Pat yourself on the back. Start referring to yourself as "a boss" if you like. You deserve it.


    CAUTION:
    Although init.d scripts are easy to make, a bad script may cause boot looping. However, a bad script does not necessarily = boot looping. I have yet to cause a boot loop and I have written many scripts that did not work. Everything typically boots normally, the bad lines in the script are simply not applied. Before enabling your script I strongly suggest taking a Nandroid backup in TWRP. To do so boot into TWRP and select "Backup" from the home screen. This will allow you to restore your entire system, which is done via the "Restore" tool in TWRP.

    NOTE - Do not enable scripts to run at boot in a program like Android Tuner or others similar to it. If the script is bad it will cause boot looping because the app will keep trying to run it. If you put the script in the init.d folder and enable it yourself you will avoid this issue.


    SUGGESTION:
    If you want more examples of tweaks that can help you optimize your tablet see my guide to tweaking and optimization. It fills any gaps in this guide and contains many useful resources. You can find it here - http://xdaforums.com/showthread.php?t=2232715
    4
    How-To Write Init.d Scripts for the tf700

    Great tutorial!

    The number, or letter, at the beggining of the init.d script determines its order of sexecution, beginning at 1 or A, and going up to 99 or Z.

    The universal convention is to use a numeric prefix from 00 to 99, but in reality the name can be anything and the scripts are simply executed in alphanumeric order - digits come before "A". I recommend using two-digit prefixes as intended.

    Code:
    #!/system/bin/sh
    
    #CPU Tweaks
    echo "1300 1200 1150 1125 1112 1100 1087 1075 1050 1037 1025 1012 987 975 962 950 925 912 900 887 875 862 850 837 825 812 800 775 762 750 737 725 712 700 687 675 650 637 625 600" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table

    Note that the UV_mV_table has a completely different format when reading or writing the file - one reason why I hate this interface. But it's the "standard" that was established by whoever hacked the first implementation, and user mode apps expect it like this.

    Although init.d scripts are easy to make, you can potentially cause boot looping, please proceed with caution.

    To repair this, boot into recovery, connect via adb shell, and do the following:

    (if needed:)
    mount -o remount,rw /system

    chmod 0666 /system/etc/init.d/50myevilscript

    This will remove "execute" permissions for the script, which will effectively disable it.
    2
    Breaking News.....

    ***************IMPORTANT UPDATE - MUST READ BREAKING NEWS*****************


    DEY TUK ARRRRR JEEEERRRRRRRBSSSSS!!!!!!!





    .....watching too many episodes of SP lately
    2
    @lucius.zen

    It is a nice write up and great tutorial. I am enjoy reading it and keep up the good work... :good:

    @LetMeKnow

    Thanks a lot dude very much appreciated, makes me miss contributing to xda. I made a lot of promises and left too much work unfinished. I haven't been on for 6 months because I have been dealing with some pretty serious mental health issues. Apparently I am mildly schizophrenic with comorbid anxiety and attention issues. Been super fun times lol. Hoping to get back in the game this holiday season, would be sweet to share some tweaking/optimization ideas, I havent had much of a chance to check out your tweaks but I have heard great things.

    All the best,

    Lucius