Skip to content

Commit

Permalink
website: Add docs for REPLACE variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Mar 27, 2023
1 parent e5617e2 commit c4c597d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
8 changes: 7 additions & 1 deletion userspace/ksud/src/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ mark_remove() {
chmod 644 $1
}

mark_replace() {
mkdir -p ${1%/*} 2>/dev/null
setfattr -n trusted.overlay.opaque -v y $1
chmod 644 $1
}

request_size_check() {
reqSizeM=`du -ms "$1" | cut -f1`
}
Expand Down Expand Up @@ -390,7 +396,7 @@ install_module() {
# Handle replace folders
for TARGET in $REPLACE; do
ui_print "- Replace target: $TARGET"
mktouch $MODPATH$TARGET/.replace
mark_replace $MODPATH$TARGET
done

# Handle remove files
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guide/difference-with-magisk.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Here are some differences:
- KernelSU modules do not have built-in support for Zygisk (but you can use Zygisk modules through [ZygiskOnKernelSU](https://github.com/Dr-TSNG/ZygiskOnKernelSU).
- The method for replacing or deleting files in KernelSU modules is completely different from Magisk. KernelSU does not support the `.replace` method. Instead, you need to create a same-named file with `mknod filename c 0 0` to delete the corresponding file.
- The directories for BusyBox are different. The built-in BusyBox in KernelSU is located in `/data/adb/ksu/bin/busybox`, while in Magisk it is in `/data/adb/magisk/busybox`. **Note that this is an internal behavior of KernelSU and may change in the future!**
- KernelSU does not support `.replace` files and `REPLACE` variable; however, KernelSU supports the `REMOVE` variable and `mknod <TARGET> c 0 0` command to remove files and folders.
- KernelSU does not support `.replace` files; however, KernelSU supports the `REMOVE` and `REPLACE` variable to remove or replace files and folders.
11 changes: 11 additions & 0 deletions website/docs/guide/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ REMOVE="

The above list will execute `mknod $MODPATH/system/app/YouTuBe c 0 0` and `mknod $MODPATH/system/app/Bloatware c 0 0`; and `/system/app/YouTube` and `/system/app/Bloatware` will be removed after the module takes effect.

If you want to replace a directory in the system, you need to create a directory with the same path in your module directory, and then set the attribute `setfattr -n trusted.overlay.opaque -v y <TARGET>` for this directory. This way, the overlayfs system will automatically replace the corresponding directory in the system (without changing the /system partition).

You can declare a variable named `REPLACE` in your `customize.sh` file, which includes a list of directories to be replaced, and KernelSU will automatically perform the corresponding operations in your module directory. For example:

REPLACE="
/system/app/YouTube
/system/app/Bloatware
"

This list will automatically create the directories `$MODPATH/system/app/YouTube` and `$MODPATH/system/app/Bloatware`, and then execute `setfattr -n trusted.overlay.opaque -v y $MODPATH/system/app/YouTube` and `setfattr -n trusted.overlay.opaque -v y $MODPATH/system/app/Bloatware`. After the module takes effect, `/system/app/YouTube` and `/system/app/Bloatware` will be replaced with empty directories.

::: tip difference with Magisk

KernelSU's systemless mechanism is implemented through the kernel's overlayfs, while Magisk currently uses magic mount (bind mount). The two implementation methods have significant differences, but the ultimate goal is the same: to modify /system files without physically modifying the /system partition.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh_CN/guide/difference-with-magisk.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
2. KernelSU 的模块没有内置的 Zygisk 支持(但你可以通过 [ZygiskOnKernelSU](https://github.com/Dr-TSNG/ZygiskOnKernelSU) 来使用 Zygisk 模块)。
3. KernelSU 模块替换或者删除文件与 Magisk 完全不同。KernelSU 不支持 `.replace` 方式,相反,你需要通过 `mknod filename c 0 0` 创建同名文件夹来删除对应文件。
4. BusyBox 的目录不同;KernelSU 内置的 BusyBox 在 `/data/adb/ksu/bin/busybox` 而 Magisk 在 `/data/adb/magisk/busybox`**注意此为 KernelSU 内部行为,未来可能会更改!**
5. KernelSU 不支持 `.replace` 文件和 `REPLACE` 变量;但 KernelSU 支持 `REMOVE` 变量和 `mknod <TARGET> c 0 0`
5. KernelSU 不支持 `.replace` 文件;但 KernelSU 支持 `REPLACE``REMOVE` 变量
13 changes: 13 additions & 0 deletions website/docs/zh_CN/guide/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ REMOVE="

上面的这个列表将会执行: `mknod $MODPATH/system/app/YouTuBe c 0 0``mknod $MODPATH/system/app/Bloatware c 0 0`;并且 `/system/app/YouTube``/system/app/Bloatware` 将会在模块生效后被删除。

如果你想替换掉系统的某个目录,你需要在模块目录创建一个相同路径的目录,然后为此目录设置此属性:`setfattr -n trusted.overlay.opaque -v y <TARGET>`;这样 overlayfs 系统会自动将系统内相应目录替换(`/system` 分区并没有被更改)。

你可以在 `customize.sh` 中声明一个名为 `REPLACE` 并且包含一系列目录的变量来执行替换操作,KernelSU 会自动为你在模块对应目录执行相关操作。例如:

```sh
REPLACE="
/system/app/YouTube
/system/app/Bloatware
"
```

上面这个列表将会:自动创建目录 `$MODPATH/system/app/YouTube``$MODPATH//system/app/Bloatware`,然后执行 `setfattr -n trusted.overlay.opaque -v y $$MODPATH/system/app/YouTube``setfattr -n trusted.overlay.opaque -v y $$MODPATH/system/app/Bloatware`;并且 `/system/app/YouTube``/system/app/Bloatware` 将会在模块生效后替换为空目录。

::: tip 与 Magisk 的差异

KernelSU 的 systemless 机制是通过内核的 overlayfs 实现的,而 Magisk 当前则是通过 magic mount (bind mount),二者实现方式有着巨大的差异,但最终的目标实际上是一致的:不修改物理的 `/system` 分区但实现修改 `/system` 文件。
Expand Down

1 comment on commit c4c597d

@wajo55
Copy link

@wajo55 wajo55 commented on c4c597d Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How its is work in redmi note 8 pro

Please sign in to comment.