How Magisk works
Magisk roots Android without writing to the system partition. It patches one boot image, takes over the first seconds of boot, and applies everything else in memory. This page follows that path stage by stage, with the exact files, triggers and paths from Magisk's source code.
Last updated 8 sourcesHow we check pages
"Systemless" in one sentence
Magisk patches only the partition that holds the boot ramdisk (boot, init_boot, vendor_boot since v30.3, or recovery). Everything else it changes, including root access, modules and properties, is applied in memory at each boot, so the /system and /vendor partitions themselves stay untouched. That is why removing Magisk or flashing the stock image returns the phone to stock.
- Image Magisk patchesThe one with the ramdisk
boot,init_boot,vendor_bootor recovery - First process
magiskinitRuns in place ofinit, then hands over - Root daemon
magiskdStarted at post-fs-data - Files on disk
/data/adbModules, database, binaries - Module filesBind mountsMagic mount; partitions stay untouched
- SELinuxStays EnforcingPolicy is patched, not disabled
The boot sequence at a glance
Magisk does its work at four points during boot. The first happens before Android's own init has done anything; the other three are triggers that Magisk adds to init.rc, so Android's init calls Magisk back at the right moments.
What runs when a Magisk-patched phone boots
- 1Bootloader and kernelLoad the patched ramdisk
- 2magiskinitPatches SELinux policy, injects
init.rcentries - 3Android initRuns normally, fires Magisk's triggers
- 4post-fs-data
magiskdstarts, Safe Mode check, modules mounted - 5Zygote and late_startZygisk loads,
service.shscripts run - 6boot-completeBootloop counter reset
| Stage | Started by | What Magisk does | Blocks boot? |
|---|---|---|---|
| Pre-init | Kernel runs /init, which is now magiskinit | Mounts what it needs, patches the SELinux policy, adds its init.rc entries, then runs the real init | Yes (briefly) |
| post-fs-data | on post-fs-data → magisk --post-fs-data | Starts magiskd, checks Safe Mode, runs post-fs-data scripts, loads system.prop, mounts modules, prepares Zygisk | Yes, up to 40 s |
| late_start service | on nonencrypted or vold.decrypt=trigger_restart_framework → magisk --service | Runs service.d and module service.sh scripts | No |
| boot-complete | on property:sys.boot_completed=1 → magisk --boot-complete | Resets the bootloop counter, sets up pre-init storage, finalizes Zygisk | No |
All three triggers run magisk from its tmpfs directory in the u:r:magisk:s0 SELinux context. You can read the exact lines in native/src/init/rootdir.rs; they are the same in v30.7 and v31.1. The stage names come from Android's own init language, where post-fs-data fires once /data is mounted.
Pre-init: magiskinit takes over
When you patch an image, the Magisk app (through magiskboot) replaces the ramdisk's init with magiskinit and keeps a backup of the original (we ran this on Google's boot image and published the result: what patching actually changes). At boot, magiskinit:
- Mounts what it needs early:
sysfs,procfs,devtmpfs, and the pre-init partition if the device has one. - Gets the system partitions mounted. On legacy system-as-root devices it switches root to
/systemitself. On two-stage init (2SI) devices, the layout used from Android 10 on, it lets the original first-stageinitmount the dynamic partitions, then takes control again as the second stage by bind-mounting itself over/system/bin/init. - Injects Magisk's services into
init.rc(the three triggers above) and applies anyoverlay.dfiles from the ramdisk. Custom kernel developers useoverlay.dto add.rcscripts and files; see Magisk's developer guide. - Patches the SELinux policy with Magisk's built-in rules plus every module's
sepolicy.rulekept in pre-init storage. How it intercepts the policy depends on the Android version (table below). - Restores and runs the original
init, so Android boots as it normally would.
| Android version | How the policy is intercepted |
|---|---|
| 10 and later (2SI) | LD_PRELOAD on init hooks security_load_policy, so the policy is patched in memory before it reaches the kernel |
| 8.0 to 9 (Treble, split policy) | Mounts selinuxfs early and replaces its load and enforce nodes; a FIFO pauses init until the patched policy is loaded |
| 7.0 to 7.1 | Pauses init with a FIFO right after it mounts selinuxfs, then uses the same node replacement |
| 6.0 (v30.7 and older only) | A variant of the 7.x method that blocked on checkreqprot. Removed in v31.1 along with Android 6.0 support. |
Pre-init storage. Module SELinux rules have to be readable before /data is decrypted, so Magisk copies them to a small writable partition it can mount at pre-init. The source picks from /persist (or /mnt/vendor/persist), /metadata, /klogdump (added in v30.7), /cache, or /data when it is unencrypted or uses file-based encryption without metadata encryption. It prefers ext4 over f2fs. magisk --preinit-device prints the device it chose.
Charger mode. When the phone boots only to show the off-mode charging screen, magiskinit does not load Magisk. v31.0 moved this check ahead of force_normal_boot, because some phones (Magisk's source names Motorola) set that flag while charging, which used to load Magisk and push the bootloop counter toward Safe Mode.
post-fs-data: the daemon starts and modules load
This is the stage that decides whether your modules load, so it is the one behind most module bootloops. Once /data is mounted and, on encrypted devices, vold is running, magiskd does the following, in this order (from bootstages.rs and module.rs):
- Removes saved root grants for apps that are no longer installed.
- Prepares
/data/adb(permissions700), createspost-fs-data.dandservice.dif missing, and copies BusyBox into the tmpfs directory. - Adds 1 to the bootloop counter and decides on Safe Mode (next section). In Safe Mode it disables every module and Zygisk, then stops here.
- Runs executable scripts in
/data/adb/post-fs-data.d. - Merges modules installed since the last boot from
modules_updateintomodules(a module that was disabled stays disabled after an update). - Deletes modules that contain a
removefile, running theiruninstall.shfirst, and skips those with adisablefile. With Zygisk off, Zygisk modules are skipped too; with Zygisk on, Riru modules are skipped. - Runs each enabled module's
post-fs-data.sh. - For each module: loads
system.propwith resetprop, then, unlessskip_mountexists, adds itssystemfolder to the mount tree. - Adds Magisk's own binaries (
magisk,magiskpolicy, and thesu,resetpropandsupolicylinks) and, with Zygisk on, the Zygisk loader library, then performs all the bind mounts.
The whole stage may hold up boot for at most 40 seconds, and post-fs-data scripts get at most 35 of those so Magisk still has time to mount modules. Magisk's developer guide warns that calling setprop here deadlocks boot; scripts must use resetprop -n instead (see the resetprop reference).
Safe Mode and the bootloop counter
Magisk counts boots that start post-fs-data and resets the count when sys.boot_completed=1. At post-fs-data it enters Safe Mode if any of these is true:
- the counter was already 2, meaning the previous two boots never reached boot-complete;
- Android itself is booting in safe mode (
persist.sys.safemodeorro.sys.safemodeis1); - Volume Down is held continuously for 3 seconds when Magisk checks.
Safe Mode creates a disable file in every module and turns Zygisk off, so the following boot is clean. Re-enable modules one at a time in the app. For the practical recovery steps, including magisk --remove-modules over ADB, see fixing a Magisk bootloop.
late_start service and boot-complete
late_start service. When Android starts its late_start services, Magisk runs scripts in /data/adb/service.d and every enabled module's service.sh. This stage does not block boot, so it is where Magisk's guide recommends most scripts go. It is skipped entirely if post-fs-data ended in Safe Mode. A script that needs the system fully booted can wait with resetprop -w sys.boot_completed 0.
boot-complete. When sys.boot_completed becomes 1, Magisk resets the bootloop counter to 0, mounts or links the writable pre-init directory so module installs can store sepolicy.rule files, and finalizes Zygisk. On headless system user (HSUM) devices, v31.1 sets the Superuser Multiuser mode to User-independent at post-fs-data and boot-complete.
All boot scripts run in Magisk's BusyBox ash with standalone mode on, so commands like ls and cp are BusyBox applets regardless of PATH. General scripts in the .d folders run only if they are executable (chmod +x); module scripts do not need that.
Module folders and magic mount
A module is a folder named after its ID in /data/adb/modules. Magisk decides what to do with it from the files inside:
| File or folder | Effect | When |
|---|---|---|
module.prop | Name, version and ID shown in the app | Read by the app |
system/ | Merged over the real /system; system/vendor, system/product and system/system_ext go to those partitions | post-fs-data |
system.prop | Properties in build.prop format, set with resetprop | post-fs-data |
sepolicy.rule | Extra SELinux rules in magiskpolicy syntax | Pre-init, next boot |
post-fs-data.sh / service.sh | Boot scripts | post-fs-data / late_start |
zygisk/<abi>.so | Zygisk libraries loaded into app processes | Zygote start |
action.sh | Shows an Action button on the module card | When you tap it |
uninstall.sh | Cleanup when the module is removed | Boot after removal |
disable, remove, skip_mount | Flags: skip the module, delete it, or load it without mounting system/ | post-fs-data |
Life of a module, from install to mounted
- InstallFlash zip in the appFiles go to
/data/adb/ modules_update/ <id> - RebootMergeMoved into
/data/adb/ modules/ <id> - CheckFlags
removedeletes it,disableskips it - Scriptpost-fs-data.shRuns before anything is mounted
- Applysystem.prop and mountsProps set,
system/bind-mounted - Laterservice.shRuns alongside the rest of boot
How magic mount works. Magisk never writes to /system. At post-fs-data it builds one virtual tree from every enabled module's system folder, splits off the parts that belong to /vendor, /product and /system_ext when those are separate partitions, and compares the tree with the real file system. A file that replaces an existing one is bind-mounted straight over it. A directory that gains new entries is rebuilt in a tmpfs workspace, with the original contents mirrored in, and the rebuilt directory is mounted over the real one. A .replace file swaps a whole directory instead of merging, and a 0:0 character device (or the installer's REMOVE list) hides a file. Disabling the module and rebooting removes all of it.
Where a module's files end up
Top: what apps and the system see. Bottom: what is stored on disk.
-
/system, /vendor, /product, /system_extThe merged view every process sees after post-fs-dataBind mounts
-
$MAGISKTMP/.magisk/workertmpfs workspace where Magisk rebuilds any directory that needs new entriesIn RAM
-
$MAGISKTMP/.magisk/modulesRead-only view of /data/adb/modules, used as the mount sourceIn RAM
-
/data/adb/modules/<id>/systemThe module's own files, on the data partitionOn disk
-
Real system partitionsNever written to; restoring the stock boot image undoes everythingUnchanged
Writing a module of your own? The module development guide covers module.prop, the installer zip and customize.sh. To browse existing modules, see the module directory.
Where su and the other tools come from
There is no su file on your system partition. On older devices where /sbin exists and is in PATH, Magisk's tmpfs directory is /sbin and the tools are simply there. Otherwise (most phones on Android 11 and later, where the directory is /debug_ramdisk) Magisk adds magisk, magiskpolicy, su, resetprop and supolicy to the magic mount tree. It picks a directory from PATH on /system, /vendor, /product or /system_ext: one that already has an su (which it overrides), otherwise the one with the fewest files, falling back to /system/bin. Run command -v su in adb shell to see where it landed. How root requests are then approved is covered on the MagiskSU page.
Where Magisk keeps its files
| Path | Contents |
|---|---|
/data/adb/magisk | Magisk's binaries, BusyBox and scripts, used for module installs, addon.d and the app |
/data/adb/modules | Installed modules |
/data/adb/modules_update | Modules installed or updated since the last boot, merged in on the next reboot |
/data/adb/magisk.db | Settings, root grants and the bootloop counter |
/data/adb/post-fs-data.d, /data/adb/service.d | General boot scripts (must be executable; modules should not add them) |
tmpfs directory (magisk --path) | /sbin where it exists, otherwise /debug_ramdisk. Holds the binaries and applet links, and under .magisk/: modules (read-only view of /data/adb/modules), config, preinit, worker (magic mount workspace), busybox, device (daemon socket, log pipe), rootdir and pts. The partition mirrors older releases kept here were removed in v28.0. |
Magisk's documentation explains the choice of /data/adb: it already exists on modern Android, is readable only by root (700), carries an SELinux label (adb_data_file) very few processes can access, and sits in device-encrypted storage, so it is available as soon as /data is mounted on file-based-encryption devices. The module folders are used through the tmpfs view because /data is mounted nosuid.
Changing read-only properties: resetprop
Normally only init can change system properties, and nobody can change ro.* properties after they are set. resetprop carries a copy of AOSP's property code patched to edit the property area directly. For ordinary properties it still goes through property_service by default, so on property: actions fire as they would with setprop. Changing an ro.* property, or passing -n, edits memory directly and triggers nothing. Module system.prop files are loaded this way, always with the direct method. Flags, examples and pitfalls are on the resetprop page.
SELinux
Magisk patches the stock SELinux policy rather than switching SELinux to permissive, so getenforce still reports Enforcing. It adds:
- a
magiskdomain (u:r:magisk:s0): unconstrained and permissive, used bymagiskdand every root shell; - a
magisk_filetype that every domain can access, used for Magisk's sockets, binaries and internal nodes; - a
magisk_log_filetype for the log pipe, which every domain can write to but only zygote and Magisk can read.
A fixed set of client domains (zygote, shell, platform_app, system_app, priv_app, untrusted_app, untrusted_app_all) may connect to Magisk's sockets, which carry su, magisk and Zygisk requests, and share the pseudo-terminals used by root shells. Whether a request is actually allowed is then decided by magiskd from your Superuser settings. Older documentation described a separate magisk_client domain that apps had to pass through; current Magisk no longer uses it. Modules add their own rules with sepolicy.rule, applied at pre-init; the syntax is on the magiskpolicy page.
Zygisk and the DenyList
Zygisk gets into zygote through Android's native bridge mechanism. At post-fs-data, magiskd sets ro.dalvik.vm.native.bridge to libzygisk.so (keeping any original value after it) and magic-mounts that library into /system/lib64, and into /system/lib on devices with 32-bit support. When zygote starts it loads the library, and Zygisk loads each enabled Zygisk module's zygisk/<abi>.so (handed over as in-memory copies) into the app processes zygote forks. Huawei's Maple compiler is switched off where present because it bypasses the native bridge. If zygote crashes more than three times in a row, Magisk restores the original property so Zygisk stops loading. One version difference: v30.7 also restored the property at boot-complete, while v31.0 and later keep it set so zygotes that start after boot (Magisk's source names Meta Quest) are injected too.
The DenyList undoes Magisk's mounts in the processes you choose. With Zygisk on, Zygisk does this as each app starts; with Zygisk off, magiskd watches the system log for process starts instead. It is not root hiding on its own. v31.0 added webview_zygote to the processes it unmounts. More on both: what Zygisk is and getting banking apps to work.
What changed in v31.0 and v31.1
The current stable release is v31.1 (October 25, 2026). v31.1 followed v30.7, which is the last release that supports Android 6.0. The boot stages, file locations and mounting described above work the same way in v30.7 and v31.1. The differences that matter internally:
- Android 7.0 minimum. v31.1 dropped Android 6.0, and with it the 6.0-specific SELinux workaround in
magiskinit. - No app hiding. The repackaged "stub" app is gone, and Magisk no longer reinstalls the app if it is missing.
- No root prompts.
magiskdno longer asks the app to show a dialog. Apps and the ADB shell must be granted root ahead of time in the Superuser tab; anything else is refused. See MagiskSU. - su passes arguments to the shell. Unknown options now go to the shell instead of causing an error, and
-g/-Ghandling was fixed. - Zygisk on Android 17 (v31.0), resetprop
--compact(v31.0), native ChromeOS signing in magiskboot (v31.1).
Internal changes worth knowing about
- v28.0Partition mirrors removed from the tmpfs directory; 2SI injection rewritten
- v30.0Module loading and magic mount rewritten in Rust
- v30.3Magisk can be installed into
vendor_boot - v30.7Android 16 QPR2 policy format;
klogdumpas pre-init storage; su keeps capabilities unless--drop-cap - v31.0Zygisk on Android 17; charger mode detected before
force_normal_boot;webview_zygoteadded to DenyList unmounts - v31.1 (stable)Android 7.0 minimum; app hiding and stub removed; no root prompts; headless system user (HSUM) support
For the full release history, see Magisk releases. The command-line side of all this is on the tools overview.
Glossary
| Term | Meaning |
|---|---|
| Bootloader unlock | Allowing the phone to boot software not signed by the manufacturer. Required before Magisk can be installed. On most phones it erases all data, and some phones cannot be unlocked at all. |
| Boot image (boot.img) | The partition image the bootloader loads first. On phones that launched before Android 13 it contains the kernel and the ramdisk, so it is the image Magisk patches. |
| init_boot.img | A separate partition introduced for phones launching with Android 13. It holds the generic ramdisk that used to be in boot.img, so on those phones it is the image Magisk patches. |
| Ramdisk | The small file system the kernel starts from. Magisk replaces its init with magiskinit. The Magisk app's "Ramdisk" value tells you whether your boot image contains one. |
| GKI (Generic Kernel Image) | Android's common kernel format since Android 12, where the boot image carries a generic kernel. Phones launching with Android 13 also split the generic ramdisk into init_boot. |
| A/B (seamless) updates | Phones with two copies (slots) of system partitions install updates to the inactive slot. Magisk's "Install to Inactive Slot" uses this to keep root through updates. |
| fastboot | The bootloader-mode protocol and command-line tool used to unlock most phones and flash patched images. |
| AP file and Download mode (Samsung) | Samsung firmware is split into AP, BL, CP and CSC files and flashed in Download mode. Magisk patches the AP file as a whole. |
| Knox warranty bit | A Samsung security flag that installing Magisk trips permanently. Knox-dependent features such as Samsung Wallet and Secure Folder stop working. |
| Systemless | Magisk's approach of changing nothing on the system partition itself. Modifications are applied at boot, so restoring the stock boot image removes them. |
| Magic mount | How Magisk applies module files: it bind-mounts each module's files over the real /system at boot instead of writing to the partition. |
| Magisk module | A folder in /data/adb/modules with files, scripts and properties that Magisk applies at boot. |
| Zygisk | A Magisk feature that runs module code inside every app process by loading into zygote, the process apps are started from. |
| DenyList | Magisk's list of apps and processes for which it reverts its modifications when Enforce DenyList is on. It is not a root-hiding system by itself. |
| MagiskSU | Magisk's su implementation. Apps request root through it, and you approve or deny each app in the Magisk app's Superuser screen. |
| Play Integrity verdict | Google's assessment of a device that apps can request. On Android 13 and later, DEVICE integrity needs hardware-backed proof of a locked bootloader. |
Sources
This page is written from the sources below. If anything here disagrees with them, the upstream source is correct.
- Magisk internal details (topjohnwu)
- Magisk developer guide: modules, boot scripts, overlay.d (topjohnwu)
- Magisk changelog (topjohnwu)
- Magisk tools reference (topjohnwu)
- Magisk source: boot stage handling, native/src/core/bootstages.rs (topjohnwu)
- Magisk source: module loading and magic mount, native/src/core/module.rs (topjohnwu)
- Magisk source: init.rc injection, native/src/init/rootdir.rs (topjohnwu)
- Android init language: triggers such as post-fs-data and late_start (AOSP)
Found a mistake or something out of date? Tell us and we will check it against the source and fix the page. Confirmed corrections are listed in the corrections log.
Report a problem with this page