当前位置:   article > 正文

安卓玩机----解锁system分区 可读写系统分区 magisk面具模块_新版magisk解锁system

新版magisk解锁system

玩机教程----安卓机型解锁system分区 任意修改删除系统文件

system分区可读写

参考上个博文可以了解到解锁system分区的有关常识。但目前很多机型都在安卓12  13  基础上。其实最简单的方法就在于刷写一个解锁system分区的第三方补丁包。在面具更新不能解锁系统分区的前提下。我们也可以通过刷写一个解锁模块来达到解锁分区的目的。

官方资源下载地址在博文最后。

测试机型与信息

机型;小米11

芯片:骁龙888

安卓版本:安卓13

面具模块:Magisk Overlayfs

系统版本:miui14

操作步骤为:

解锁bl后有面具root权限。这个可以参考自己机型的解锁bl与root方法操作

然后在面具里刷入此模块。

重启后,查看模块运行开启正常。此时就可以任意系统分区读写。使用re管理器可以直观查看效果

操作效果

目前就可以任意删减系统分区文件。

部分源代码如下:

  1. SKIPUNZIP=1
  2. if [ "$BOOTMODE" ] && [ "$KSU" ]; then
  3. ui_print "- Installing from KernelSU app"
  4. ui_print "- KernelSU version: $KSU_KERNEL_VER_CODE (kernel) + $KSU_VER_CODE (ksud)"
  5. ui_print "- Please note that KernelSU modules mount will make"
  6. ui_print " your system partitions unable to mount as rw"
  7. ui_print "- If you are using KernelSU, "
  8. ui_print " please unmount all ksu overlayfs"
  9. ui_print " when you want to modify system partitions"
  10. elif [ "$BOOTMODE" ] && [ "$MAGISK_VER_CODE" ]; then
  11. ui_print "- Installing from Magisk app"
  12. else
  13. ui_print "*********************************************************"
  14. ui_print "! Install from recovery is not supported"
  15. ui_print "! Please install from KernelSU or Magisk app"
  16. abort "*********************************************************"
  17. fi
  18. loop_setup() {
  19. unset LOOPDEV
  20. local LOOP
  21. local MINORX=1
  22. [ -e /dev/block/loop1 ] && MINORX=$(stat -Lc '%T' /dev/block/loop1)
  23. local NUM=0
  24. while [ $NUM -lt 1024 ]; do
  25. LOOP=/dev/block/loop$NUM
  26. [ -e $LOOP ] || mknod $LOOP b 7 $((NUM * MINORX))
  27. if losetup $LOOP "$1" 2>/dev/null; then
  28. LOOPDEV=$LOOP
  29. break
  30. fi
  31. NUM=$((NUM + 1))
  32. done
  33. }
  34. randdir="$TMPDIR/.$(head -c21 /dev/urandom | base64)"
  35. mkdir -p "$randdir"
  36. ABI="$(getprop ro.product.cpu.abi)"
  37. # Fix ABI detection
  38. if [ "$ABI" == "armeabi-v7a" ]; then
  39. ABI32=armeabi-v7a
  40. elif [ "$ABI" == "arm64" ]; then
  41. ABI32=armeabi-v7a
  42. elif [ "$ABI" == "x86" ]; then
  43. ABI32=x86
  44. elif [ "$ABI" == "x64" ] || [ "$ABI" == "x86_64" ]; then
  45. ABI=x86_64
  46. ABI32=x86
  47. fi
  48. unzip -oj "$ZIPFILE" "libs/$ABI/overlayfs_system" -d "$TMPDIR" 1>&2
  49. chmod 777 "$TMPDIR/overlayfs_system"
  50. if ! $TMPDIR/overlayfs_system --test; then
  51. ui_print "! Kernel doesn't support overlayfs, are you sure?"
  52. abort
  53. fi
  54. ui_print "- Extract files"
  55. unzip -oj "$ZIPFILE" post-fs-data.sh \
  56. service.sh \
  57. util_functions.sh \
  58. mode.sh \
  59. mount.sh \
  60. uninstall.sh \
  61. module.prop \
  62. "libs/$ABI/overlayfs_system" \
  63. -d "$MODPATH"
  64. unzip -oj "$ZIPFILE" util_functions.sh -d "/data/adb/modules/${MODPATH##*/}"
  65. ui_print "- Setup module"
  66. chmod 777 "$MODPATH/overlayfs_system"
  67. resize_img() {
  68. e2fsck -pf "$1" || return 1
  69. if [ "$2" ]; then
  70. resize2fs "$1" "$2" || return 1
  71. else
  72. resize2fs -M "$1" || return 1
  73. fi
  74. return 0
  75. }
  76. test_mount_image() {
  77. loop_setup /data/adb/overlay
  78. [ -z "$LOOPDEV" ] && return 1
  79. result_mnt=1
  80. mount -t ext4 -o rw "$LOOPDEV" "$randdir" && \
  81. "$MODPATH/overlayfs_system" --test --check-ext4 "$randdir" && result_mnt=0
  82. # ensure that uppderdir does not override my binary
  83. rm -rf "$randdir/upper/system/bin/overlayfs_system" \
  84. "$randdir/upper/system/bin/magic_remount_rw" \
  85. "$randdir/upper/system/bin/magic_remount_ro"
  86. umount -l "$randdir"
  87. return $result_mnt
  88. }
  89. create_ext4_image() {
  90. dd if=/dev/zero of="$1" bs=1024 count=100
  91. /system/bin/mkfs.ext4 "$1" && return 0
  92. return 1
  93. }
  94. if [ ! -f "/data/adb/overlay" ] || ! test_mount_image; then
  95. rm -rf "/data/adb/overlay"
  96. ui_print "- Setup 2GB ext4 image at /data/adb/overlay"
  97. ui_print " Please wait..."
  98. if ! create_ext4_image "/data/adb/overlay" || ! resize_img "/data/adb/overlay" 2000M || ! test_mount_image; then
  99. rm -rf /data/adb/overlay
  100. abort "! Setup ext4 image failed, abort"
  101. fi
  102. fi
  103. mkdir -p "$MODPATH/system/bin"
  104. chcon -R u:object_r:system_file:s0 "$MODPATH/system"
  105. chmod -R 755 "$MODPATH/system"
  106. ln "$MODPATH/overlayfs_system" "$MODPATH/system/bin"
  107. ln -s "./overlayfs_system" "$MODPATH/system/bin/magic_remount_rw"
  108. ln -s "./overlayfs_system" "$MODPATH/system/bin/magic_remount_ro"
  109. . "$MODPATH/util_functions.sh"
  110. support_overlayfs && rm -rf "$MODPATH/system"
  111. ui_print

MODDIR="${0%/*}"

set -o standalone

export MAGISKTMP="$(magisk --path)"

chmod 777 "$MODDIR/overlayfs_system"

OVERLAYDIR="/data/adb/overlay"
OVERLAYMNT="/dev/mount_overlayfs"
MODULEMNT="/dev/mount_loop"


mv -fT /cache/overlayfs.log /cache/overlayfs.log.bak
rm -rf /cache/overlayfs.log
echo "--- Start debugging log ---" >/cache/overlayfs.log
echo "init mount namespace: $(readlink /proc/1/ns/mnt)" >>/cache/overlayfs.log
echo "current mount namespace: $(readlink /proc/self/ns/mnt)" >>/cache/overlayfs.log

mkdir -p "$OVERLAYMNT"
mkdir -p "$OVERLAYDIR"
mkdir -p "$MODULEMNT"

mount -t tmpfs tmpfs "$MODULEMNT"

loop_setup() {
  unset LOOPDEV
  local LOOP
  local MINORX=1
  [ -e /dev/block/loop1 ] && MINORX=$(stat -Lc '%T' /dev/block/loop1)
  local NUM=0
  while [ $NUM -lt 2048 ]; do
    LOOP=/dev/block/loop$NUM
    [ -e $LOOP ] || mknod $LOOP b 7 $((NUM * MINORX))
    if losetup $LOOP "$1" 2>/dev/null; then
      LOOPDEV=$LOOP
      break
    fi
    NUM=$((NUM + 1))
  done
}

if [ -f "$OVERLAYDIR" ]; then
    loop_setup /data/adb/overlay
    if [ ! -z "$LOOPDEV" ]; then
        mount -o rw -t ext4 "$LOOPDEV" "$OVERLAYMNT"
        ln "$LOOPDEV" /dev/block/overlayfs_loop
    fi
fi

if ! "$MODDIR/overlayfs_system" --test --check-ext4 "$OVERLAYMNT"; then
    echo "unable to mount writeable dir" >>/cache/overlayfs.log
    exit
fi

num=0

for i in /data/adb/modules/*; do
    [ ! -e "$i" ] && break;
    module_name="$(basename "$i")"
    if [ ! -e "$i/disable" ] && [ ! -e "$i/remove" ]; then
        if [ -f "$i/overlay.img" ]; then
            loop_setup "$i/overlay.img"
            if [ ! -z "$LOOPDEV" ]; then
                echo "mount overlayfs for module: $module_name" >>/cache/overlayfs.log
                mkdir -p "$MODULEMNT/$num"
                mount -o rw -t ext4 "$LOOPDEV" "$MODULEMNT/$num"
            fi
            num="$((num+1))"
        fi
        if [ "$KSU" == "true" ]; then
            mkdir -p "$MODULEMNT/$num"
            mount --bind "$i" "$MODULEMNT/$num"
            num="$((num+1))"
        fi
    fi
done

OVERLAYLIST=""

for i in "$MODULEMNT"/*; do
    [ ! -e "$i" ] && break;
    if [ -d "$i" ] && [ ! -L "$i" ] && "$MODDIR/overlayfs_system" --test --check-ext4 "$i"; then
        OVERLAYLIST="$i:$OVERLAYLIST"
    fi
done

mkdir -p "$OVERLAYMNT/upper"
rm -rf "$OVERLAYMNT/worker"
mkdir -p "$OVERLAYMNT/worker"

if [ ! -z "$OVERLAYLIST" ]; then
    export OVERLAYLIST="${OVERLAYLIST::-1}"
    echo "mount overlayfs list: [$OVERLAYLIST]" >>/cache/overlayfs.log
fi

# overlay_system <writeable-dir>
. "$MODDIR/mode.sh"
"$MODDIR/overlayfs_system" "$OVERLAYMNT" | tee -a /cache/overlayfs.log

if [ ! -z "$MAGISKTMP" ]; then
    mkdir -p "$MAGISKTMP/overlayfs_mnt"
    mount --bind "$OVERLAYMNT" "$MAGISKTMP/overlayfs_mnt"
fi


umount -l "$OVERLAYMNT"
rmdir "$OVERLAYMNT"
umount -l "$MODULEMNT"
rmdir "$MODULEMNT"

rm -rf /dev/.overlayfs_service_unblock
echo "--- Mountinfo (post-fs-data) ---" >>/cache/overlayfs.log
cat /proc/mounts >>/cache/overlayfs.log
(
    # block until /dev/.overlayfs_service_unblock
    while [ ! -e "/dev/.overlayfs_service_unblock" ]; do
        sleep 1
    done
    rm -rf /dev/.overlayfs_service_unblock

    echo "--- Mountinfo (late_start) ---" >>/cache/overlayfs.log
    cat /proc/mounts >>/cache/overlayfs.log
) &

  1. resize_img() {
  2. e2fsck -pf "$1" || return 1
  3. if [ "$2" ]; then
  4. resize2fs "$1" "$2" || return 1
  5. else
  6. resize2fs -M "$1" || return 1
  7. fi
  8. return 0
  9. }
  10. loop_setup() {
  11. unset LOOPDEV
  12. local LOOP
  13. local MINORX=1
  14. [ -e /dev/block/loop1 ] && MINORX=$(stat -Lc '%T' /dev/block/loop1)
  15. local NUM=0
  16. while [ $NUM -lt 2048 ]; do
  17. LOOP=/dev/block/loop$NUM
  18. [ -e $LOOP ] || mknod $LOOP b 7 $((NUM * MINORX))
  19. if losetup $LOOP "$1" 2>/dev/null; then
  20. LOOPDEV=$LOOP
  21. break
  22. fi
  23. NUM=$((NUM + 1))
  24. done
  25. }
  26. sizeof(){
  27. EXTRA="$2"
  28. [ -z "$EXTRA" ] && EXTRA=0
  29. [ "$EXTRA" -gt 0 ] || EXTRA=0
  30. size="$(du -s "$1" | awk '{ print $1 }')"
  31. # append more 20Mb
  32. size="$((size + EXTRA))"
  33. echo -n "$((size + 20000))"
  34. }
  35. handle() {
  36. if [ ! -L "/$1" ] && [ -d "/$1" ] && [ -d "$MODPATH/system/$1" ]; then
  37. rm -rf "$MODPATH/overlay/$1"
  38. mv -f "$MODPATH/overlay/system/$1" "$MODPATH/overlay"
  39. ln -s "../$1" "$MODPATH/overlay/system/$1"
  40. fi
  41. }
  42. create_ext4_image() {
  43. dd if=/dev/zero of="$1" bs=1024 count=100
  44. /system/bin/mkfs.ext4 "$1" && return 0
  45. return 1
  46. }
  47. support_overlayfs() {
  48. #OVERLAY_IMAGE_EXTRA - number of kb need to be added to overlay.img
  49. #OVERLAY_IMAGE_SHRINK - shrink overlay.img or not?
  50. if [ -d "$MODPATH/system" ]; then
  51. OVERLAY_IMAGE_SIZE="$(sizeof "$MODPATH/system" "$OVERLAY_IMAGE_EXTRA")"
  52. rm -rf "$MODPATH/overlay.img"
  53. create_ext4_image "$MODPATH/overlay.img"
  54. resize_img "$MODPATH/overlay.img" "${OVERLAY_IMAGE_SIZE}M" || { ui_print "! Setup failed"; return 1; }
  55. ui_print "- Created overlay image with size: $(du -shH "$MODPATH/overlay.img" | awk '{ print $1 }')"
  56. loop_setup "$MODPATH/overlay.img"
  57. if [ ! -z "$LOOPDEV" ]; then
  58. rm -rf "$MODPATH/overlay"
  59. mkdir "$MODPATH/overlay"
  60. mount -t ext4 -o rw "$LOOPDEV" "$MODPATH/overlay"
  61. chcon u:object_r:system_file:s0 "$MODPATH/overlay"
  62. cp -afT "$MODPATH/system" "$MODPATH/overlay/system"
  63. # fix context
  64. ( cd "$MODPATH" || exit
  65. find "system" | while read line; do
  66. chcon "$(ls -Zd "$line" | awk '{ print $1 }')" "$MODPATH/overlay/$line"
  67. if [ -e "$line/.replace" ]; then
  68. setfattr -n trusted.overlay.opaque -v y "$MODPATH/overlay/$line"
  69. fi
  70. done
  71. )
  72. # handle partition
  73. handle vendor
  74. handle product
  75. handle system_ext
  76. umount -l "$MODPATH/overlay"
  77. if [ "$OVERLAY_IMAGE_SHRINK" == "true" ] || [ -z "$OVERLAY_IMAGE_SHRINK" ]; then
  78. ui_print "- Shrink overlay image"
  79. resize_img "$MODPATH/overlay.img"
  80. ui_print "- Overlay image new size: $(du -shH "$MODPATH/overlay.img" | awk '{ print $1 }')"
  81. fi
  82. rm -rf "$MODPATH/overlay"
  83. return 0
  84. fi
  85. fi
  86. return 1
  87. }

 这个是一个开源的解锁系统分区资源。官方下载链接:官方开源地址

整体操作步骤还是比较简单。适合任意阶段的玩友使用。

关注我。了解一些玩机常识和基本的故障解决。

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/429932
推荐阅读
相关标签
  

闽ICP备14008679号