Related
Hey everyone,
wesgarner said:
Zip Align reduces the amount of RAM used during processing running for a major speed increase in running the apps: http://developer.android.com/guide/developing/tools/zipalign.html
Click to expand...
Click to collapse
I had been messing about with a script to pull apks off my phone, zipalign them and then push them back, but then I saw wesgarner's CM build with a binary and script for use on your phone. I don't really want to mess round with flashing a ROM just for that though, so I've ripped them out and uploaded them below. Another reason is I want to run this manually (with GScript) rather than on boot (as it does in wesgarner's ROM).
I take no credit for this, the binary and script were both taken from wesgarner's CM buiild.
To "install" this, just adb push the two files in the zip below onto your phone with:
Code:
adb shell mount -o remount,rw /system
adb push zipalign /system/bin
adb push zipalign_apks /system/sd/zipalign_apks.sh
adb shell chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
adb shell mount -o remount,ro /system
Then anytime you want to run the script just do:
Code:
adb shell sh /system/sd/zipalign_apks.sh
Or in terminal:
Code:
su
sh /system/sd/zipalign_apks.sh
Has been tested on CM 4.2.7.1
ZipAlign
senab said:
Hey everyone,
I had been messing about with a script to pull apks off my phone, zipalign them and then push them back, but then I saw wesgarner's CM build with a binary and script for use on your phone. I don't really want to mess round with flashing a ROM just for that though, so I've ripped them out and uploaded them below. Another reason is I want to run this manually (with GScript) rather than on boot (as it does in wesgarner's ROM).
I take no credit for this, the binary and script were both taken from wesgarner's CM buiild.
To "install" this, just adb push the two files in the zip below onto your phone with:
Code:
adb shell mount -o remount,rw /system
adb push zipalign /system/bin
adb push zipalign_apks.sh /system/sd
adb shell chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
adb shell mount -o remount,ro /system
Then anytime you want to run the script just do:
Code:
adb shell /system/sd/zipalign_apks.sh
Or in terminal:
Code:
su
sh /system/sd/zipalign_apks.sh
Has been tested on CM 4.2.7.1
Click to expand...
Click to collapse
i do not even know what zipalign does .. but i did add this to my script
# lucid -z
so .. what does it do exactly?
Sweet... Thanks...
I was surprised that more than half of the Apps I have were already ZipAligned...
LucidREM said:
i do not even know what zipalign does .. but i did add this to my script
# lucid -z
so .. what does it do exactly?
Click to expand...
Click to collapse
APKs (as you probably already know) are just zip files. zipalign simply aligns the APK on 4-byte boundaries which Android is more efficient wrt memory access.
You can read more from Jean-Baptiste Queru at http://android-developers.blogspot.com/2009/09/zipalign-easy-optimization.html
Vermithrax said:
Sweet... Thanks...
I was surprised that more than half of the Apps I have were already ZipAligned...
Click to expand...
Click to collapse
Since the 1.6 SDK was released, the ADT does this automatically on APK export. Therefore any app which has been updated since ~September (and was developed using the ADT Eclipse plugin) will be zipalign'd. I was more surprised that 12 out of the 43 apps on my phone weren't aligned!
ZipAlign
senab said:
APKs (as you probably already know) are just zip files. zipalign simply aligns the APK on 4-byte boundaries which Android is more much efficient wrt memory access.
You can read more from Jean-Baptiste Queru at http://android-developers.blogspot.com/2009/09/zipalign-easy-optimization.html
Click to expand...
Click to collapse
that's awesome .. thanks for the link .. i hadn't read about that
Thanks much for this!
Here is a simple gscript to install zipalign after a wipe or new build flash.
You must first create directory /sdcard/zipalign and place zipalign from the zip in the OP there. Path to the file should now be /sdcard/zipalign/zipalign.
Place this script in your gscript folder (after removing .txt from the name) and load it in gscript with su permissions.
I also find it easier to run the script in the zip from the OP in Gscript as well. Instead of placing it in /system/sd run this (assumes zipalign_apks.sh is at root of C:\)
Code:
adb remount
adb push C:\zipalign_apks.sh /sdcard/gscript/zipalign_apks.sh
Then just load it into Gsrcipt with su permissions as with the other script.
Easiest of all may just be to use the commands within Lucid's script. But, I'm comfortable with Gscript, and I can make it 2 clicks away.
EDIT: First execution, you may want to run the original way, because guess what? Gscript isn't zipaligned. But it worked fine just the same.
worked great thanks.
Thanks. I didn't want to flash whole ROM to zipalign apps, so script was very handy.
Actually I've zipaligned only 2 apps, one of them was everybody loved Linda
so anyone wanna bless me with a terminal code to install the script?
garz said:
so anyone wanna bless me with a terminal code to install the script?
Click to expand...
Click to collapse
Read, its on the first post....xD
ZipAlign
garz said:
so anyone wanna bless me with a terminal code to install the script?
Click to expand...
Click to collapse
# lucid -z
yeah so su? then #lucid -z? cause that did nothing for me...
LucidREM said:
i do not even know what zipalign does .. but i did add this to my script
# lucid -z
so .. what does it do exactly?
Click to expand...
Click to collapse
I put a quick explanation of my script on my ROM page: here ya go (rough explanation)
Zip Align reduces the amount of RAM used during processing running for a major speed increase in dex-opt and running the apps, along with the RAM hack and a CC (or your userinit) boots speeds incredibly and better usability of apps (boot and system) in Android: http://developer.android.com/guide/d.../zipalign.html
Most developers have not used this yet (CM does ZipAlign his apps), but this does for the system apps provided from the now old Google Apps
Click to expand...
Click to collapse
senab said:
Since the 1.6 SDK was released, the ADT does this automatically on APK export. Therefore any app which has been updated since ~September (and was developed using the ADT Eclipse plugin) will be zipalign'd. I was more surprised that 12 out of the 43 apps on my phone weren't aligned!
Click to expand...
Click to collapse
Agreed. The Market won't let non-zipaligned apps be uploaded.
AndroidAppCritic said:
Agreed. The Market won't let non-zipaligned apps be uploaded.
Click to expand...
Click to collapse
it will really, it doesn't detect the diff
Also, SDK4 didn't really include an enforced ZipAlign like SDK5 (eclair) does
Plus I built the ZipAlign from source from eclair - so this script may not update them all perfectly
garz said:
yeah so su? then #lucid -z? cause that did nothing for me...
Click to expand...
Click to collapse
Unzip the files to your SD Card, then:
Code:
su
mount -o remount,rw /system
mv /sdcard/zipalign /system/bin
mv /sdcard/zipalign_apks /system/sd/zipalign_apks.sh
chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
mount -o remount,ro /system
Post deleted becoz it was redundant
can someone make a script for windows or a bat file that can zipalign a batch of apks? I am not that ofay with line commands and when i create a new theme (which i often do), i then have to go and zipalign every single apk i have altered 1 at a time..... i do:
Code:
zipalign -f -v 4 E:\app\theapp.apk E:\app\theapp.apk.out
senab said:
Unzip the files to your SD Card, then:
Code:
su
mount -o remount,rw /system
cp /sdcard/zipalign /system/bin
cp /sdcard/zipalign_apks.sh /system/sd
chmod 755 /system/bin/zipalign /system/sd/zipalign_apks.sh
mount -o remount,ro /system
Click to expand...
Click to collapse
This isnt working for me bc of the .sh after zipalign_apks .. do i rename the zipalign_apks to zipalign_apks.sh after unzipping?
edit:that worked THANKS!
hey,
whenever i flash a new rom i edit the zip to replace keylayouts, apps in /system and /data , bootscreens and some other stuff......
i now want to symlink some directories with a script which will be loaded during rom flash because otherwise i would need a pc to access it through adb...
the script i want FOR NOW (i may use it for other things in the future)
is about symlinking the
/system/customize/resource/bootanimation.zip to /data/local/bootanimation.zip
/system/customize/resource/android_audio.mp3 to /data/local/android_audio.mp3
i can do this through adb as i said but i'd prefer it to be done automatically by a script during flash.... i know the commands to use but i need a way to implement the script into the rom.....
i think it's like the a2sd+ script but i am not sure....
if anyone knows please help me
you need to split open your boot.img and modify the init.rc (the file where services are initialised at Android startup)
See this link for notes on working with the boot.img
you can create the symlinks directly in this file, have a look at the syntax and you should be able to work it out. The ln command doesn't work though, use the format:
Code:
symlink /system/customize/resource/bootanimation.zip /data/local/bootanimation.zip
Or you can create a dummy 'service' which executes a file on your filesystem (like /etc/rc.local) and put your "ln -s" commands in there.
Why not just create a custom update.zip with your changes only, then you can apply it after flashing any rom.
Klutsh said:
Why not just create a custom update.zip with your changes only, then you can apply it after flashing any rom.
Click to expand...
Click to collapse
How would you do this?
Say I wanted an update.zip that would remove plurk and add a certain app. How would I go about creating that?
removing and adding is easy with the update signer app.....i just want to add a script that symlinks directories at boot in order to avoid the use of a pc.....i tried the trick st0kes said and i am waiting for the flashing now to complete and send my feedback
nope it didn't work.....is there any specific place to put the command ????
i put it at the very end of the init.rc file
ok after a lot of reading i created a service which runs a folder with scripts...where i have the script that symlinks the files.....
service myscripts /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/myscript.d
oneshot
Click to expand...
Click to collapse
this is the service code
and here is the code i have into the "bootanimation" script which is inside the myscript.d folder
#!/system/bin/sh
mount /system
mount /data
ln -s /system/customize/resource/bootanimation.zip /data/local/bootanimation.zip
ln -s /system/customize/resource/android_audio.mp3 /data/local/android_audio.mp3
Click to expand...
Click to collapse
what am i doing wrong here ????? please someone with knowledge enlighten me!! the script does not run
damn....it's been a long night and still haven't found a way to do it !!!!!!
i tried all the followings:
1) added a file called "myscript" (it contained two lines with the symlink commands) in init.d folder in order to execute when the boot is complete - FAILED
2) added the same file into another folder and added a service at the bottom of the init.rc file that called it
service myscript /system/etc/myscripts/myscript
oneshot
Click to expand...
Click to collapse
-FAILED
3) added the SYMLINK commands into the init.rc file
a)at the bottom -FAILED
b) before the bootanim, bootsound services -FAILED
c) before the bootcomplete = 1 value in init.rc -FAILED
d) after sysinit execution in init.rc -FAILED
e) before sysinit execution in init.rc - FAILED
f) at the top after some lines of code in init.rc - FAILED
i read that HTC change the boot process and to run custom scripts at boot you must add their commands in "bootcomplete.bravo.rc"
i tried that too but FAILED again....i think this is logical cause these scripts are executed after the boot and just when the phone is gonna show the pin dialog....
i think it's something to do with the init.rc file...but i dunno what else to add....
is there anything i have to mount in order to symlink ???? add busybox to something or anything ??????
PLEASE someone with success at scripting like a2sd+ please help me
Try naming your script
Code:
03BootAnim
and place it in
Code:
/system/etc/init.d
Also don't forget to chmod +x it
how to chmod +x ??? nvm i did it...i am now signing it to try it
in adb
Code:
adb shell chmod +x /system/etc/init.d/03BootAnim
chmod 755 does the same, makes it executable by the system
Klutsh said:
Try naming your script
Code:
03BootAnim
and place it in
Code:
/system/etc/init.d
Also don't forget to chmod +x it
Click to expand...
Click to collapse
hey klutsh i tried what you said but it didn't work...
look i created the file
Code:
03BootAnim
and placed it into the
Code:
/system/etc/init.d
the commands i have into the file are these
Code:
#!/system/bin/sh
ln -s /data/local/bootanimation.zip /system/customize/resource/bootanimation.zip
ln -s /data/local/android_audio.mp3 /system/customize/resource/android_audio.mp3
ok i edited the commands like these but no result too.....
Code:
#!/system/bin/sh
busybox mount /system
busybox mount /data
busybox ln -s /data/local/bootanimation.zip /system/customize/resource/bootanimation.zip
busybox ln -s /data/local/android_audio.mp3 /system/customize/resource/android_audio.mp3
i checked with the
Code:
ls -l /system/etc/init.d
command and the permissions are all the same (they are all enabled i think, -rwxr-xr-x )
i wiped everything, flashed, rebooted but no bootanimation!!! the default android logo with the moving shade appears (i have deleted the animation in the system/customize/resource folder in order for the symlink to work)
what am i doing wrong ???? is there something with the script ?
I'm trying to get this working, and so far it is running before the bootanimation, but I get
Code:
run-parts: can't execute '/system/etc/init.d/03BootAnim': No such file or directory
Yet it is available...
what commands do you have in yours ????
maybe a reboot will fix it o yours since it will rescan ?
edit: hey klutsh i logcated my boot and i see that the symlinks do not work cause it says that /system/customize/resource/bootanimation.zip and android_audio.mp3 directories are read-only file systems
That's the problem then.
Already got a fix that you apply once only to a flashed rom then the boot anim runs from /data/local and can be replaced.
http://www.asificanrememberthat.com/DeLite/BootAmin_to_Data.zip
Flash that after any Sense rom that normally has bootanimation in /system/customize
It will delete the 2 files in /system/customize/resource
flash my own bootanimation to /data/local
create the required symlinks that survive reboot's.
You can then just replace the files in /data/local as needed.
as i see you made it with the update sign and packager isn't it ????
nice idea....
BUT why can't we access /system files through boot ???? is there any way to get root access at booting ???
THANKS YOU VERY MUCH for the great effort you made....
is there a way to implement the update-script into the 03BootAnim in order not to have to flah anything ????
the reson i want this is cause i am cooking my roms on my own and i want them to have all i need inside....not having to flash mod1, mod2 etc
It's a feature of the desire, no write access to /system unless in recovery.
You can just take those bit's from my update-script and add them to your own rom's script.
oh yes...this is what i was asking i have tow update-scripts though, one old and one in the android.new folder
i am using dsixda kitchen....in which should i put it ??? does it matter where is it?
edit: found it....signing to flash
HURRAYYYYYYYYYYYYYYYYYYYYYYY
hey klutsh i thank you a lot.....
it was so easy to do it just copy paste the update-script but we (I) took the hard way of READ-ONLY file system....anw i learned A LOT (if you think that i am reading 15hours constantly about this)
PROBLEM SOLVED
You can delete the android.new folder, it isn't used.
What is init.d ?
Init.d is a feature which allows you to run brunch of scripts at boot . Thats really useful while you want to set values which reset at boot or run/do any thing at every boot or install tweaks , engines and....
There are some ways to add this feature to you rom but always best way is to add init.d support directly by your kernel . I want to help you to do this
Requirements
1- Ability to unpack boot.img & ramdisk
2- Some basic linux shell knowloedge
3- Having Busybox located in /system/bin/busybox at your rom
Step 1: Making kernel ready
1- Unpack kernel then ramdisk
2- Open Init.rc with a text editor
3- Add this codes at the end , before the paragraph which there is "stop bootanim" command in it :
Code:
service sysinit /system/bin/sysinit
oneshot
4- Save , Exit and repack ramdisk and boot.img
Step 2 : Making Rom Ready !
1- Open /system/bin/sysinit
2- Add this codes :
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/
3- Set permissions of sysinit to 777 or 755 ( rwxrwxr-x | rwxrwxrwx )
4- Make a directory at system/etc and name it init.d
Now you have init.d support !
Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:
Someone had to document this ^^, good job
RobyRc said:
Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:
Click to expand...
Click to collapse
Pimp uses one of the worst method to add this feature to your ROM ! it doesn't effect on kernel so : 1- running init.d is slower 2- init.d is not stable at all 3- not usable for ones want to add this feature to his/her kernel 4- not run init.d at end of boot so some script which needs some binaries that are not loaded yet doesn't work 5- Can not be used for room devs
This method is the official method which is used on most famous kernels such as brood kernel . and best for devs and users
any way that depends on users idea that this is good or not
RobyRc said:
Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:
Click to expand...
Click to collapse
Why are you so rude?
There are ways and ways to express own opinions... And alireza has just explained you why this method is better then PIMPMYROM.
Sent from my AriesVe using xda premium
alireza7991 said:
Pimp uses one of the worst method to add this feature to your ROM ! it doesn't effect on kernel so : 1- running init.d is slower 2- init.d is not stable at all 3- not usable for ones want to add this feature to his/her kernel 4- not run init.d at end of boot so some script which needs some binaries that are not loaded yet doesn't work 5- Can not be used for room devs
This method is the official method which is used on most famous kernels such as brood kernel . and best for devs and users
any way that depends on users idea that this is good or not
Click to expand...
Click to collapse
You are wrong.
RobyRc said:
You are wrong.
Click to expand...
Click to collapse
well, if he is wrong you can explain why, he explained why according to him is better this way, you could explain why not
What happens if your ROM doesn't have /system/bin/sysinit?
vMAC said:
What happens if your ROM doesn't have /system/bin/sysinit?
Click to expand...
Click to collapse
* Your rom has sysinit -> You have already init.d support and no need to this guide
* Your rom has'nt it -> You need to do my guide to get init.d support
alireza7991 said:
* Your rom has sysinit -> You have already init.d support and no need to this guide
* Your rom has'nt it -> You need to do my guide to get init.d support
Click to expand...
Click to collapse
And is it possible to create sysinit and init.d folder with an updater script?
GT-af said:
And is it possible to create sysinit and init.d folder with an updater script?
Click to expand...
Click to collapse
sure but do'nt forget :
1- your kernel must support init.d ( look at first post step 1)
2- do step 2 at fist post on sys init or you wo'nt have init.d support !
I have MTK 6577 device this will work ?
andrman1 said:
I have MTK 6577 device this will work ?
Click to expand...
Click to collapse
all android devices are supported
alireza7991 said:
all android devices are supported
Click to expand...
Click to collapse
In init.rc file I haven't code "stop bootanim" why and where I put this code ?
And I haven't in /system/bin file "sysinit" ?
andrman1 said:
In init.rc file I haven't code "stop bootanim" why and where I put this code ?
And I haven't in /system/bin file "sysinit" ?
Click to expand...
Click to collapse
Place those codes on the middle of init.rc ; the only difference is execute order . if you put it at first init.d wont execute becuase we have'nt system mounted still and if you put it at the end you will stop at your homescreen for a few secound so its better to execute it while you are seeing bootanimation
make new file name it sysinit and put codes siad in OP inside it .
Step 2 : Making Rom Ready !
1- Open /system/bin/sysinit
2- Add this codes :
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/
Is this needed?
I've seen some ROMs not having /system/bin/sysinit but init.d kernel support, and I've tested a ROM myself not having this file, but the
99test init.d script gave some output to /data/tmp. So I guess it was executed properly.
t-ryder said:
Step 2 : Making Rom Ready !
1- Open /system/bin/sysinit
2- Add this codes :
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/
Is this needed?
I've seen some ROMs not having /system/bin/sysinit but init.d kernel support, and I've tested a ROM myself not having this file, but the
99test init.d script gave some output to /data/tmp. So I guess it was executed properly.
Click to expand...
Click to collapse
There are many ways to get init.d working , you may include sysinit in init.rc or you may completely remove it and use a direct code in init.rc to execute init.d scripts or ....
Here in this method , I used sysinit in user-space to let init.d be dynamicly modifed or removed without repacking the kernel
alireza7991 said:
There are many ways to get init.d working , you may include sysinit in init.rc or you may completely remove it and use a direct code in init.rc to execute init.d scripts or ....
Here in this method , I used sysinit in user-space to let init.d be dynamicly modifed or removed without repacking the kernel
Click to expand...
Click to collapse
So just the file
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/
would make it run (having busybox in /xbin) without having to mess around in the kernel using e.g. virtous ten studio?
t-ryder said:
So just the file
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/
would make it run (having busybox in /xbin) without having to mess around in the kernel using e.g. virtous ten studio?
Click to expand...
Click to collapse
there are many strange and not suggested methods which add init.d without repacking kernel but the best method is using init.rc .
But I have some ideas on getting init.d working withouy messing around kernel . I am going to test them ;
alireza7991 said:
there are many strange and not suggested methods which add init.d without repacking kernel but the best method is using init.rc .
But I have some ideas on getting init.d working withouy messing around kernel . I am going to test them ;
Click to expand...
Click to collapse
Hi; I googled for a while to find a way to add init.d to my ROM and found your thread. Can you also explain how to adjust the source tree before compilation that I get the init.d? I am compiling AOSP with the stock kernel. I saw a few posts before that this method just works for a kernel which supports init.d. I have no clue if the stock kernel does. Thanks
*****************************************************************************************************************************************************
Credit for discovering this method goes to Sr. Staff gurus @_that (bet you could have guessed) and @becomingx for parsing GNU code to figure out file naming limitations (no dots!) to make this work.
******************************************************************************************************************************************************
This short Guide accompanies the need to run my B2R startup script (or any script) as root at boot. If you are rooted and have busybox installed on a stock ROM or any ROM that does not have init.d support thru init.rc, here's how you can add it. This is an alternative method to either using Script Manager (SManager) or hijacking the install-recovery.sh file directly to run a startup script. Enabling this support allows you to be able to run all executable scripts located in init.d as root at boot.
IMPORTANT: Your init script name can NEITHER have any dots in the filename NOR use an extension. Name it something like autostart or start-up or init_script. Also when you write a script, NEVER forget to start it with the hash-bang-path to shell (#!/system/bin/sh) and NEVER forget to press ENTER after the last character of the last line of code. You can't just use any simple text editor to create the file - you must pay close attention to "line ends". I use ES Note Editor on device and Notepad++ configured for UNIX/OSX line ends on PC. Always save the file AS PLAIN TEXT. Read "Additional Information" below on line ends.
[NOTE: /system/etc = /etc (symlink)]
1. Mount your /system rw
Code:
mount -o remount,rw /system
2. Make directory /system/etc/init.d
Code:
mkdir /system/etc/init.d
3. Create a shell script (using a text editor with UNIX line ends [LF only] ) named "/system/etc/install-recovery.sh" with the following contents:
Code:
#!/system/bin/sh
/system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
4. Put your init script in init.d and remember to make both /system/etc/install-recovery.sh and your script in /system/etc/init.d executable.
Code:
cd /system/etc
chmod 755 install-recovery.sh
cd /system/etc/init.d
chmod 755 name_of_your_init_script
5. Immediately reboot or if not, mount your /system ro
Code:
mount -o remount,ro /system
If you have busybox installed in /system/xbin this enables support for running init.d scripts from ROMs that do not offer native support thru init.rc.
Additional Information:
Every file has what are know as line ends or more technically end of line (EOL) conversions. These are HIDDEN characters that you normally don't see (if the line end are in the native OS format) at the end of lines in a text editor when editing files. This is the character that tells the OS where one line stops and the next starts in any file. In order to see the line ends you must enable "show all characters".
Your text editor must support UNIX line ends (LF only, not CR + LF = CRLF). Do NOT use Windows Notepad as it only creates Windows line ends (CRLF).
Always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends or it will fail to execute. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed) or (CRLF). The consequence is that the system can't find your shell under the name "sh^M" (or any subsequent command "some_command^M") and your script will fail.
This is VERY important to understand and also how to configure any cross-platform text editor. Using notepad++ in Windows without changing the default settings still results in CRLF at the end of lines because it knows its running in Windows and thinks you want Windows line ends. In order to change this behavior, Under the Edit menu find EOL conversion, and select Unix/OSX format. Also toggle the paragraph symbol on the top bar (backwards P with double verticles; show all characters) and now its clear as day what line ends you have, where they are, and if you have one after the end of the last line or not. Now its WYSIWYG. Once these setting are toggled, saving the file in Windows results in Unix/OSX line ends (LF) and when you open notepad++ the next time the settings are retained. See screenshot before attachment at the end of this post.
Example for changing default EOL conversion to Unix LF for an older version of notepad++:
http://techtips-it.blogspot.com/2011/04/can-i-convert-file-format-in-notepad.html
If done correctly, the output you will see if VIEWED (not edited) using Windows notepad will show a small hollow rectangle representing each LF. You will see one for each line end, and two together at the end of the last line itself - the first is the EOL LF for that line, and the subsequent is the LF you entered after the last line. If notepad just shows what you would normally see in the XDA code block with no extra special characters as described, you have Windows line ends and your script will fail to execute.
If you have multiple scripts to run at boot, the real purpose of init.d, you should name your init scripts prepended with two digits between 00 and 99. (Fairly) Evenly divide the range into 3 groups like 2# (20-29), 5# (50-59), and 8# (80-89). Scripts in the 20 series will be run first, followed by 50 series scripts, ending with 80 series scripts. They will be executed from lowest number to highest number, in that order. This allows you to define the load order for a group of init scripts. We didn't use 00-19 or 90-99 in case we need to put a future script before the first or after the last one without having to rename the rest of the scripts to do so.
Example init script names: 20firststart, 50mid_start, 80end-boot
******************************************************************************************************************************************************
Download the attachment and remove the txt extension and copy it into /system/etc and make sure it is executable. Make directory /system/etc/init.d, put your executable boot scripts in there, and reboot to run your executable init.d scripts as root.
This method replaces the depreciated method of directly hijacking install-recovery.sh with a single boot script run as root. Why have only one when you can have many?
Linkback to dev thread
http://forum.xda-developers.com/showthread.php?t=2191777
Reserved
Sent from my LG-LS970 using xda app-developers app
elfaure said:
@_that, please review and bless.
Click to expand...
Click to collapse
elfaure said:
IMPORTANT: Your init script name can NEITHER have any dots in the filename NOR use an extension. Name it something like autostart or start-up or init_script.
Click to expand...
Click to collapse
I still recommend using the common Unix convention of 2 digits + lowercase name for init.d scripts, e.g. 50something, 60dothislater, 90somethingtodolast. The numbers allow for clearly defining the order in which multiple startup scripts are executed.
elfaure said:
Also when you write a script, NEVER forget to start it with the hash-bang-path to shell (#!/system/bin/sh) and NEVER forget to press ENTER after the last character of the last line of code. You can use any simple text editor to create the file. I use ES Note Editor on device and Notepad++ on PC. Always save the file AS PLAIN TEXT.
Click to expand...
Click to collapse
And always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed). The consequence is that the system can't find your shell under the name "sh^M" and your script will fail.
elfaure said:
4. Remember to make it executable and to create the /system/etc/init.d directory.
Click to expand...
Click to collapse
You already created init.d in step 1.
Looks like it could work like this. If you want to be sure, remove your existing scripts and rmdir your init.d directory, then follow your own guide and see if everything is OK. Then you can bless it yourself. In software development, peer review is always good, but testing is even more important.
_that said:
I still recommend using the common Unix convention of 2 digits + lowercase name for init.d scripts, e.g. 50something, 60dothislater, 90somethingtodolast. The numbers allow for clearly defining the order in which multiple startup scripts are executed.
And always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed). The consequence is that the system can't find your shell under the name "sh^M" and your script will fail.
You already created init.d in step 1.
Looks like it could work like this. If you want to be sure, remove your existing scripts and rmdir your init.d directory, then follow your own guide and see if everything is OK. Then you can bless it yourself. In software development, peer review is always good, but testing is even more important.
Click to expand...
Click to collapse
Thanks for the review! I will make some edits, test drive the guide, and bless it myself. I was already going to add the two digit numerical discussion. I'm not trying to get you to do any extra or my work here, God knows you are a very busy multi-tasking hundreds of tasks , I just thought I was on newb patrol after posting a non-working script and then mandated to your must review list.
Is this method works on other phone too?
I really do want the init.d support on stock rom
Sorry for my bad English...
Sent from my HTC Desire 200 using XDA Premium 4 Mobile app
dicks93277 said:
Is this method works on other phone too?
I really do want the init.d support on stock rom
Click to expand...
Click to collapse
The method is reasonably generic that it is worth trying on your device.
so sad that i can't make this work on my phone
but still thanks for your reply @_that
Awesome it works on my Panasonic T41 running MIUI 5 beta
Could you tell how to do the same thing from init.rc ???
and also one script is not working
Code:
#!/system/bin/sh
su
mount -o rw,remount /
mkdir -p /rex
mount -o bind /data/data/com.spartacusrex.spartacuside/files/system /rex
mount -o rw,remount /system
mkdir -p /system/vendor/bin
mount -o /rex/bin /system/vendor/bin
Is there any thing wrong with it ?? I used unix terminators and also set the permissions to 755
uttarayan21 said:
Awesome it works on my Panasonic T41 running MIUI 5 beta
Could you tell how to do the same thing from init.rc ???
and also one script is not working
Code:
#!/system/bin/sh
su
mount -o rw,remount /
mkdir -p /rex
mount -o bind /data/data/com.spartacusrex.spartacuside/files/system /rex
mount -o rw,remount /system
mkdir -p /system/vendor/bin
mount -o /rex/bin /system/vendor/bin
Is there any thing wrong with it ?? I used unix terminators and also set the permissions to 755
Click to expand...
Click to collapse
The 'su' command with no arguments starts an interactive shell, everything after 'su' waits for the user to exit that shell, which you can't do. Init.rc and subsequent scripts are run as root anyway, including init.d scripts, so just delete the 'su' line and it should work.
Sent from my LGL41C using Tapatalk
Kor1134 said:
The 'su' command with no arguments starts an interactive shell, everything after 'su' waits for the user to exit that shell, which you can't do. Init.rc and subsequent scripts are run as root anyway, including init.d scripts, so just delete the 'su' line and it should work.
Sent from my LGL41C using Tapatalk
Click to expand...
Click to collapse
Thanks !!! It worked !!!!
uttarayan21 said:
Thanks !!! It worked !!!!
Click to expand...
Click to collapse
You're welcome [emoji6]
Sent from my LGL41C using Tapatalk
Why don't use service from init.rc ??
elfaure said:
*************************************,
3. Create a shell script (using a text editor with UNIX line ends [LF only] ) named "/system/etc/install-recovery.sh" with the following contents:
Code:
#!/system/bin/sh
/system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
Click to expand...
Click to collapse
But it is better to add a service to init.rc and launch sysinit from there for init.d support !!!
Maybe you should update your guide with that !!!
:laugh: :good:
uttarayan21 said:
But it is better to add a service to init.rc and launch sysinit from there for init.d support !!!
Maybe you should update your guide with that !!!
:laugh: :good:
Click to expand...
Click to collapse
Changing init.rc requires repacking the boot image.
_that said:
Changing init.rc requires repacking the boot image.
Click to expand...
Click to collapse
Yeah it does but if you install SuperSU then the install-recovery.sh file will be modified and init.d will be lost !!!
Hello guys!
I am not new in the Android and Nexus world but at this time I need some help.
I am used to root any Nexus phone in this way:
1. Put su, daemonsu, busybox on /system/xbin/ path;
2. Create the init.d folder in /system/etc/ path;
3. Add a script file to start the superuser daemon at the boot;
4. Edit the kernel ramdisk adding the sysinit script to add the init.d support at the boot;
5. Edit the updated-script for the right permissions to the new init.d folder (and its content) and to the su binary file.
I never had problems with Galaxy Nexus and LG Nexus 4 but today I am having troubles with the Nexus 5.
Is this a common issue?
I hope to get answers,
regards,
kalo86
kalo86 said:
Hello guys!
I am not new in the Android and Nexus world but at this time I need some help.
I am used to root any Nexus phone in this way:
1. Put su, daemonsu, busybox on /system/xbin/ path;
2. Create the init.d folder in /system/etc/ path;
3. Add a script file to start the superuser daemon at the boot;
4. Edit the kernel ramdisk adding the sysinit script to add the init.d support at the boot;
5. Edit the updated-script for the right permissions to the new init.d folder (and its content) and to the su binary file.
I never had problems with Galaxy Nexus and LG Nexus 4 but today I am having troubles with the Nexus 5.
Is this a common issue?
I hope to get answers,
regards,
kalo86
Click to expand...
Click to collapse
fastboot oem unlock
flash custom recovery
flash SuperSU in recovery
Of course I have unlocked the bootloder but the init.d script does not work.
Neither a test script works...
This is the test script that I am using to verify if the init.d support is working. The file 00test is placed in /system/etc/init.d/.
Code:
#!/system/bin/sh
#Init.d Test
busybox mount -o remount,rw -t auto /system
if [ -e /system/Test.log ]; then
rm /system/Test.log
fi
echo "kalo86 @ XDA 2014" > /system/Test.log
echo "Init.d is working !!!" >> /system/Test.log
kalo86 said:
Of course I have unlocked the bootloder but the init.d script does not work.
Neither a test script works...
This is the test script that I am using to verify if the init.d support is working. The file 00test is placed in /system/etc/init.d/.
Code:
#!/system/bin/sh
#Init.d Test
busybox mount -o remount,rw -t auto /system
if [ -e /system/Test.log ]; then
rm /system/Test.log
fi
echo "kalo86 @ XDA 2014" > /system/Test.log
echo "Init.d is working !!!" >> /system/Test.log
Click to expand...
Click to collapse
You're making it way too difficult. Just flash supersu in a custom recovery
Sent from my Nexus 5 using XDA Free mobile app
You could install an application such as Universal init.d from the playstore. It works for me on both my Nexus 5 and 10. Initially works without issue.
Sent from my Nexus 10 using XDA Premium HD app
jd1639 said:
You're making it way too difficult. Just flash supersu in a custom recovery
Sent from my Nexus 5 using XDA Free mobile app
Click to expand...
Click to collapse
Why difficult? This is the same identical mechanism that Chainfire uses to root your phone but I like to share a rooted-ROM ready to use.
The init.d folder is not supported at the moment. This is the truth.
And I don't want a workaround since the init.d support is very useful also for other stuff which is not only root access.