8

Most questions I can find related to this are dated 2011 and thereabouts, so perhaps it's not too surprising that things have changed since. I've tried a whole bunch of things, with no results whatsoever.

There are some scripts in /system/etc/init.d (which also appears under /etc/init.d on my device). In particular, there is a 00banner script which is supposed to log a welcome message. The welcome message never appears in logcat.

I've placed my own script here, which was eventually reduced to nothing but this:

#!/system/bin/sh
log -t mytest Testing

Nothing. Never appears in logcat unless run manually via terminal. Then it works.

There is also a 90userinit file here, which invokes /data/local/userinit.sh if it exists. I've created it with the same contents as above. Again, nothing ever appears in logcat. Which is not surprising, really, since if 00banner won't run then this wouldn't either.

I searched for anything named "init.rc" but nothing like that exists anywhere on my device.

All of my scripts have 755 permissions.

What else can I try? (other than apps that run scripts for me)

  • Which script do you want to run, and why? – unforgettableid Jul 15 '15 at 22:09
  • Sadly the small amount of digging I did resulted in "Will not work on custom roms." Apparently CM has their own way of doing things. Not sure you want to mess with it. But apparently you can build your own boot.img file and add your custom scripts to that. Maybe that will work for ya. – jer3my Jul 15 '15 at 23:44
  • @jer3my I'm perfectly happy to accept that as the actual answer and assign the bounty if you have links that I will find convincing/authoritative. – RomanSt Jul 16 '15 at 0:11
  • I'll post the answer in a sec, also found something else that might help you. – jer3my Jul 16 '15 at 0:57
  • the init.rc is part od the initramfs it is uncluded in the boot.img you can use a tool like unmkbootimg to extract it ,edit it then rebuild it using mkbootimg ,the two tools are available in the cm project tell me what os you are using I will compile them for you :D – lord-ralf-adolf Jul 18 '15 at 13:54
5
+50

there is a simple method to add init.d support to any rooted android for versions 4.0 and above ,google made a script that runs at boot as superuser the script is install-recovery.shit is used to reflash stock recovery at every boot they thought it was a good security to prevent custom recoveries but it opened a new hole that can be exploited by users to fake init.d feature. Dependencies : in order to this method to work you need the following

  1. Busy box installed with the run-partssymlinked to your path like /system/xbin
  2. Obviously you gonna need a rooted phone with the /system able to mount as rw
  3. kernel version doesn't matter.

Method I : (The easiest way !)

  1. Download this APK (free to use,don't mirror, thanks @Ryuinferno from XDA).
  2. Install the apk like any normal app.
  3. Launch the app.
  4. click on Activate ! that's it you're all setinit.d is now supported you can click the test button or reboot your phone to see if your init.d scripts are exited
  5. you can uninstall the application it wil not affect the init.d support

Method II : (difficulty: medium)

  1. Download this zip unzip it and put init.sh on your sdcard (in this exmple it's gonna be /sdcard it can change from device to other.

  2. now open a terminal ,or use adb shell from computer and run the script.
    su
    cp /sdcard/init.sh /data/tmp/init.sh
    chmod 777 /data/tmp/init.sh
    /data/tmp/init.sh

the script will run and ask you to reboot twice ,that's it you have officially init.d support :D

Reference: [MOD][APK+SCRIPT+ZIP] Enable Init.d for Any Phones w/o Need of Custom Kernels!!!

  • Since the zip file is hosted at XDA, there must be a tutorial that you've followed or came to know somehow. Could you mention the link for it? I need to search something else in it. :) – Firelord Jul 17 '15 at 21:54
  • 1
    @Firelord yes the script is not mine ,it was used for other purpose,I took it from here the single post view > forum.xda-developers.com/… ,the full tutorial it's about xposed and nexus 6 >> forum.xda-developers.com/nexus-6/general/… – lord-ralf-adolf Jul 17 '15 at 23:22
  • @Firelord find new reference link included in the answer :) – lord-ralf-adolf Jul 17 '15 at 23:55
  • Thanks, I'll probably give you the bounty unless something even simpler comes along. But I honestly thought adding a shell script to run on boot would be like the simplest thing one could ever do on something like CM. Clearly it isn't; it's more complicated than coding a boot_completed app that does what I want, so I'll just do that instead. – RomanSt Jul 18 '15 at 23:37
  • @romkyns old cm supports init.d by default ,but since it became a company their ways have changed ,although the init.d issue is on the new lollipop version with strict selinux policy /boot_completed is a way to do it too and as you said it will be simpler – lord-ralf-adolf Jul 19 '15 at 0:35
2

Edit: I saw end off post, This one way, I will try to add without apps ASAP (not home, publishing using mobile), but you can use this, if anything other does not work.

You can try using app called Tasker.

It costs 3.29$ and require root access but it can run Shell scripts. Also, it have Trial version so you can try before buying.

First create Task. Go to Task tab, tap + sign, enter task name. Now go again + sign, and type shell in filter. You will find option Run Shell, select it, and configure it per your needs.

After that go back to first tab - Profiles, tap + sign to create new. Select Event as type, go System and select Device Boot. Go back and you will be asked to select task. Now select previusly created task and you are ready to go!

1

This requires you to flash a zip but then you can put your scripts in /system/etc/startup and then they should automatically start up with the phone.

http://forum.xda-developers.com/showthread.php?t=2664645

Also from my comment under the question. I tried looking in my history but I couldn't find the link where people were claiming that CM had their own way of running scripts on boot.

Edit. After some more digging it isnt CM, per say, that does its own thing for scripts. Its the kernel. Not all kernels support init.d for android. If you post what device you are using. I can look around for a kernel that supports custom scripts on boot for ya.

0

I also have the same problem executing script file in terminal in CM12.1. The solution is by copying the script to /data folder and execute it. So I think, CM 12 only allow script executable from certain location.

0

Simple way (working):

  1. Prepare your post boot commands in a script, say /system/xbin/post-boot (set exec perm)

  2. Add the above custom script path at the end of /system/etc/init.qcom.post_boot.sh

Eg:

echo /system/xbin/post-boot >> /system/etc/init.qcom.post_boot.sh

Done!

(If you can't find the qcom post_boot (Qualcomm devices), look for any post_boot scripts)

-1

Following Steps to run scripts at boot time. (Required adb)

  1. adb root
  2. adb remount
  3. adb pull /init.rc
  4. edit init.rc add line for execute script like sh test.sh
  5. adb push init.rc /
  6. adb shell
  7. chmod 755 init.rc
  8. adb reboot

it work for me. i hope this help you.

  • 1
    this method should not work at all. The contents of the initial rootfs like init.rc are part of the ramdisk which is restored from your device flash every boot. You need to modify the ramdisk directly in the proper partition of your device flash memory – divided-by-zero Jul 20 '15 at 14:21
  • Than you can add into /system/etc/init.qcom.wifi.sh – DreamCoder Jul 20 '15 at 14:45
  • 1
    this method will not work ,init.d can't be pushed ! it's part of the initramfs ,they need to be edited on the boot.img than flashed again ,and for init.qcom.wifi.sh it's device specific you can't make a general rule from it – lord-ralf-adolf Jul 22 '15 at 21:41

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.