Usage of init.d scripts - HTC One V

Hi
Actually there are already a lot of threads on xda which describe this
so everyone interessted can already get a enough information about it.
If you have specific questions you can of course use this thread
for asking them.
I just want to share some "insights" that I recently discovers which maybe
of interest for e.g. ROM developers that use init.d scripts
Typically init.d scripts are "enabled" by using the following in
the "main" startup script that is executed right after the kernel
has booted which is /init.rc
/system/xbin/busybox run-parts /system/etc/init.d
So it requires busybox and is using the command "run-parts" which is
simply executing all scripts found in /system/etc/init.d
This is how the line looks in Titanium kernels
but this line can create a small "problem"
Depending on your busybox installation run-parts is already a symlink
in /system/xbin to busybox
The effect is that now all scripts are executed TWICE
If you use e.g. myONE you can check this by examing
/data/zipalign.log where yuo will see everything twice
The init.rc parser seems to "know" that run-parts is already a executable
and therefore runs both
busybox run-parts /system/etc/init.d
AND
run-parts /system/etc/init.d
Aside from the "bad" that scripts are executed twice which needs more time
it can have unwanted sideeffects depending on what you are doing in init.d scripts
There are two ways to "fix" this
1) remove the symlink run-parts in /system/xbin
2) change the line in init.rc to
run-parts /system/etc/init.d
But since this file is typically in the ramdisk of the boot.img you
dont have full control of this file since flashing a different kernel
may override it again.
Actually the best way to fix this would be in init.rc to check if the
symlink is there or not. But I dont know have enough knowledge about
all of this at the moment.
regards
max

Thanks for the heads up. I just checked mine and all the init scripts were running twice so I moved /system/xbin/run-parts to /system/xbin/run-parts.bak

this should be posted under "GENERAL"....

1ceb0x said:
this should be posted under "GENERAL"....
Click to expand...
Click to collapse
Feel free to tell the mod
regards
max

Related

init.d scripts not running?

Ok so I was able to make a bootable boot.img but now I'm trying to get the init.d scripts working. Basically I'm looking to run some commands on boot and felt this is the best way. What I did was put the following in my boot.img's init.rc file:
Code:
# Execute files in /etc/init.d before booting
service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
disabled
oneshot
Then in my update-script file I added the following to make the directory and containing files executable:
Code:
set_perm_recursive 0 2000 0755 0750 SYSTEM:etc/init.d
set_perm 0 0 0755 SYSTEM:etc/init.d
Then I packaged up the boot.img, added to an update.zip (with custom rom) and flashed it. However it doesn't appear that the scripts inside /system/etc/init.d are running. Anyone have any ideas for me? Anything I'm forgetting to do?
I don't think you can add a directory and have it execute every script within the directory. I believe you need to explicitly call the scripts within the directory. At least that's how every other init.d implementation I've ever worked with functioned.
Good luck!
cent
CentroniX said:
I don't think you can add a directory and have it execute every script within the directory. I believe you need to explicitly call the scripts within the directory. At least that's how every other init.d implementation I've ever worked with functioned.
Good luck!
cent
Click to expand...
Click to collapse
Could you elaborate. I'm not too familiar with the init.d stuff with android right now. So how would I call these scripts at startup? I can't tell where in other roms these scripts are being called.
chuckhriczko said:
Could you elaborate. I'm not too familiar with the init.d stuff with android right now. So how would I call these scripts at startup? I can't tell where in other roms these scripts are being called.
Click to expand...
Click to collapse
Ok, so if you had a script in /etc/init.d called 'doit', you would invoke it by calling /etc/init.d/doit.
So I'd try:
Code:
# Execute files in /etc/init.d before booting
service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d/doit /system/etc/init.d/doit2
disabled
oneshot
I'll be honest that I have zero experience with startup scripts in Android, but I have over 15 years experience as a *nix adminitrator. In every *nix I've ever used, you can't just call upon a directory and have every script within it execute; You have to explicitly call each script.
CentroniX said:
Ok, so if you had a script in /etc/init.d called 'doit', you would invoke it by calling /etc/init.d/doit.
So I'd try:
Code:
# Execute files in /etc/init.d before booting
service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d/doit /system/etc/init.d/doit2
disabled
oneshot
I'll be honest that I have zero experience with startup scripts in Android, but I have over 15 years experience as a *nix adminitrator. In every *nix I've ever used, you can't just call upon a directory and have every script within it execute; You have to explicitly call each script.
Click to expand...
Click to collapse
Sounds good to me. I'll try that and keep this thread updated.
in the custom kernels i built for android 2.1 this is the method i used to call custom scripts in init.rc . pretty sure it should work for you, just change the paths and commands as you need!
## SDX processes
# install busybox
service busybox /sbin/busybox --install -s /bin/
oneshot
# run custom SDX functions
service sdx /sbin/sdx.sh
oneshot
for those wanting to learn the technical details on the init.rc google android has a great article on the commands for their init.rc file.
http://source.android.com/porting/bring_up.html - scroll down to the section title Android Init Language
joeykrim said:
in the custom kernels i built for android 2.1 this is the method i used to call custom scripts in init.rc . pretty sure it should work for you, just change the paths and commands as you need!
## SDX processes
# install busybox
service busybox /sbin/busybox --install -s /bin/
oneshot
# run custom SDX functions
service sdx /sbin/sdx.sh
oneshot
google android has a great article on the commands for their init.rc file but i cant seem to find it at the moment ... will post back if i get it.
Click to expand...
Click to collapse
Even better. Thanks!
CentroniX said:
Ok, so if you had a script in /etc/init.d called 'doit', you would invoke it by calling /etc/init.d/doit.
So I'd try:
Code:
# Execute files in /etc/init.d before booting
service sysinit /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d/doit /system/etc/init.d/doit2
disabled
oneshot
I'll be honest that I have zero experience with startup scripts in Android, but I have over 15 years experience as a *nix adminitrator. In every *nix I've ever used, you can't just call upon a directory and have every script within it execute; You have to explicitly call each script.
Click to expand...
Click to collapse
I just realized the run-parts command in busybox runs a bunch of scripts in a directory (description if you run busybox runparts by itself) so this should work.... but it doesnt...
From the documentation joeykrim linked:
Services
Services are programs that init launches and (optionally) restarts when they exit.
Services take the form of:
service <name> <pathname> [ <argument> ]*
<option>
<option>
Click to expand...
Click to collapse
So you'd want:
Code:
service <name> /etc/init.d/your-script-here
oneshot
You'll need to add that block for each script you wish to run.
Furthermore, the documentation states
disabled - This service will not automatically start with its class. It must be explicitly started by name.
Click to expand...
Click to collapse
So the fact that you have the 'disabled' option set might be the reason it's not executing.
CentroniX said:
From the documentation joeykrim linked:
So you'd want:
Code:
service <name> /etc/init.d/your-script-here
oneshot
You'll need to add that block for each script you wish to run.
Furthermore, the documentation states
So the fact that you have the 'disabled' option set might be the reason it's not executing.
Click to expand...
Click to collapse
Well that disabled is why it wasn't trying to run the script however when I removed disabled it kept looping at the first boot screen (before the animated one). So I just tried taking the code out of the init.rc and putting it in the bootcomplete.supersonic.rc file. This allowed the phone to boot but it looks like the scripts aren't running at all. Ugh. lol
Ok so I figured it out. In all of the init.d setups I have seen they create a service in the init.rc that will load all the scripts in the init.d directory and then after the file system loads they start that service. Well, the boot process for the Evo is apparently a little different. HTC changed things to have seperate rc scripts for when the boot and shutdowns are complete. So the bootcomplete.supersonic.rc file is what we want to modify.
This script doesn't work with the init.rc commands but it does work with simple linux shell commands. So simply adding
Code:
/system/xbin/busybox run-parts /system/etc/init.d
to the bottom of this file will call all scripts inside the /system/etc/init.d folder on boot completion.
Good to know, and glad you got it working!! Hopefully we'll see a kickass ROM from you soon!
CentroniX said:
Good to know, and glad you got it working!! Hopefully we'll see a kickass ROM from you soon!
Click to expand...
Click to collapse
Well it will be better than my last (hopefully released today) but nothing truly kick ass until we get kernel source in which the camera works. Oh the possibilities.
chuckhriczko said:
This script doesn't work with the init.rc commands but it does work with simple linux shell commands. So simply adding
Code:
/system/xbin/busybox run-parts /system/etc/init.d
to the bottom of this file will call all scripts inside the /system/etc/init.d folder on boot completion.
Click to expand...
Click to collapse
so you added that line to bootcomplete.supersonic.rc ?
interesting HTC modified the boot order and setup, but not surprising.
glad we now know how to execute multiple scripts.
out of curiosity and hopefully not off topic, what are you executing in multiple scripts which couldn't be executed in one script called by the original init.rc file?
for reference, when running one individual script, the code i posted above, adheres to google's standard and should work fine.
# run custom SDX functions
service sdx /sbin/sdx.sh
oneshot
joeykrim said:
so you added that line to bootcomplete.supersonic.rc ?
interesting HTC modified the boot order and setup, but not surprising.
glad we now know how to execute multiple scripts.
out of curiosity and hopefully not off topic, what are you executing in multiple scripts which couldn't be executed in one script called by the original init.rc file?
for reference, when running one individual script, the code i posted above, adheres to google's standard and should work fine.
# run custom SDX functions
service sdx /sbin/sdx.sh
oneshot
Click to expand...
Click to collapse
Oh I could have put it all in one script but for cleanliness I wanted multiple scripts. This way they can more easily be read and modified. I hate ugly dirty cluttered code and directories.
Actually, you could've left the lines the way they were...
Right above class_start default, put the following two lines in:
start sysinit
on property:cm.filesystem.ready=1
The last line is to stop init.rc until you set the cm.filesystem.ready property (you do that from one of the scripts in /system/etc/init.d)
chuckhriczko said:
Ok so I figured it out. In all of the init.d setups I have seen they create a service in the init.rc that will load all the scripts in the init.d directory and then after the file system loads they start that service. Well, the boot process for the Evo is apparently a little different. HTC changed things to have seperate rc scripts for when the boot and shutdowns are complete. So the bootcomplete.supersonic.rc file is what we want to modify.
This script doesn't work with the init.rc commands but it does work with simple linux shell commands. So simply adding
Code:
/system/xbin/busybox run-parts /system/etc/init.d
to the bottom of this file will call all scripts inside the /system/etc/init.d folder on boot completion.
Click to expand...
Click to collapse
tkirton said:
Actually, you could've left the lines the way they were...
Right above class_start default, put the following two lines in:
start sysinit
on property:cm.filesystem.ready=1
The last line is to stop init.rc until you set the cm.filesystem.ready property (you do that from one of the scripts in /system/etc/init.d)
Click to expand...
Click to collapse
interesting approach! thanks for sharing this!
i assume this on property cm.filesystem.ready feature must be exclusive to android?
would the logic also follow, you'd set ready to 0 in the last of the scripts located under /system/etc/init.d ?
would there be any downside to this approach? if there was an error in the script files and they stopped, would loading of the init.rc also stop and severely stall the boot up process?
joeykrim said:
in the custom kernels i built for android 2.1 this is the method i used to call custom scripts in init.rc . pretty sure it should work for you, just change the paths and commands as you need!
## SDX processes
# install busybox
service busybox /sbin/busybox --install -s /bin/
oneshot
# run custom SDX functions
service sdx /sbin/sdx.sh
oneshot
for those wanting to learn the technical details on the init.rc google android has a great article on the commands for their init.rc file.
http://source.android.com/porting/bring_up.html - scroll down to the section title Android Init Language
Click to expand...
Click to collapse
Also:
https://android.git.kernel.org/?p=p...5790acb05904ddd109ed33de3863a4b413d53;hb=HEAD
And take a look at:
http://www.androidenea.com/2009/08/init-process-and-initrc.html
leonnib4 said:
Also:
https://android.git.kernel.org/?p=p...5790acb05904ddd109ed33de3863a4b413d53;hb=HEAD
And take a look at:
http://www.androidenea.com/2009/08/init-process-and-initrc.html
Click to expand...
Click to collapse
hey man does this work with the desire too??????? cause i have been unable to achieve custom boot scripts with desire init.rc
Im confused can someone help me figure it out!
ok so here the confusion
set_perm_recursive(0, 0, 0777, 0777, "/system/etc/init.d"); changhong z-me updater script
set_perm_recursive(0, 2000, 0755, 0755, "/system/etc/init.d"); ideos x6 updater script
I don't know which 1 to put in the update script!?!
Im trying to port cm7 to changhong z-me and using ideos x6 as port.

Init.d do not run

I am using the rom IML74K Android 4.0.3 Build 8 from bigxie and franco.Kernel #13.
I think the rom and kernel suppose to support init.d scripts. And I can found the script in etc/init.d named 97schedmc.
I wanna the hotplug function, so I put a file named 98hotplug(I don't know how to named the script), but I found it would not work. The parameter would not change after restart the device. Even I excute it(rename to sh file) in RootExplor, the parameter did not changed.
I try to run or sh the command in adb shell, it works fine, and the parameter changed.
I thinks it is relate to the access right issue, but I don't know how to fix it.
Could any one can help me?
Thanks for the guy who reply me.
you most chmod the files. Just sticking them it won't allow them to run.
I am not such understand... What should I do then?
chmod them?
755 works.
Hi,
Like this:
For 755,right permissions for scripts in Init.d folder,a good link i think: http://www.elated.com/articles/understanding-permissions/
Do not create a sh. file,for example in Root Eplorer,go to system/etc/init.d and menu/New file then put your script with #!/system/bin/sh first then space then enter.
Or on your pc take a init.d file in a rom,erase the script,copy yours with the correct script,reput in your phone,set the correct permissions then reboot.
Are you really sure your rom/kernel suppot Init.d ?
Just one question,I do not use this combo...
Hoping this helps
Permissions are set correctly, the kernel (faux123) supports init.d scripts, and the script works when run from terminal, but it still does not run on boot.
Thanks for your reply and great help!
I am sure the kernel support the init.d, but I not sure the rom, is it necessary both of them to support init.d?
What is your combo??
Hi,
To monkeyzou,yes i use the same kernel wich support Init.d script,but i use aokp rom,the rom you are using seems not support Init.d (it is not specified?),but in any case the Franco kernel support it,and it create the necessary lines in "init.rc" for activate the init.d support+the init.d file+the correct permissions,all automatically when you flash the kernel...
So i don't now what is wrong
Are you sure you set the right permissions for your file script in init.d?Are you sure your script is written correctly?
Can you share it?
After that my knowledges stop there,sorry...
init.d support only needs to be in the kernel ramdisk. As for rom support, that only goes as far as needing the directory. Note that some of the kernels out there are anykernel format and therefore would not support init.d scripts.
I was trying to do the exact same thing and couldn't make it work either. Eventually I just used Script Manager (on market) and let it run the script at boot.
Here is my script:
Code:
#!/system/xbin/bash
echo 1 > /sys/module/dsscomp/parameters/hotplug_enabled
Re,
To monkeyzou can you test this script at the bottom of my message?
Remove the .txt and copy it to your init.d folder then set the right permissions for it as i have shown above.
Or test another script where you could see a change?
At the end are you sure your script don't work?
After reboot with the script go to /sys/module/dsscomp/parameters/hotplug_enabled and see if the value is set to 1,if yes it's ok,if no (so set to 0),i don't know more...
ctbear said:
I was trying to do the exact same thing and couldn't make it work either. Eventually I just used Script Manager (on market) and let it run the script at boot.
Here is my script:
Code:
#!/system/xbin/bash
echo 1 > /sys/module/dsscomp/parameters/hotplug_enabled
Click to expand...
Click to collapse
Hi,
Test the script i've posted above:
#!/system/bin/sh
echo 1 > /sys/module/dsscomp/parameters/hotplug_enabled
Click to expand...
Click to collapse
I hope that helps
viking37 said:
Hi,
Test the script i've posted above:
I hope that helps
Click to expand...
Click to collapse
Thanks. Unfortunately it still didn't work, but I've found a workaround (looks stupid, but somehow works):
Basically I have a script file at the root of storage, and it contains just the echo line. My init script will just run that /sdcard script and it works fine.
viking37 said:
Re,
To monkeyzou can you test this script at the bottom of my message?
Remove the .txt and copy it to your init.d folder then set the right permissions for it as i have shown above.
Or test another script where you could see a change?
At the end are you sure your script don't work?
After reboot with the script go to /sys/module/dsscomp/parameters/hotplug_enabled and see if the value is set to 1,if yes it's ok,if no (so set to 0),i don't know more...
Click to expand...
Click to collapse
Tried this script and it works

[Solve][Q] Enable logcat in Glados Kernel

Hello,
I am trying to develop an app for my Samsung Galaxy Nexus but I have problem with the logcat :
?:??: W/?(?): Unable to open log device '/dev/log/main': No such file or directory
I think it's deactivated in the Glados Kernel which I use, so if somebody know how to enable it without change of kernel, it would be very helpful.
Thanks in advance,
Just load the logger kernel module
Create a file called "98logcat" or similar in /system/etc/init.d with contents
Code:
#!/system/bin/sh
insmod /system/modules/logger.ko
Thanks for your answer.
You made just a small mistake. It's :
Code:
insmod /system/modules/logger.ko
I see the logcat of my device but I can't see the log of my app. When I do a Log.i("Msg", "Msg") for example, nothing appear in the logcat and I have this message at the launch of my app :
03-13 20:09:23.988: I/AndroidRuntime(3357): NOTE: attach of thread 'Binder Thread #3' failed
Unless it was introduced with that kernel, there is no /system/modules.
OP, check system/etc/init.d for a script.
See if it contains:
rm /dev/log/main
If it does, comment it out or remove it, save, and reboot your device.
benoitm76 said:
Thanks for your answer.
You made just a small mistake. It's :
Code:
insmod /system/modules/logger.ko
I see the logcat of my device but I can't see the log of my app. When I do a Log.i("Msg", "Msg") for example, nothing appear in the logcat and I have this message at the launch of my app :
03-13 20:09:23.988: I/AndroidRuntime(3357): NOTE: attach of thread 'Binder Thread #3' failed
Click to expand...
Click to collapse
Ah, sorry, made a typo there.
Hmm, my logcat seems to show messages from my installed apps fine. I suppose this is a stupid question to ask since your logcat does work, which probably means the init.d script is running, but your permissions on your new init.d file are 755 root root, right?
If that isn't the problem, I have one more stupid guess to hazard: I think this is what a normal init.rc file is supposed to contain to run init.d scripts:
Code:
service userinit /system/xbin/busybox run-parts /system/etc/init.d
oneshot
class late_start
user root
group root
However, my init.rc mysteriously contains this instead:
Code:
service run_parts /system/xbin/run-parts /system/etc/init.d
class main
oneshot
Did you turn device encryption on? Might it be that the logcat module has to be loaded earlier in the boot process than when /data is decrypted (late_start services run only after the decryption, I think, unlike main, which run before that)?
Sorry if this isn't helpful. I googled and found a few others saying they faced your problem (no app messages), but no one ever posted that they'd found a solution. This difference in my init.rc (class main as opposed to class late_start) is the only difference I could think of that might be affecting this.
Problem solve.
@vincom2 : Your first method work good, I made just a little mistake when I created the file the first time.
Thanks for your help !
I've been trying to get logcat to work on my phone all day (AOKP M4 and GLaDOS 1.24) with very little luck. Creating /etc/init.d/98logger containing
Code:
#!/system/bin/sh
insmod /system/modules/logger.ko
doesn't seem to do anything. I reboot, the the module isn't loaded. Same behavior if I add it at the end of an existing init.d script.
Manually executing
Code:
insmod /system/modules/logger.ko
doesn't do me any good either... "lsmod" doesn't show any modules loaded.
Anyone have any ideas? I really like the performance and battery life of GLaDOS, but get really frustrated that I can't do something simple like pull a logcat.

How to know if custom kernel and init.d scripts are working?

Sorry to post here cuz the FAQ thread was locked
create this script
Code:
#!/system/bin/sh
touch /data/kurotsugi_test.txt
echo "have a nice day" > /data/kurotsugi_test
put that file into init.d, give 777 permission then reboot. if your kernel support init.d script you'll find kurotsugi_test.txt in /data.
PS: don't forget to install busybox.
download the attached file below and extract
put inside the system/etc/init.d folder
set permissions to r-w-x times 3 (777)
restart
go to ---> data folder/local/tmp/init.d_log_test.txt
and there should be the word "done" <--- confirmed working
ps. note the time and date

Help. Need default applets

I need default ash and sh applets.
/system/bin/ash and /system/bin/sh
Can someone zip, and upload those 2 files for me? Pretty please.
Reason: my busybox installer (meefik) replace those 2 applets with symlink to its busybox – which is a no no, and I lost root because of that.
Nevermind, i just reflashed my whole ROM.
Careful with hardlinked 'sh' or any binaries.. and any busybox installers that override it.

Categories

Resources