User init.d for CM12.1

For some reason the support for init.d and thereby userinit.d has been removed from CyanogenMod starting with CM12. Unfortunately it is not easy to re-activate the functionality, even more so if you want the change to survive future CM updates.

So I decided to create a trivial app that will simply execute run-parts on the /data/local/userinit.d directory when the phone completes booting to get the good old userinit.d back. To clone the git repository run:

git clone https://lisas.de/~alex/runuserinit.git

Find more details on the repository contents here.

After installation you will have to start RunUserinit once and hit the button.ย  When asked whether RunUserinit should be allowed to use root privileges accept that and make the setting permanent. Finally sshd will run automatically again, whenever my phone requires a reboot…

40 Comments

  1. Exactly what I was looking for since CM removed init.d support. Any possibility you can provide the apk?

  2. I haven’t really investigated whether there is something to consider when building ‘release’ apks, but I’ll send you the last debug apk I built – it works nicely on my phone running the latest CM13 builds.

  3. Any chance I could get my hands on that apk as well, I’ve been looking for this for a log time!.

    Thanks!

  4. Sure, James, I’ll send it right away. I need to investigate on how to get this on FDroid somehow.

  5. Thank you very much! Using your app is the ONLY way I could figure out to start the SSH server on Cyanogenmod, since /data/local/userinit.sh and even /system/bin/sysinit are not run anymore on CM13.

    For anyone else trying this solution: you can build the source code into an APK with the following command: ./gradlew assembledebug

  6. Would it be possible that you send me the apk? Would be great. Thanks for your effort.

  7. Hey JJ, same for me; good to know it works for you, too! And thanks a lot for adding the build instructions, I should update the post to include this information.

  8. If you are ok with running non-free software, you could use an app called Tasker (paid). It is possible to run tasks on device boot.

  9. Hi Alex,

    Thanks for sharing. I think its the way to start opensshd on boot of CM13.
    I have tried to clone your git repo, but without success.

    Is it possible that you will share the apk with me ?

    Thanks in advance.

  10. Hi Alex,

    Now, I have cloned your git project and it does like it should. Now the sshd starts on boot. ๐Ÿ™‚

  11. Excellent, good to hear that it works for you… now let’s see whether the current code will run with CM14, too…

  12. Thank you for the app, it works great ๐Ÿ™‚
    I’m using it on a CM-14.1 build from today.

    I just bumped the SDK and build tools versions and it compiled fine.

  13. Nice – haven’t upgraded my phone yet, but good to know that I wont have to worry about sshd when I finally install CM14.1. Thanks!

  14. Hi,

    I compiled apk, no issues here but then userinit.d does not seem to work. I launched the app, taped the button, it gave me ls /data/local/userinit.d….and that is it. I went there with Root explorer, there was no userinit.d so I created it, put my script inside, rebooted and nothing.

    What did I do wrong?

  15. Hey John, are the executable mode bits set for your script? If you haven’t done yet try adding them (as root) with ‘chmod a+x yourfile’. You can test running ‘su -c /data/local/userinit.d/yourfile’ from the terminal or via adb – if that works it should work via RunUserInit, too.

  16. Hi Alex,

    Thank you for sharing this. Could you maybe send me the apk as well?

    Thank you,

    Daan

  17. Do I have to put a single bash script in the userinit.d folder which executes other scripts or do I have to put all my scripts in the userinit.d folder?

  18. Unfortunately the wiki describing this has vanished together with CyanogenMod: Originally the start-ssh script was located in /system/bin and all you had to do was to copy it to /data/local/userinit.d/99sshd and make it executable (it’s still there on my phone running LineageOS). Some modifications to the sshd configuration files was also required. A quick search yields this gist to run on your host connected to the phone via ADB, from a quick review it seems to generate all the necessary files:
    https://gist.github.com/alainwolf/1579adfe032c15350322.

  19. Hi Alex, I managed to compile your app with android studio (it just wouldn’t from the command line), but having installed your app on my droid, I’m not getting UI. Could you send me the apk, so I could compare it with mine.
    Thanks ๐Ÿ˜‰

  20. Hello Alex, I have installed the linage OS in an S5, I will not compile the application, I can request that you send me the apk, thanks for sharing

  21. Thank you very much Alex, it works perfectly in lineage OS 7.1.2

  22. Hi Alex,
    I tried to find the apk in fdroid but I think it is not there yet.
    Can you send the apk to my email address please?
    Thanks in advance
    Klaus

  23. Sure, you should have it by now, unfortunately the FDroid upload is still a TODO.

    Alex

  24. Hi Alex,

    Can you please send me the APK?
    I’ve got your code, installed Java, downloaded Android Studio, which at startup downloaded 1GB addition data (I believe including the SDK), but I cannot get it to compile. It’s complaining that it doesn’t know where the SDK is. I also couldn’t find the Android SDK on my drive, but I’m sure that Android Studio showed that it is going to download it.
    When I try to use gradle in the Android Studio folder, then it complains that this is gradle 4.4 but the project needs 2.2.

    Thanks,
    Dirk

  25. Hi Alex,

    I forgot to ask if there’s any other way to run a script at boot time which does not require permanent root permissions.
    In an ideal solution, I would become (temporarily) root, make all the required modifications and then disable root access in the developer settings or maybe even unroot the device. The new script shall still be run at boot time (with root permissions).

    I don’t like to have permanently root enabled and I believe that with your app I have to.

    I’ve tried all day to find a solution (without installing an app) to run my script at boot time, but couldn’t find any solution. I was mainly trying to get a init_d.rc script working. Like described here:
    https://www.reddit.com/r/LineageOS/comments/7n6sue/initd_support/
    I can get my script to run AFTER booting by entering “start init_d” in the terminal under root, but I couldn’t manage to have it automatically run during boot. I’ve tried loads of possibilities for “on property:sys.boot…” and also tried to copy my stuff into an existing .rc file, but nothing helped.

    I’ve also tried adding it to /init.rc in the root folder, but /init.d is overwritten with the original version at every reboot. I know there are ways to extract it from ramdisk and to write a new boot image or so, but that sounds far too complicated and I don’t want to spend another day on it.

    Best Regards,
    Dirk

  26. Hi Dirk, you should’ve received the APK by now. Oh and with regards to running as root: Basically the app isn’t really “running” once the boot trigger has been handled, disabling root for apps shouldn’t really matter then. However you would have to find a way to automatically re-enable it before you reboot your device next time.

    Cheers, Alex

  27. Hi i hope you have the time to put in on Fdroid someday
    meenwhile can you email it to me as well..

  28. Hi

    great little app

    Used it on my previous phone with Lineageos 14

    Is there any reason why I shouldn’t use it on LineageOS17 ?

    When I run it I get a message that it was built for an older version of Android and to contact you.

  29. Works fine for me on LineageOS 17.1, I think the Android warning just let’s you know that the app might not fully utilize your display depending on the device’s aspect ratio. Probably I’d have to target a newer Android version, but that might impact backwards compatibility.

Leave a Reply

Your email address will not be published. Required fields are marked *