How to Make a Magisk Module

Here is a template (9.6 KB) for a basic magisk module
Inside there are a few things to focus on

  1. /common/ and its contents
  2. /system/
  3. install.sh
  4. module.prop
    Most of these files have the following instructions in them

Common

In /common/ there are 2 files that will run scripts (post-fs-data.sh and service.sh) and 1 file that will set properties (system.prop)
For the scripts use MODDIR=${0%/*} to set the directory (in case magisk changes directories)
For system.prop simply put the property you want (for example, in /vendor/build.prop on the Cat there is a proprety ro.config.low_ram=true so in system.prop i added a line ro.config.low_ram=false)

System

If you want to place a file in any of the super partitions you place them in /system/. For directories other than system, you make it a sub-directory of system (e.g. /system/vendor/ or system/system_ext/), and magisk figures it out. For example, In my Android Auto module for the Cat I put 2 files in, /system/app/gappstub/gappstub.apk and /system/product/priv-app/AndroidAutoPrebuiltSub/AndroidAutoPrebuiltStub.apk).

Install.sh

In install.sh there are a few options

  1. Flags: If you want any of the files in /common/ to make changes you need to set its flag to true, all flags are already there and set to false by default (e.g. to allow system.prop to make changes set PROPFILE=true)
  2. Replace list: If you want to remove something or replace all the files in the directory you’re adding something to (instead of merging it with an existing directory) you add it to the replace list, it is already in the install.sh but it is empty by default. For example, if you want to remove youtube and youtube music it would look like this:
REPLACE="
/system/app/Youtube
/system/app/YTMusic
"
  1. Display when installing: toward the end of install.sh there is an option to display something while installing the module
print_modname() {
  ui_print "************************************"
  ui_print "  Module Name and Message   "
  ui_print "************************************"

}

replace the text with whatever you want. if you add lines make sure to add ui_print " yourtext " to the line

Module.prop

the module.prop should have this layout

id=your_custom_module_id
name=Your Custom Module Name
version=v1 or whatever version
versionCode=1 or whatever version code
author=You
description=A short description of your module

Making the Zip File

I suggest using 7-zip
select all the files (common, META-INF, system, etc) and right click on them, hover over 7-zip and select “add to archive” then under Archive Format select “zip”, under Compression Level select “0-store” and press ok

6 Likes

Did you every figure out how to permanently install a magisk module?

Meaning instead of making an init.rc script, use a post-fs-data or post-boot animation magisk script - that’s stored in /system - so it doesn’t get lost after a factory reset.

Basically, create a symlink that points to /system/and/magisk instead of the default /data etc.

1 Like

I wasted hours on GPT 4.o and Claude till I found this template (which also has the instructions in the install.sh). I’m not sure about modding the system directly with magisk, but you could probably make magisk run a script to push a script file somewhere