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 devices.

Run adb root.

Run adb remount /. This will remount root filesystem in rw mode.

Run 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:

on boot
    exec u:r:su:s0 root root -- /system/etc/

Then create /system/etc/, write your script and make it executable.

Then open the /system/addon.d/ 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:

list_files() {
cat <<EOF

That's all, exit root shell, disable rooted debugging, reboot your phone and see if it worked.

If you have any comments, contact me by email.
powered by OpenBSD
© ch1p 2021