3

I am using LineageOS 18.1

When I was on LOS 16, I used to edit the file /system/etc/init.d/00banner and put my iptables commands there, e.g.:

#!/system/bin/sh
sh -c 'iptables -A OUTPUT -m owner --uid-owner 10195 -d 203.205.255.78/23 -j REJECT'

All iptables commands I put in there used to run on phone start up. But in LOS 18.1, the /system/etc/init.d/ directory was deprecated.

1. I created and filled the custom script with the iptables commands above:

touch /system/etc/custominit.sh
chmod 0755 /system/etc/custominit.sh

2. Then I edited /system/etc/init/hw/init.rc and I added to the end:

chmod 0755 /system/etc/custominit
exec /system/etc/custominit

3. I also tried adding:

service custominit /system/bin/custominit.sh
    disabled
    oneshot

But none of this worked.

What is it that I doing wrong? I have root access but I do not want to install any additional apps on my phone for this, as it was possible to do on LOS 16.

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Firelord
    Nov 23 at 17:26
2

Issue was solved by following instructions here:

https://ch1p.io/lineageos-run-shell-script-at-boot-as-root/

The main issue turned out to be missing full path of executables, e.g.:

/system/bin/iptables instead of iptables

4
  • ... that doesn't explain why 'echo test >> /data/local/tmp/test.log' did not work to you
    – alecxs
    Nov 21 at 19:29
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 22 at 11:56
  • @alecxs echo still did not work, even if I added /system/bin/echo it did not work, but iptables did. I don't know why..
    – light9876
    Nov 22 at 21:29
  • echo exist as 1) shell builtin and 2) toybox applet. I think it's bad timing /data is late mounted. anyway never mind, it was just for testing if service is executed - which it obviously does
    – alecxs
    Nov 22 at 22:16
1

Once you added your service as "disabled" on init.rc you must call it on boot, add the following lines:

on boot
    custominit your_params

I hope it solves your problem

2
  • The syntax isn't correct. It should be start custominit your_params. But still this might not work due to other reasons. Nov 21 at 12:29
  • 1
    No, it did not work..
    – light9876
    Nov 21 at 15:12

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.