3

I am trying to modify AOSP to run a specific shell command on boot.

I tried to modify init.rc in system/core/rootdir/ to run a command on boot, but I could not make it work.

I know that I should use exec so I tried all these variations but none of them worked for me:

exec mkdir /data/local/tmp/test_directory
exec "mkdir /data/local/tmp/test_directory2"
exec -- mkdir /data/local/tmp/test_directory3
exec -- "mkdir /data/local/tmp/test_directory4"

I also tried all solutions on this page on Android 6.0 without any luck.

Anybody have an idea about what I am doing wrong?

0

You should grab the source code, modify init.rc and recompile it. The rootfs in Android gets 'refreshed' every time the device boots, so it makes no sense to edit init.rcdirectly on your device.
However there are alternative approaches and the following one is what I'm currently using.
Find a system service that you probably don't need at all, which in most times, is debuggerd. Locate its binary at /system/bin/debuggerd, rename it to something like debuggerd.bak, and then put your shell script in that place. Then in a shell, run

start debuggerd

and reboot. Your shell script will be executed every 5 seconds after the previous task died. It's recommended that you add a sleep loop at the bottom of your script if you want it to be run only once per boot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.