Tools-cx-app/meta-magic_mount-rs
About
An implementation of a metamodule using Magic Mount, Based on MKSU, Template is from meta-overlay.
Other ProjectsMeasured star growth
- in 24h
- +2
- in 7 days
- +12
- in 15 days
- +30
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
docs/README_en.md
OriginalIntroduction
Magic Mount Metamodule (mmrs) is a Rust implementation of a Magic Mount metamodule. It merges files from enabled modules into the system mount view, using tmpfs and bind mounts to provide systemless modifications without writing directly to system partitions.
- Module mounting: merge module
system/contents and handlevendor,system_ext,product, andodmaccording to the device layout. - Custom partitions: extend the traditional layout with
partitions, or mount partition directories from the module root withextra_mount. - Directory rules: replace directories with
.replaceor hide them with.remove. - Lua extensions: queue bind mounts before or after Magic Mount, or skip, block, replace, and hide content for a specific module.
- WebUI: view module mount status and edit configuration in either the MiuiX or MD3 theme.
Installation and usage
- In a KernelSU / APatch environment with metamodule support, download the ZIP for your architecture from Releases, or choose the
universalpackage. - Install the ZIP through your root manager and reboot.
- Open the module WebUI, adjust the configuration, save, and reboot to apply changes.
The installer recognizes the arm64, arm, x64, and riscv64 architecture identifiers. Magisk is not supported. Actual mounting requires a rooted Android environment.
Configuration lives at /data/adb/magic_mount/config.toml. Updates preserve an existing configuration; uninstalling the metamodule deletes the entire /data/adb/magic_mount/ directory, including configuration and Lua scripts.
Configuration
Use the WebUI configuration page or edit the TOML file directly. Both MiuiX and MD3 let you add and remove partitions and extra_mount entries. The backend checks filesystem eligibility.
Configuration example
mountsource = "KSU"
umount = false
partitions = []
extra_mount = []
These are the installation defaults for KernelSU. A fresh APatch installation uses mountsource = "APatch"; the other fields are identical.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mountsource |
String | "KSU" / "APatch" |
Mount source label, selected for the root platform on first installation. |
umount |
Boolean | false |
Register mount paths with KernelSU for attempted unmounting. Requires the corresponding kernel interface; does not unmount them immediately. |
partitions |
String array | [] |
Additionally handle <module>/system/<partition>/, mounting its contents at an existing /<partition>/. |
extra_mount |
String array | [] |
Read <module>/<partition>/ and merge its contents into an existing /<partition>/. |
vendor, system_ext, product, and odm already have built-in handling and do not need entries in partitions. The first three require /system/<partition> to be a symlink; odm does not.
tmpfsdir is no longer a configuration field. The implementation uses /debug_ramdisk as its temporary tmpfs mount point. moduledir and disable_umount are fields in the CLI JSON interface, not TOML settings.
partitions and extra_mount
For example, a module using the traditional layout places files in system/mi_ext/, while the extra mount directory lives at the module root as my_product/:
example_module/
├── module.prop
├── system/
│ ├── etc/example.conf → /system/etc/example.conf
│ └── mi_ext/etc/example.xml → /mi_ext/etc/example.xml
└── my_product/
└── etc/example.xml → /my_product/etc/example.xml
Use this configuration:
mountsource = "KSU"
umount = false
partitions = ["mi_ext"]
extra_mount = ["my_product"]
Each extra_mount entry must meet these conditions:
- Use a single name, not a path. It must not be empty,
.,.., orsystem, and must not contain/or NUL. - The target at the filesystem root, such as
/my_product, must be an existing directory. /system/<name>must have no directory entry at all, including a dangling symlink.
Duplicate names are processed once. Invalid or ineligible entries are logged and skipped. Modules containing only top-level extra_mount content can mount without a system/ directory.
Module and directory rules
Module markers
A module-root disable, remove, or skip_mount marker prevents mount content scanning and execution of that module's Lua API 2 load() callback. Modules listed in BLOCKLIST in the installation script metainstall.sh are also excluded from mounting.
Ordinary mount conflicts are resolved in ascending module ID order, using IDs from module.prop: the first contribution at a conflicting path wins. Rule matching does not depend on directory names.
Directory markers
Create an empty marker file in the corresponding module directory and reboot:
| Marker | Effect | Example |
|---|---|---|
.replace |
Replace the target directory with module contents, without retaining the original system directory contents. | system/app/Foo/.replace |
.remove |
Hide the entire target directory and its contents in the mount view, without deleting files on disk. | system/app/Foo/.remove |
Within the same directory, .remove takes precedence over .replace, and that directory's module contents are not mounted. Neither marker is mounted. Directories under extra_mount support the same markers. The directory extended attribute trusted.overlay.opaque=y also requests replacement.
.remove applies only to directory nodes; use Lua remove() to hide a regular file or symlink. A module-root remove marker, without a dot, requests module removal and has a different meaning.
Lua extensions
Script location and headers
Place Lua 5.5 scripts in /data/adb/magic_mount/lua/ and reboot. Only regular .lua files directly in that directory are loaded, in ascending filename order. Symlinks and subdirectories are excluded. A missing directory means no scripts. Each script uses an independent Lua VM.
Start each file with API = 1 or API = 2; API 2 must then declare MODULE = "module ID". Each literal declaration occupies its own line. Leading whitespace, Lua comments, and either string quote style are supported. API and MODULE are read-only at runtime.
API 1: before and after hooks
The optional callbacks before() and after() take no arguments and provide bind_mount(source, target):
API = 1
function before()
bind_mount("/data/local/tmp/before.conf", "/system/etc/before.conf")
end
function after()
bind_mount("/data/local/tmp/hosts", "/system/etc/hosts")
end
Prepare the source files first. A missing source is logged and its bind is skipped. Targets must be absolute. Paths must not be empty or contain control characters or .. components. Binds are read-only. A missing target uses a temporary mirror from the nearest existing non-root ancestor; mirroring the entire root is refused.
Execution order:
- Call all
before()callbacks in filename order to collect the bind queue. - Apply module rules, prepare the mount tree, and write the startup snapshot.
- Prepare tmpfs, execute before binds, and perform Magic Mount.
- After successful Magic Mount, call all
after()callbacks in filename order. Execute after binds only if every callback succeeds.
Magic Mount may cover a before bind target. Script loading, before, module rule, or tree preparation errors stop execution before mounting. An after callback error cancels that stage's bind queue without rolling back completed Magic Mount. A failure during bind execution does not guarantee rollback of the whole batch either.
API 2: rules for a specific module
MODULE matches the ID in module.prop. Before scanning that module's mount content, the required Lua function load() is called without arguments. Scripts for the same module run in filename order. Missing modules and modules excluded by markers or BLOCKLIST do not invoke load().
API = 2
MODULE = "example_module"
function load()
block("system/etc/unwanted.conf")
replace("/data/local/tmp/hosts", "system/etc/hosts")
remove("system/app/Example")
end
These functions are available only inside the load() callback:
| Function | Behavior |
|---|---|
skip() |
Skip all mount content scanning and mounting for the module, clear its rules, ignore subsequent rules, and stop later scripts for that module. Takes no arguments, is idempotent, and creates no skip_mount file. |
block(path) |
Exclude only this module's contribution at a file or directory path, preserving original system content and other modules' contributions. |
replace(source, target) |
Replace a module-relative target with an absolute regular file or directory. Directories replace contents as a whole. The last declaration for a target wins; source symlinks and special devices are rejected. |
remove(path) |
Hide a file, symlink, or directory in the final mount view, including other modules' contributions at that path, without deleting disk contents. Partition roots cannot be removed. |
Paths are relative to the module root and must start with system or an eligible extra_mount partition. Examples include my_product/etc/example.xml and, for a traditional partition, system/mi_ext/etc/example.xml. Absolute targets, empty paths, control characters, and .. components are rejected. Modules without system/ can still contribute mount content through rules.
skip() overrides all rules. Otherwise, precedence is remove > block > replace, with ancestor block / remove rules covering descendants. block and replace apply before the module is merged; remove applies to the final tree. replace does not change the first-contribution policy for ordinary conflicts between modules.
To skip the whole module, replace load() with:
function load()
skip()
return
end
skip() does not end the current Lua callback; use return to leave early. It applies only to this boot. The module remains in query results as unmounted.
Runtime environment and migration
The global moduledir points to the modules root, /data/adb/modules, rather than the directory of the script's target module. Lua provides the base, table, string, math, and utf8 libraries. It does not provide os, io, package, debug, file loaders, rawset, or setmetatable. Local scripts have no execution time or memory quotas.
Migrate legacy bind calls to API 1 bind_mount, and modules[id].skip to API 2 skip(). Legacy custom/custom.lua files are no longer read. The WebUI does not provide a Lua script editor.
Command-line interface
The installed entry point is /data/adb/modules/magic_mount_rs/meta-mm. Run it from an Android root shell, for example:
/data/adb/modules/magic_mount_rs/meta-mm show-config
/data/adb/modules/magic_mount_rs/meta-mm modules
/data/adb/modules/magic_mount_rs/meta-mm version
| Command | Description |
|---|---|
show-config |
Output configuration and compatibility fields as JSON. |
save-config --payload HEX |
Save configuration encoded as UTF-8 JSON, then hexadecimal. Supports partial updates. |
gen-config |
Overwrite configuration with program defaults: KSU, false, and two empty arrays. Does not select APatch defaults by platform. |
modules |
Scan current module identities and merge mount status, modes, and rules from the startup snapshot by ID, then output JSON. |
version |
Output the version as JSON. |
emulated-soft-reboot |
Unmount recorded mounts for an emulated soft reboot; used by lifecycle scripts. |
| No subcommand | Perform the full mount flow; invoked by the metamodule startup script. |
In show-config, moduledir is fixed at /data/adb/modules, and disable_umount is the inverse of umount. When both unmount fields are supplied on save, umount takes precedence. These commands initialize the runtime and read configuration first. modules also requires a valid /data/adb/magic_mount/scan.ret.
Building and development
Prerequisites
- Rust nightly with
rust-src,rustc-codegen-cranelift-preview,rustfmt, andclippy. - Android NDK r29 and
cargo-ndk. - Node.js >= 24 and the pnpm version pinned in
packageManagerin webui/package.json.
The following example uses Linux. The RISC-V build currently uses the NDK's linux-x86_64 toolchain directory explicitly.
git clone https://github.com/Tools-cx-app/meta-magic_mount-rs.git
cd meta-magic_mount-rs
rustup toolchain install nightly --component rust-src --component rustc-codegen-cranelift-preview --component rustfmt --component clippy
rustup target add --toolchain nightly aarch64-linux-android armv7-linux-androideabi x86_64-linux-android
cargo install cargo-ndk
export ANDROID_NDK_HOME=/path/to/android-ndk-r29
export ANDROID_NDK_ROOT="$ANDROID_NDK_HOME"
cd webui
pnpm install --frozen-lockfile
cd ..
cargo xtask build -t arm64
Build targets and artifacts
-t value |
Architectures included | Current build API |
|---|---|---|
arm64 (default) |
arm64-v8a |
30 |
armv7 |
armeabi-v7a |
26 |
x86-64 |
x86_64 |
30 |
riscv64 |
riscv64 |
35 |
universal |
All of the above | 26 for ARM / x86, 35 for RISC-V |
The build compiles the WebUI, then the binaries, and packages the module. Artifacts are written to output/magic_mount_rs-<version>-<Git commit count>-<architecture>.zip; x86 package names use x86_64. Use cargo xtask -- --help for task help.
Checks
Run from the repository root:
cargo test
cargo fmt --all -- --check
cargo ndk --platform 26 -t arm64-v8a -t armeabi-v7a clippy -- -D warnings
Run from webui/:
pnpm run lint
pnpm run typecheck
pnpm run build
Use pnpm run dev for frontend development with the mock API. Standalone frontend builds default the module ID to test; build installable packages through cargo xtask build to inject the correct ID.
Cargo builds generate module/module.prop, and frontend builds write directly to module/webroot/. These paths, along with module/bin/, output/, and target/, contain generated artifacts and should not be edited manually or committed. Host tests do not verify real tmpfs, bind, or move mounts; mount behavior requires a rooted Android device.
Frequently asked questions
Why do saved settings not apply immediately?
Mounting runs at boot. Reboot after changing configuration, directory markers, or Lua scripts.
Why is a saved extra_mount partition not mounted?
Check that the content lives at the module root, the target directory exists, and /system/<name> has no entry. Also check the module exclusion markers. Invalid or ineligible entries are skipped. Inspect the Android log for details:
logcat -d -s MagicMount
Does the WebUI status prove that every file mounted successfully?
No. Neither modules nor WebUI queries execute Lua. They merge current module identities with /data/adb/magic_mount/scan.ret by ID. The snapshot is written before actual mounting and describes the startup plan. Newly installed modules appear as unmounted until included in a new snapshot. A missing or corrupt snapshot causes the query to fail.
When reporting a problem, include device and root platform details, the version, relevant configuration, module layout, Lua scripts, and MagicMount logs.
Acknowledgements
- 5ec1cff/KernelSU: original Magic Mount implementation.
- YuzakiKokuban: WebUI improvements.
- shadow3aaa/fas-rs: reference for the configuration and Lua extension module structure, and for this documentation's layout.
License
This project is licensed under GNU GPL v3.
Star History
Explore related projects
Loading…