How to run shell scripts at boot time as root on LineageOS 18.1 without Magisk
Enable developer settings.
Enable USB debugging (adb) and rooted debugging.
Warning: rooted debugging is a very dangerous feature, don't forget to turn it off when you've done!
Attach your Android phone to a computer via USB cable, verify that device is detected by running
adb remount /. This will remount root filesystem in rw mode.
adb shell to get the root shell on your phone.
On the phone, go to
/system/etc/init and create a file named
myboot.rc with following content:
exec u:r:su:s0 root root -- /system/etc/myboot.sh
/system/etc/myboot.sh, write your script and make it executable.
Note: the first line of the script must be
Note: If you want to use iptables in this script (or some other external binary), use full path (
/system/bin/iptables) instead of just
/system/bindirectory seems to be missing from the
$PATHwhen the script is launched.
Then open the
/system/addon.d/50-lineage.sh file, find the
list_files function and add paths to files you've just created (relative to
/system/) to the list. It is to backup and restore listed files on upgrade. It should look like this:
This is all, now exit root shell, disable rooted debugging, reboot your phone and see if it worked.