How to enable init.d to function in LineageOS 14.x (and later more?)

ramast_

Member
Sep 21, 2016
25
15
0
I am using LineageOS 14 on my Galaxy S5 and while I do have the directory /system/etc/init.d , its scripts are not executed on startup as one would expect.
Searching different forums didn't lead to much beyond installing some random person's script with root permission or doing hacks.

I've invested sometime to get init.d work on my phone and wanted to share the how to with you:

Prerequisite:
Root access (shell) [ I am using addonsu-14.1-arm if that make a difference ]
LineageOS 14 (not tested on other versions but should work)

Steps:

1. mount your system partition as read/write
Code:
mount -oremount,rw /system
2. go to init directory
Code:
 cd /system/etc/init/
3. create file init_d.rc with following content
Code:
service init_d /system/bin/sh /system/bin/sysinit
    user root
    group root
    disabled
    oneshot
    seclabel u:r:sudaemon:s0

on property:sys.boot_completed=1 && property:sys.logbootcomplete=1
    start init_d
That's it.

Explanation:

/system/etc/init/ is android's version of linux's init.d but it have very different syntax and restricted set of commands.

the file init_d define a service called init_d which basically execute sysinit script (the script responsible for running /etc/init.d/ scripts).

the service is set to be disabled so it won't run by default. Finally I say that when the system finish booting start the service. the oneshot keyword is important because without the system will keep executing sysinit each time it exit.

the seclabel define SELinux label for this service, this one should give it full access
 

Whammamoosha

Senior Member
Jan 6, 2012
79
29
0
54
Rio de Janeiro
Worked like a charm!

I needed it to run swapon once (to free some unused RAM) without modifying any system files, only adding new ones, so system updates wouldn't overwrite the configuration.

Thank you very much!

Running LineageOS 15.1, 2018-11-30 nightly build on griffin (XT1650-3).

I am using LineageOS 14 on my Galaxy S5 and while I do have the directory /system/etc/init.d , its scripts are not executed on startup as one would expect.
Searching different forums didn't lead to much beyond installing some random person's script with root permission or doing hacks.

I've invested sometime to get init.d work on my phone and wanted to share the how to with you:

Prerequisite:
Root access (shell) [ I am using addonsu-14.1-arm if that make a difference ]
LineageOS 14 (not tested on other versions but should work)

Steps:

1. mount your system partition as read/write
Code:
mount -oremount,rw /system
2. go to init directory
Code:
 cd /system/etc/init/
3. create file init_d.rc with following content
Code:
service init_d /system/bin/sh /system/bin/sysinit
    user root
    group root
    disabled
    oneshot
    seclabel u:r:sudaemon:s0

on property:sys.boot_completed=1 && property:sys.logbootcomplete=1
    start init_d
That's it.

Explanation:

/system/etc/init/ is android's version of linux's init.d but it have very different syntax and restricted set of commands.

the file init_d define a service called init_d which basically execute sysinit script (the script responsible for running /etc/init.d/ scripts).

the service is set to be disabled so it won't run by default. Finally I say that when the system finish booting start the service. the oneshot keyword is important because without the system will keep executing sysinit each time it exit.

the seclabel define SELinux label for this service, this one should give it full access
 
Last edited:

Lordlight

Member
Aug 19, 2018
28
2
0
Thank you so much !

I am using LineageOS 14 on my Galaxy S5 and while I do have the directory /system/etc/init.d , its scripts are not executed on startup as one would expect.
Searching different forums didn't lead to much beyond installing some random person's script with root permission or doing hacks.

I've invested sometime to get init.d work on my phone and wanted to share the how to with you:

Prerequisite:
Root access (shell) [ I am using addonsu-14.1-arm if that make a difference ]
LineageOS 14 (not tested on other versions but should work)

Steps:

1. mount your system partition as read/write
Code:
mount -oremount,rw /system
2. go to init directory
Code:
 cd /system/etc/init/
3. create file init_d.rc with following content
Code:
service init_d /system/bin/sh /system/bin/sysinit
    user root
    group root
    disabled
    oneshot
    seclabel u:r:sudaemon:s0

on property:sys.boot_completed=1 && property:sys.logbootcomplete=1
    start init_d
That's it.

Explanation:

/system/etc/init/ is android's version of linux's init.d but it have very different syntax and restricted set of commands.

the file init_d define a service called init_d which basically execute sysinit script (the script responsible for running /etc/init.d/ scripts).

the service is set to be disabled so it won't run by default. Finally I say that when the system finish booting start the service. the oneshot keyword is important because without the system will keep executing sysinit each time it exit.

the seclabel define SELinux label for this service, this one should give it full access
You are great bro !
I try it on lineage os 14.1 on moto G and it works !
I tried many ways to do this but all of them are not effective, thanks
 

ramast_

Member
Sep 21, 2016
25
15
0
There is a process responsible for showing bootanimation, I don't remember exact process name but should contain word "animation" in it.

Once you figured out its name, you can make your script check every second - in a while loop - if that process is running or not. Once the process stopped, you can assume that bootanimation has stopped.

There might be a better way but I honestly don't know.