[Magisk] topjohnwu:
This thread is outdated and will never be updated

Please check the official Magisk documentation on Github!

Magisk Guides and Tricks

How Do Magic Mount Behave

Magic Mount by default merges the files in $MODPATH/system into the real /system. You can think as it dirty flashes the contents into /system.

Existing files will be replaced; new files will be added; will not remove any files

Directories under $MODPATH/system that contains a file named ".replace" will NOT merge into the system. It will directly replace the correspond directory in /system.

In the module template, you can list them in "config.sh", the scripts will create the ".replace" file automatically for you.

You can think as it wipes the existing folder, and then adds contents to that folder in /system.

The directory that contains ".replace" will replace the one in /system, all contents originally in the folder will be discarded

Adding items to system is relatively expensive, Magisk would need to do many under-the-hood tasks to achieve it (thus, called "Magic Mount")

Furthermore, the higher level the file is added, the more it effects the overall system

Only add new items if necessary! Think twice before adding items to /system root!

Replacing a whole folder is recommended if viable, it reduces the complicated process and speed up the booting time

Manipulate system props (build.prop)

Since the early days of XDA, people love "build.prop" mods. It can bring cool effects to our devices.

build.prop files are loaded early in the boot process, and once read-in, the values cannot be modified... in theory.

Magisk included a tool called "resetprop", it can modify any system props you want easily.

In the module template, you can set PROPFILE=true, then add your props into the file common/system.prop

Magisk by default reads the system.prop of each module and set the props.

Further resetprop options:

usage: /data/magisk/resetprop [-v] [-n] [--file propfile] [--delete name] [ name value ]
-v :
verbose output (Default: Disabled)
-n :
no event triggers when changing props (Default: Will trigger events)
--file propfile :
Read props from prop files (e.g. build.prop)
--delete name :
Remove a prop entry

Remove files / folders

It is complicated to actually remove a file (possible, not worth the effort). Replacing it with a dummy file should be good enough

Add an empty file with the same name and path into your module (easy way), or add this code to the updater-script to create it at flash time

# Example: you want to remove /system/media/audio/alarms/Argon.ogg
# Note: mktouch is a function defined in my updater-script, it is not a standard command!
mktouch $MODDIR/system/media/audio/alarms/Argon.ogg

It is complicated to actually remove a folder (possible, not worth the effort). Replacing it with an empty folder should be good enough

Add the folder to the replace list in "config.sh" in the module template, it will replace the folder with an empty one

Cache mounts

Some files requires to be mounted much earlier in the boot process, currently known are bootanimation, and some libs (most users won't change them).

You can place your files into the corresponding location under /cache/magisk_mount, Magisk will automagiskally manage selinux contexts, permissions and the mounting for you. For example, you want to replace /system/media/bootanimation.zip, copy your new boot animation zip to /cache/magisk_mount/system/media/bootanimation.zip, Magisk will mount your files in the next reboot​

More to come ...