Last active
November 19, 2025 00:55
-
-
Save ayasa520/825654694dbfd206ecdd4383575208b4 to your computer and use it in GitHub Desktop.
安装 magisk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on post-fs | |
| mkdir /debug_ramdisk 0755 root root | |
| mount tmpfs tmpfs /debug_ramdisk mode=0755 | |
| on post-fs-data | |
| exec u:r:su:s0 root root -- /debug_ramdisk/magisk --stop | |
| exec u:r:su:s0 root root -- /system/bin/sh /data/adb/magisk_init.sh | |
| exec u:r:su:s0 root root -- /debug_ramdisk/magisk --post-fs-data | |
| on boot | |
| exec u:r:su:s0 root root -- /debug_ramdisk/magisk --service | |
| on property:sys.boot_completed=1 | |
| exec u:r:su:s0 root root -- /debug_ramdisk/magisk --boot-complete | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/system/bin/sh | |
| # Magisk 环境初始化脚本 | |
| # 设置环境变量 | |
| export PATH=/sbin:/system/bin:/system/xbin | |
| # 确定 MAGISKTMP(根据 Android 版本) | |
| if [ -d /debug_ramdisk ]; then | |
| export MAGISKTMP=/debug_ramdisk | |
| elif [ -d /sbin ]; then | |
| export MAGISKTMP=/sbin | |
| else | |
| echo "Error: Cannot determine MAGISKTMP location" | |
| exit 1 | |
| fi | |
| log() { | |
| echo "[Magisk Init] $1" | |
| echo "[$(date)] $1" >> /data/local/tmp/magisk_init.log | |
| } | |
| log "Starting Magisk initialization" | |
| log "MAGISKTMP=$MAGISKTMP" | |
| MAGISKBIN="/data/adb/magisk" | |
| if [ ! -f "$MAGISKBIN/magisk" ]; then | |
| log "Error: Magisk binary not found at $MAGISKBIN/magisk" | |
| exit 1 | |
| fi | |
| chmod 755 -R $MAGISKBIN | |
| log "Creating directory structure" | |
| mkdir -p $MAGISKTMP/.magisk/device | |
| mkdir -p $MAGISKTMP/.magisk/worker | |
| chmod 755 $MAGISKTMP/.magisk | |
| chmod 711 $MAGISKTMP/.magisk/device | |
| chmod 000 $MAGISKTMP/.magisk/worker | |
| mkdir -p /data/adb/modules | |
| mkdir -p /data/adb/post-fs-data.d | |
| mkdir -p /data/adb/service.d | |
| log "Copying Magisk binaries" | |
| for file in magisk magisk32 magiskpolicy busybox stub.apk; do | |
| if [ -f "$MAGISKBIN/$file" ]; then | |
| cp -af "$MAGISKBIN/$file" "$MAGISKTMP/$file" | |
| chmod 755 "$MAGISKTMP/$file" | |
| log "Copied $file" | |
| fi | |
| done | |
| log "Creating symbolic links" | |
| ln -sf ./magisk $MAGISKTMP/su | |
| ln -sf ./magisk $MAGISKTMP/resetprop | |
| ln -sf ./magiskpolicy $MAGISKTMP/supolicy | |
| log "Setting up worker directory" | |
| if ! mount | grep -q "$MAGISKTMP/.magisk/worker"; then | |
| mount -t tmpfs -o 'mode=0755' magisk $MAGISKTMP/.magisk/worker | |
| mount --make-private $MAGISKTMP/.magisk/worker | |
| fi | |
| if [ -f "$MAGISKTMP/busybox" ]; then | |
| log "Setting up BusyBox" | |
| mkdir -p $MAGISKTMP/.magisk/busybox | |
| $MAGISKTMP/busybox --install -s $MAGISKTMP/.magisk/busybox | |
| export PATH=$MAGISKTMP/.magisk/busybox:$PATH | |
| fi | |
| log "Running preinit device" | |
| MAKEDEV=1 $MAGISKTMP/magisk --preinit-device | |
| log "Applying SELinux policy" | |
| RULESCMD="" | |
| rule="$MAGISKTMP/.magisk/preinit/sepolicy.rule" | |
| [ -f "$rule" ] && RULESCMD="--apply $rule" | |
| if [ -d /sys/fs/selinux ]; then | |
| if [ -f /vendor/etc/selinux/precompiled_sepolicy ]; then | |
| $MAGISKTMP/magiskpolicy --load /vendor/etc/selinux/precompiled_sepolicy \ | |
| --live --magisk $RULESCMD 2>&1 | |
| log "Applied SELinux policy from vendor" | |
| elif [ -f /sepolicy ]; then | |
| $MAGISKTMP/magiskpolicy --load /sepolicy --live --magisk $RULESCMD 2>&1 | |
| log "Applied SELinux policy from rootfs" | |
| else | |
| $MAGISKTMP/magiskpolicy --live --magisk $RULESCMD 2>&1 | |
| log "Applied SELinux policy from kernel" | |
| fi | |
| fi | |
| log "Magisk initialization complete" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment