How to run `chmod` command on boot on Android 10? I have an Android 10 device whose bootloader is unlocked. I have downloaded its firmware, modified it and get the adb shell rooted in recovery. Following are the steps for it:


Download AIK
Extract recovery.img and modified ramdisk/default.prop as follows:


 ro.secure=0
 ro.adb.secure=0
 security.perf_harden=0
 ro.debuggable=1
 persist.sys.usb.config=adb,mtp



Replace split_img/recovery.img-zImage with permissive kernel(built from kernel sources)
Repack it and flash it on the device.
Reboot to recovery and run adb shell. It will be rooted.


I want to add simple chmod 666 /dev/diag command and I have mounted system with stock recovery mount system option and then tried to do following:


Write chmod command at the end of init.rc.
Tried creating new rc scripts under /system/etc/init/ folder. New rc script has just chmod command written in it.
Tried appending(e.g. echo "chmod 666 /dev/diag" >> /system/etc/init/cameraserver.rc) chmod command in other rc files in /system/etc/init/ folder.


All were not able to change the required permissions. init.rc changes lost after reboot. Other files/changes persist after reboot but doesn't change the permission of diag port.

OTOH, I was able to make a system app with changes in /system/app/ folder.

Is there anything else that I can try to run the chmod command after phone boots?
echo "chmod 666 /dev/diag" &gt;&gt; /system/etc/init/cameraserver.rc won't work. You need to provide an init trigger as well. For instance:

~# echo "on boot" &gt;/etc/init/dev_diag_chmod.rc
~# echo "    chmod 666 /dev/diag" &gt;&gt;/etc/init/dev_diag_chmod.rc
~# chown 0.0 /etc/init/dev_diag_chmod.rc
~# chmod 0644 /etc/init/dev_diag_chmod.rc
~# chcon u:object_r:system_file:s0 /etc/init/dev_diag_chmod.rc


But even simple approach is to edit the ueventd.rc file (which is read and executed by Android's device manager) provided by vendor (since /dev/diag is a hardware specific interface) which creates the device node. Replace the relevant statement inside that file to set whatever permission mode, owner and group you want. E.g. you can replace:

/dev/diag    0660    system    system


With:

/dev/diag    0666    system    system