Internals

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.

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

  1. 1Bootloader and kernelLoad the patched ramdisk
  2. 2magiskinitPatches SELinux policy, injects init.rc entries
  3. 3Android initRuns normally, fires Magisk's triggers
  4. 4post-fs-datamagiskd starts, Safe Mode check, modules mounted
  5. 5Zygote and late_startZygisk loads, service.sh scripts run
  6. 6boot-completeBootloop counter reset
Simplified from Magisk's internal details documentation and its source code (native/src/init and native/src/core/bootstages.rs) at tag v31.1, checked 26 October 2026. The stages are the same in v30.7.
StageStarted byWhat Magisk doesBlocks boot?
Pre-initKernel runs /init, which is now magiskinitMounts what it needs, patches the SELinux policy, adds its init.rc entries, then runs the real initYes (briefly)
post-fs-dataon post-fs-data → magisk --post-fs-dataStarts magiskd, checks Safe Mode, runs post-fs-data scripts, loads system.prop, mounts modules, prepares ZygiskYes, up to 40 s
late_start serviceon nonencrypted or vold.decrypt=trigger_restart_framework → magisk --serviceRuns service.d and module service.sh scriptsNo
boot-completeon property:sys.boot_completed=1 → magisk --boot-completeResets the bootloop counter, sets up pre-init storage, finalizes ZygiskNo

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:

  1. Mounts what it needs early: sysfs, procfs, devtmpfs, and the pre-init partition if the device has one.
  2. Gets the system partitions mounted. On legacy system-as-root devices it switches root to /system itself. On two-stage init (2SI) devices, the layout used from Android 10 on, it lets the original first-stage init mount the dynamic partitions, then takes control again as the second stage by bind-mounting itself over /system/bin/init.
  3. Injects Magisk's services into init.rc (the three triggers above) and applies any overlay.d files from the ramdisk. Custom kernel developers use overlay.d to add .rc scripts and files; see Magisk's developer guide.
  4. Patches the SELinux policy with Magisk's built-in rules plus every module's sepolicy.rule kept in pre-init storage. How it intercepts the policy depends on the Android version (table below).
  5. Restores and runs the original init, so Android boots as it normally would.
Android versionHow 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.1Pauses 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):

  1. Removes saved root grants for apps that are no longer installed.
  2. Prepares /data/adb (permissions 700), creates post-fs-data.d and service.d if missing, and copies BusyBox into the tmpfs directory.
  3. 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.
  4. Runs executable scripts in /data/adb/post-fs-data.d.
  5. Merges modules installed since the last boot from modules_update into modules (a module that was disabled stays disabled after an update).
  6. Deletes modules that contain a remove file, running their uninstall.sh first, and skips those with a disable file. With Zygisk off, Zygisk modules are skipped too; with Zygisk on, Riru modules are skipped.
  7. Runs each enabled module's post-fs-data.sh.
  8. For each module: loads system.prop with resetprop, then, unless skip_mount exists, adds its system folder to the mount tree.
  9. Adds Magisk's own binaries (magisk, magiskpolicy, and the su, resetprop and supolicy links) 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.safemode or ro.sys.safemode is 1);
  • 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 folderEffectWhen
module.propName, version and ID shown in the appRead by the app
system/Merged over the real /system; system/vendor, system/product and system/system_ext go to those partitionspost-fs-data
system.propProperties in build.prop format, set with resetproppost-fs-data
sepolicy.ruleExtra SELinux rules in magiskpolicy syntaxPre-init, next boot
post-fs-data.sh / service.shBoot scriptspost-fs-data / late_start
zygisk/<abi>.soZygisk libraries loaded into app processesZygote start
action.shShows an Action button on the module cardWhen you tap it
uninstall.shCleanup when the module is removedBoot after removal
disable, remove, skip_mountFlags: skip the module, delete it, or load it without mounting system/post-fs-data

Life of a module, from install to mounted

  1. InstallFlash zip in the appFiles go to /data/adb/modules_update/<id>
  2. RebootMergeMoved into /data/adb/modules/<id>
  3. CheckFlagsremove deletes it, disable skips it
  4. Scriptpost-fs-data.shRuns before anything is mounted
  5. Applysystem.prop and mountsProps set, system/ bind-mounted
  6. Laterservice.shRuns alongside the rest of boot
From Magisk's module installer script (scripts/util_functions.sh) and module loader (native/src/core/module.rs) at tag v31.1, checked 26 October 2026.

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.

  1. /system, /vendor, /product, /system_extThe merged view every process sees after post-fs-data
    Bind mounts
  2. $MAGISKTMP/.magisk/workertmpfs workspace where Magisk rebuilds any directory that needs new entries
    In RAM
  3. $MAGISKTMP/.magisk/modulesRead-only view of /data/adb/modules, used as the mount source
    In RAM
  4. /data/adb/modules/<id>/systemThe module's own files, on the data partition
    On disk
  5. Real system partitionsNever written to; restoring the stock boot image undoes everything
    Unchanged
Based on Magisk's internal details documentation (paths in the Magisk tmpfs directory) and native/src/core/module.rs at tag v31.1, checked 26 October 2026.

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

PathContents
/data/adb/magiskMagisk's binaries, BusyBox and scripts, used for module installs, addon.d and the app
/data/adb/modulesInstalled modules
/data/adb/modules_updateModules installed or updated since the last boot, merged in on the next reboot
/data/adb/magisk.dbSettings, root grants and the bootloop counter
/data/adb/post-fs-data.d, /data/adb/service.dGeneral 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 magisk domain (u:r:magisk:s0): unconstrained and permissive, used by magiskd and every root shell;
  • a magisk_file type that every domain can access, used for Magisk's sockets, binaries and internal nodes;
  • a magisk_log_file type 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. magiskd no 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/-G handling was fixed.
  • Zygisk on Android 17 (v31.0), resetprop --compact (v31.0), native ChromeOS signing in magiskboot (v31.1).

Internal changes worth knowing about

  1. v28.0Partition mirrors removed from the tmpfs directory; 2SI injection rewritten
  2. v30.0Module loading and magic mount rewritten in Rust
  3. v30.3Magisk can be installed into vendor_boot
  4. v30.7Android 16 QPR2 policy format; klogdump as pre-init storage; su keeps capabilities unless --drop-cap
  5. v31.0Zygisk on Android 17; charger mode detected before force_normal_boot; webview_zygote added to DenyList unmounts
  6. v31.1 (stable)Android 7.0 minimum; app hiding and stub removed; no root prompts; headless system user (HSUM) support
From Magisk's changelog and GitHub releases, checked 26 October 2026. v31.0 was a pre-release; v31.1 is the current stable release.

For the full release history, see Magisk releases. The command-line side of all this is on the tools overview.

Glossary

TermMeaning
Bootloader unlockAllowing 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.imgA 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.
RamdiskThe 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) updatesPhones 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.
fastbootThe 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 bitA Samsung security flag that installing Magisk trips permanently. Knox-dependent features such as Samsung Wallet and Secure Folder stop working.
SystemlessMagisk's approach of changing nothing on the system partition itself. Modifications are applied at boot, so restoring the stock boot image removes them.
Magic mountHow Magisk applies module files: it bind-mounts each module's files over the real /system at boot instead of writing to the partition.
Magisk moduleA folder in /data/adb/modules with files, scripts and properties that Magisk applies at boot.
ZygiskA Magisk feature that runs module code inside every app process by loading into zygote, the process apps are started from.
DenyListMagisk'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.
MagiskSUMagisk's su implementation. Apps request root through it, and you approve or deny each app in the Magisk app's Superuser screen.
Play Integrity verdictGoogle'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.

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