On LineageOS 23.2 having `adb root` access, how to run a given ADB command on device start?
Mar 13, 9:37pm

To run an ADB command automatically when your LineageOS 23.2 device starts, you need to place your command in a script that runs at boot. Here’s how you can do it:


1. Create a Boot Script

You need to create a script that contains your ADB command. Since you have adb root access, you can place this script in a location that runs at boot, such as /data/local/userinit.d/ or /system/etc/init.d/ (if supported by your ROM).

Example Script:

bash
#!/system/bin/sh
# Wait for ADB to be ready
while ! getprop sys.boot_completed | grep -q 1; do
    sleep 1
done
# Your ADB command here
your_adb_command_here

Replace your_adb_command_here with the actual command you want to run.


2. Save the Script

Save the script to a file, for example /data/local/userinit.d/your_script.sh.
Make sure the script is executable:

bash
chmod 755 /data/local/userinit.d/your_script.sh

3. Ensure the Script Runs at Boot

  • If your ROM supports /system/etc/init.d/, you can also place the script there.
  • Some custom ROMs (like LineageOS) may require additional steps to enable init.d support. You can check if it’s enabled by looking for the presence of the init.d directory or by searching for related settings in your ROM’s configuration.

4. Alternative: Use Magisk (if rooted)

If your device is rooted and you have Magisk installed, you can use the Magisk Boot Scripts module or create a custom module to run your script at boot.


5. Verify the Script Runs

After setting up, reboot your device and check if the command runs as expected. You can verify by checking logcat:

bash
adb logcat | grep "your_script"

Important Notes:

  • ADB Root Access: Ensure adb root is enabled before the script runs. You may need to add adb root as the first command in your script if it requires root access.
  • Permissions: Ensure the script has the correct permissions (chmod 755).
  • Testing: Test the script manually before relying on it to run at boot.

Mar 13, 9:37pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.