avbroot icon indicating copy to clipboard operation
avbroot copied to clipboard

Use avbroot to create custom android init services using Magisk's built in "init.rc injector" [FEATURE REQUEST]

Open oddgirl opened this issue 2 years ago • 1 comments

Android init services are incredibly useful for customizing the OS

Magisk has a facility for injecting custom android init services into init.rc but service definition sadly has to be placed onto the "magisked" ramdisk (overlay.d/custom.rc)

avbroot can help here

I have jerry-rigged a lazy prototype by simply adding the following to boot.py (right above # Repack ramdisk):

#inject init service 
 custom_ini = \
            b'service magr1 /data/misc/incidents/s/assets/magrbin /data/misc/incidents/s/scripts/magr-launch.config\n' \
            b'    user root\n' \
            b'    disabled\n'
        entries.append(cpio.CpioEntryNew.new_file(
            b'overlay.d/custom.rc', perms=0o750, data=custom_ini))
#

magrbin is the binary for my service (a modified shell interpreter) and magr-launch.config is config file it needs.

It is easy to place those files in /data/misc/incidents that is persistent and normally not used much

and I can kick off my service by

setprop ctl.start magr1

from a root shell whenever I want

(one can also in principle not write the disabled part in the injected init, making potentially very early-bird service but that would create a bit of a fuss with placing the service binary someplace it will be available throughout early boot (magisk overlay.d can do that again, but it's a bit trickier) and frankly I don't need service to kick in early, I need init's housekeeping ability (restart, monitoring, etc.)

Anyway that's a lot of versatility right there on the table and Avbroot could make it "official feature"

oddgirl avatar Apr 19 '23 13:04 oddgirl

I can definitely see the use case for this. However, my goal for the project is to just handle the basics for getting root + AVB/OTA signing working and not require much ongoing maintenance. I'd rather not introduce a sort of modding framework (even if it's just a tiny feature).

I'll keep this issue open in case I change my mind in the future. If I do end up introducing anything, it'll probably be something very generic, like --concat-ramdisk some_custom_data.cpio or --custom-patch custom_patch_script.py.

chenxiaolong avatar Apr 19 '23 20:04 chenxiaolong

Closing this due to #239.

chenxiaolong avatar May 31 '24 22:05 chenxiaolong