[ASUS ZenFone 8] bnsmb:
How to change files in the directory /system with Magisk

Note:

I tested the instructions below with Magisk 24. 25.0, and 25.2 on an ASUS Zenfone 8 running OmniROM (Android 12 ) .

The filesystem for /system is normally mounted read-only In Android 12 and it's difficult to change files in that filesystem.

One possible solution to change files in /system is to create a Magisk module for this task.

For testing if a Magisk Module would work like expected you can create a Dummy Magisk module . The steps to implement the Dummy Magisk Module are:

Install Magisk, enable root access for the shell in Magisk and enable access via adb (this can be done in the "Developer Options" in the system settings)

Next connect to the phone using the command

adb shell

and become root user

su -

Now create a sub directory in the directory

/data/adb/modules

e.g.

ASUS_I006D:/ # ls -ld /data/adb/modules/*
drwxrws--- 3 u0_a118 media_rw 3452 2022-05-30 12:12 /data/adb/modules/playstore
ASUS_I006D:/ #

Then copy the new files for the directory in /system to that directory (/data/adb/modules/<modulename>/ is equal here to the root dir, /, on the phone)

Example:

ASUS_I006D:/ # find /data/adb/modules/playstore
/data/adb/modules/playstore
/data/adb/modules/playstore/system
/data/adb/modules/playstore/system/etc
/data/adb/modules/playstore/system/etc/permissions
/data/adb/modules/playstore/system/etc/permissions/com.android.vending.xml
/data/adb/modules/playstore/system/priv-app
/data/adb/modules/playstore/system/priv-app/Phonesky
/data/adb/modules/playstore/system/priv-app/Phonesky/lib
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libbrotli.so
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libconscrypt_jni.so
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libcronet.85.0.4181.5.so
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libgame_sdk_device_info_jni.so
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libphonesky_data_loader.so
/data/adb/modules/playstore/system/priv-app/Phonesky/lib/arm/libtensorflowlite_jni.so
/data/adb/modules/playstore/system/priv-app/Phonesky/Phonesky.apk
/data/adb/modules/playstore/system/priv-app/FakeStore
/data/adb/modules/playstore/system/priv-app/FakeStore/oat
/data/adb/modules/playstore/system/priv-app/FakeStore/oat/arm64
/data/adb/modules/playstore/system/priv-app/FakeStore/oat/arm64/FakeStore.odex
/data/adb/modules/playstore/system/priv-app/FakeStore/oat/arm64/FakeStore.vdex
/data/adb/modules/playstore/system/priv-app/FakeStore/FakeStore.apk
ASUS_I006D:/ #

Now reboot the phone.

After the reboot all files in /data/adb/modules/<modulename> will be mapped to /system by Magisk, e.g:

ASUS_I006D:/ # find /system/priv-app/Phonesky/
/system/priv-app/Phonesky/
/system/priv-app/Phonesky/lib
/system/priv-app/Phonesky/lib/arm
/system/priv-app/Phonesky/lib/arm/libbrotli.so
/system/priv-app/Phonesky/lib/arm/libconscrypt_jni.so
/system/priv-app/Phonesky/lib/arm/libcronet.85.0.4181.5.so
/system/priv-app/Phonesky/lib/arm/libgame_sdk_device_info_jni.so
/system/priv-app/Phonesky/lib/arm/libphonesky_data_loader.so
/system/priv-app/Phonesky/lib/arm/libtensorflowlite_jni.so
/system/priv-app/Phonesky/Phonesky.apk
ASUS_I006D:/ #

ASUS_I006D:/ # find /system/priv-app/FakeStore/
/system/priv-app/FakeStore/
/system/priv-app/FakeStore/oat
/system/priv-app/FakeStore/oat/arm64
/system/priv-app/FakeStore/oat/arm64/FakeStore.vdex
/system/priv-app/FakeStore/oat/arm64/FakeStore.odex
/system/priv-app/FakeStore/FakeStore.apk
ASUS_I006D:/ #

Because the mapping will be done while booting the phone it will also survive updating the OS on the phone to a new version as long as the user data is not deleted and Magisk is installed in the boot partition.

Notes:

Magisk "replaces" existing directories and files in /system with the files in that directory by using bind mounts.

You can not add additional files or directories to /system using this method -- it's only possible to add additional files and directories to the existing sub directories in /system.

This Magisk feature can also be used to make files in sub directories in /system writable -- see How to make files in system writable for detailed instructions.

This method can also be used to replace files in the directories /vendor, /product, or /system_ext:

from https://topjohnwu.github.io/Magisk/guides.html:

But this seems to work only to replace existing files in these directories.

This method to replace files in /system simulates a module in Magisk so if everything is okay I strongly recommend to create a "real" Magisk Module with the new files for /system.

Trouble Shooting

If something does not work check the Magisk log file in /cache :

/cache/magisk.log

History

Update 10.06.2022

added the infos about how to update files /vendor, /product, /system-ext

Update 12.06.2022

The Magisk Module to install the patched Playstore used in this example can be downloaded here

http://bnsmb.de/files/public/Android/PlayStore_for_MicroG.zip

see also this Message

https://xdaforums.com/t/magisk-modu...h-a-patched-playstore-from-nanodroid.4456421/

Update 03.10.2022

The sentence about how to update files in /vendor, /product, /system-ext was missing here --fixed

Added a note about what can not be done using this method

Update 04.11.2022

Added the hint for the post to make files in /system writable

Doing some cleanup to make the instructions more clear

Update 18.01.2023

See How to change any file or directory using Magisk for another approach to change files on read-only mounted filesystems.