/magisk-autoboot

a Magisk module to enable automatic booting/for turning on of your Android device when it's connected to a charger or USB.

Primary LanguageShellOtherNOASSERTION

anasfanani - magisk-autoboot Github All Releases GitHub release issues - magisk-autoboot

Magisk Autoboot

This repository contains a Magisk module designed to enable automatic booting of your Android device when it's connected to a charger or USB.

Requirements

Before you can use this Magisk module, you need to ensure that:

  1. Android device rooted with Magisk.
  2. Basic knowledge for module management.

Important :

  • Backup of your boot.img to restore in case of issues.
  • This module not work on devices where Magisk is installed via the recovery partition. It is designed to work on devices where Magisk is installed via the boot partition.

Installation

  1. Download the latest zip file from the Releases page.
  2. Install the downloaded zip file using Magisk App/TWRP.
  3. Power off your phone.

After installation, your Android will boot automatically on cable connected.

Usage

This module adds autoboot.init.rc and autoboot.sh to the boot image. The patching process can be viewed in scripts/boot_patch.sh. The scripts folder is obtained from the installed Magisk on Android in the /data/adb/magisk folder. Only some necessary code is imported and then modified for patching boot.img.

In the autoboot.sh file, MIN_CAPACITY=5 is set as the minimum battery percentage threshold before Android boots automatically. If your battery percentage is below 5, the device will wait until it reaches this threshold before booting automatically. If you need to adjust this threshold, change the MIN_CAPACITY value in the autoboot.sh file and reflash this module.

In case of any errors, your current boot image is backed up under /data/adb/modules/magisk-autoboot/AutoBoot-Backup. If something happens, you can safely restore them.

Troubleshooting

If you encounter any issues while using this module, follow these steps:

  1. Check if your current boot image is backed up under /data/adb/modules/magisk-autoboot/AutoBoot-Backup. If it is, try restoring it.

  2. Confirm successful installation by checking the presence of the autoboot.sh file in the directory outputted by the magisk --path command, usually /debug_ramdisk or /sbin.

If you continue to experience issues, please raise an issue in the repository with a detailed description of the problem, steps to reproduce it, and any error messages you are seeing.

Manual Patching

If you're an advanced user and want to patch your boot image manually without implementing minimum battery percentage threshold, follow these steps:

Preparation

Prepare your boot image by following these steps:

Method 1: Using TWRP Terminal

On TWRP, go to Advanced > Terminal and run the following commands:

  1. Create base folder for placing boot image files. For example, mkdir /sdcard/autboot.
  2. Run dd if=/dev/block/bootdevice/by-name/boot of=/sdcard/autoboot/boot.img for dump boot.img.

Method 2: Using ADB Shell with TWRP Recovery

Boot into TWRP recovery and connect your device to your computer, connect to ADB shell and run the following commands:

mkdir /sdcard/autoboot
dd if=/dev/block/bootdevice/by-name/boot of=/sdcard/autoboot/boot.img

Method 3: Using TWRP Backup

On TWRP, go to Backup and select Boot. Then, swipe to backup. Your boot image will be backed up to /sdcard/TWRP/BACKUPS/<device_serial_number>/<name_of_backup>/boot.emmc.win. Just copy and place it in a folder /sdcard/autoboot/ on your device, then rename it to boot.img.

Patching

Create a file named autoboot.init.rc in the same folder as boot.img with the following contents:

on charger
 setprop ro.bootmode "normal"
 setprop sys.powerctl "reboot"

Execute the following commands:

/data/adb/magisk/magiskboot unpack boot.img
/data/adb/magisk/magiskboot cpio ramdisk.cpio \
"mkdir 0700 overlay.d" \
"add 0700 overlay.d/autoboot.init.rc autoboot.init.rc"
/data/adb/magisk/magiskboot repack boot.img boot_patched_autoboot.img
/data/adb/magisk/magiskboot cleanup

Flashing

You can flash the patched boot image using the following methods:

Method 1: Using TWRP Terminal

On TWRP, go to Advanced > Terminal and run the following commands:

dd if=/sdcard/autoboot/boot_patched_autoboot.img of=/dev/block/bootdevice/by-name/boot

Method 2: Using ADB Shell with TWRP Recovery

Boot into TWRP recovery and connect your device to your computer, connect to ADB shell and run the following commands:

dd if=/sdcard/autoboot/boot_patched_autoboot.img of=/dev/block/bootdevice/by-name/boot

Method 3: Using TWRP Install

On TWRP, go to Install and select the patched boot image. Then, swipe to flash.

Power Off

Power off your device and connect it to a charger or USB. Your device should boot automatically.

Disclaimer

This module is provided "as is" without warranty of any kind, either express or implied, including without limitation any warranties of merchantability, fitness for a particular purpose, and non-infringement. The entire risk as to the quality and performance of the module is with you. Should the module prove defective, you assume the cost of all necessary servicing, repair, or correction.

Tested Devices

The method has been successfully tested on the following devices:

  • Redmi 4X running Android 10 ( With implement minimum battery percentage threshold )
  • Samsung J3 (2016) running Android 7.1.2 ( Without implement minimum battery percentage threshold )
  • Redmi Note 11 (spesn) Android 13

Links

Here are some useful links for further reading:

Credits

License

This project is licensed under the MIT License.