How To Guide How to change any file or directory using Magisk

Search This thread

bnsmb

Senior Member
Aug 22, 2017
243
128
Frankfurt
To change a file (or directory) in one of the read-only mounted filesystems in the Android OS Magisk can be used.
(see How to change files in the directory /system with Magisk and How to make files in /system writable )

But this method only works for files in the directories /system, /vendor, /product, or /system_ext.

In current Android OS implementations there are a lot of other directories on read-only filesystems with files that must be changed or replaced to change the behaviour of Android.

For example on some Android implementations the boot animation is in the file /my_product/media/bootanimation/bootanimation.zip. The standard mechanism to change a file on a read-only mounted filesystem via Magisk can not be used to replace this file with another file.

But Magisk also supports executing scripts while booting the phone (see How to run a script at every boot using Magisk)

And the Magisk init scripts in the directory /data/adb/post-fs-data.d are executed early in the boot process. Therefor we can create a Magisk init script to replace any file with another file using the same method Magisk is using (that is a "mount -o bind ..." ):

Note

All commands in this Howto must be done by the user root.

Example

To replace the boot animation with another one copy the ZIP file with the new boot animation to the directory /data/adb (or any other read-write mounted directory available early in the boot process), e.g:

Code:
ASUS_I006D:/data # ls -l /data/adb/Earth_bootanimation.zip                                                                      
-rw-r--r-- 1 u0_a130 media_rw 13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
ASUS_I006D:/data #

Make sure that the permissions and SELinux contexts for the file are okay using these commands:

Bash:
chown root:root /data/adb/Earth_bootanimation.zip
chmod 0644 /data/adb/Earth_bootanimation.zip
chcon -v u:object_r:system_file:s0 /data/adb/Earth_bootanimation.zip

Result:

Code:
ASUS_I006D:/data # ls -ldZ /data/adb/Earth_bootanimation.zip                                                                    
-rw-r--r-- 1 root root u:object_r:system_file:s0  13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
ASUS_I006D:/data #

Now create a Magisk init script to replace the file via bind mount:

Bash:
echo "mount -o bind /data/adb/Earth_bootanimation.zip   /system/media/bootanimation.zip " >/data/adb/post-fs-data.d/change_bootanimation.sh
chmod 755 /data/adb/post-fs-data.d/change_bootanimation.sh

That's it .. Reboot the phone and enjoy the new animation.

To remove the new animation just delete the script /data/adb/post-fs-data.d/change_bootanimation.sh and reboot the phone.


The same method can be used to replace a complete directory using these steps:

e.g. to make the directory /odm/etc writable do:

Bash:
#
# create the new directory
#
mkdir /data/adb/odm_etc

#
# copy the existing files in /odm/etc to the new directory
#
cd /odm/etc && find . | cpio -pdum /data/adb/odm_etc

#
# create the Magisk init script to replace /odm/etc with the new directory /data/adb/odm_etc
#
echo "# make /odm writable
mount -o bind /data/adb/odm_etc /odm/etc
" >/data/adb/post-fs-data.d/make_odm_etc_writable
chmod 0755 /data/adb/post-fs-data.d/make_odm_etc_writable


Now reboot the phone and check the result:

Code:
ASUS_I006D:/ #
ASUS_I006D:/ # ls -l /odm/etc
total 15
-rw-r--r-- 1 root root 4961 2009-01-01 01:00 NOTICE.xml.gz
-rw------- 1 root root 1136 2009-01-01 01:00 build.prop
-r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_dirs
-r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_files
-rw-r--r-- 1 root root    0 2009-01-01 01:00 group
-rw-r--r-- 1 root root    0 2009-01-01 01:00 passwd
drwxr-xr-x 2 root root 3452 2023-01-18 16:30 selinux
ASUS_I006D:/ #

#
# create a new file in the directory used to replace /odm/etc
#
ASUS_I006D:/ # touch /data/adb/odm_etc/test.$$                                                                                                              

ASUS_I006D:/ # ls -l /data/adb/odm_etc/test.$$                                                                                                              
-rw-r--r-- 1 root root 0 2023-01-18 16:41 /data/adb/odm_etc/test.4597
ASUS_I006D:/ #

#
# check the contents of the directory /odm/etc
#
ASUS_I006D:/ # ls -l /odm/etc/test.$$                                                                                                                      
-rw-r--r-- 1 root root 0 2023-01-18 16:41 //odm/etc/test.4597
ASUS_I006D:/ #


Caution

I'm sure there is a reason why this feature is not implemented for all directories by default in Magisk
And, for example, if you make the directory /odm/etc writable using the method described above Android will complain after the next reboot with an error message that something is wrong with your phone.
Therefor please use with care! If possible only use this approach to make single files writable.


Trouble Shooting


In case the phone does not boot anymore after replacing a file or directory using this method:

Reboot the phone from a recovery with adb support (like TWRP) and delete the script in /data/adb/post-fs-data to fix the error


Notes

Files or directories that are used by Android before the Magisk init scripts are executed can not be changed using this method. These files must be replaced by changing the files in the ramdisk on the boot partition (see How to change files in the boot image using Magisk and How to trigger an action when a property is changed )

There are various Magisk Modules available in the internet to replace the animation that use this technique

To test a boot animation while the Android OS is running do:

Bash:
mount -o bind /data/adb/bootanimation_android12.zip   /system/media/bootanimation.zip                                                        
bootanimation
 

Romano36

Member
Sep 13, 2022
11
0
Can it be used to add a self-signed SSL certificate? And also this method works only with ASUS ZenFone 8 or also with others (e.g. OnePlus 9 pro)?
 

bnsmb

Senior Member
Aug 22, 2017
243
128
Frankfurt
Can it be used to add a self-signed SSL certificate? And also this method works only with ASUS ZenFone 8 or also with others (e.g. OnePlus 9 pro)?
Hi

Can it be used to add a self-signed SSL certificate?

What is the purpose of the new SSL certificate?

If you intend to change the SSL certificate that was used to create the OS :

I did not test this but I'm pretty sure that you can not replace that certificate in an installed OS.

And also this method works only with ASUS ZenFone 8 or also with others (e.g. OnePlus 9 pro)?

This method works for all phones and OS that are supported by Magisk.

regards

Bernd
 

bnsmb

Senior Member
Aug 22, 2017
243
128
Frankfurt
My purpose is to put a new certificate in this folder /system/etc/security/cacerts/. I have to try.

That should work . But I suggest to use a "dummy" Magisk module for that purpose -- see:


regards


Bernd
 
  • Love
Reactions: Romano36

sargodian2

Member
Nov 15, 2012
24
1
30
Sargodha
To change a file (or directory) in one of the read-only mounted filesystems in the Android OS Magisk can be used.
(see How to change files in the directory /system with Magisk and How to make files in /system writable )

But this method only works for files in the directories /system, /vendor, /product, or /system_ext.

In current Android OS implementations there are a lot of other directories on read-only filesystems with files that must be changed or replaced to change the behaviour of Android.

For example on some Android implementations the boot animation is in the file /my_product/media/bootanimation/bootanimation.zip. The standard mechanism to change a file on a read-only mounted filesystem via Magisk can not be used to replace this file with another file.

But Magisk also supports executing scripts while booting the phone (see How to run a script at every boot using Magisk)

And the Magisk init scripts in the directory /data/adb/post-fs-data.d are executed early in the boot process. Therefor we can create a Magisk init script to replace any file with another file using the same method Magisk is using (that is a "mount -o bind ..." ):

Note

All commands in this Howto must be done by the user root.

Example

To replace the boot animation with another one copy the ZIP file with the new boot animation to the directory /data/adb (or any other read-write mounted directory available early in the boot process), e.g:

Code:
ASUS_I006D:/data # ls -l /data/adb/Earth_bootanimation.zip                                                                     
-rw-r--r-- 1 u0_a130 media_rw 13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
ASUS_I006D:/data #

Make sure that the permissions and SELinux contexts for the file are okay using these commands:

Bash:
chown root:root /data/adb/Earth_bootanimation.zip
chmod 0644 /data/adb/Earth_bootanimation.zip
chcon -v u:object_r:system_file:s0 /data/adb/Earth_bootanimation.zip

Result:

Code:
ASUS_I006D:/data # ls -ldZ /data/adb/Earth_bootanimation.zip                                                                   
-rw-r--r-- 1 root root u:object_r:system_file:s0  13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
ASUS_I006D:/data #

Now create a Magisk init script to replace the file via bind mount:

Bash:
echo "mount -o bind /data/adb/Earth_bootanimation.zip   /system/media/bootanimation.zip " >/data/adb/post-fs-data.d/change_bootanimation.sh
chmod 755 /data/adb/post-fs-data.d/change_bootanimation.sh

That's it .. Reboot the phone and enjoy the new animation.

To remove the new animation just delete the script /data/adb/post-fs-data.d/change_bootanimation.sh and reboot the phone.


The same method can be used to replace a complete directory using these steps:

e.g. to make the directory /odm/etc writable do:

Bash:
#
# create the new directory
#
mkdir /data/adb/odm_etc

#
# copy the existing files in /odm/etc to the new directory
#
cd /odm/etc && find . | cpio -pdum /data/adb/odm_etc

#
# create the Magisk init script to replace /odm/etc with the new directory /data/adb/odm_etc
#
echo "# make /odm writable
mount -o bind /data/adb/odm_etc /odm/etc
" >/data/adb/post-fs-data.d/make_odm_etc_writable
chmod 0755 /data/adb/post-fs-data.d/make_odm_etc_writable


Now reboot the phone and check the result:

Code:
ASUS_I006D:/ #
ASUS_I006D:/ # ls -l /odm/etc
total 15
-rw-r--r-- 1 root root 4961 2009-01-01 01:00 NOTICE.xml.gz
-rw------- 1 root root 1136 2009-01-01 01:00 build.prop
-r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_dirs
-r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_files
-rw-r--r-- 1 root root    0 2009-01-01 01:00 group
-rw-r--r-- 1 root root    0 2009-01-01 01:00 passwd
drwxr-xr-x 2 root root 3452 2023-01-18 16:30 selinux
ASUS_I006D:/ #

#
# create a new file in the directory used to replace /odm/etc
#
ASUS_I006D:/ # touch /data/adb/odm_etc/test.$$                                                                                                             

ASUS_I006D:/ # ls -l /data/adb/odm_etc/test.$$                                                                                                             
-rw-r--r-- 1 root root 0 2023-01-18 16:41 /data/adb/odm_etc/test.4597
ASUS_I006D:/ #

#
# check the contents of the directory /odm/etc
#
ASUS_I006D:/ # ls -l /odm/etc/test.$$                                                                                                                     
-rw-r--r-- 1 root root 0 2023-01-18 16:41 //odm/etc/test.4597
ASUS_I006D:/ #


Caution

I'm sure there is a reason why this feature is not implemented for all directories by default in Magisk
And, for example, if you make the directory /odm/etc writable using the method described above Android will complain after the next reboot with an error message that something is wrong with your phone.
Therefor please use with care! If possible only use this approach to make single files writable.


Trouble Shooting


In case the phone does not boot anymore after replacing a file or directory using this method:

Reboot the phone from a recovery with adb support (like TWRP) and delete the script in /data/adb/post-fs-data to fix the error


Notes

Files or directories that are used by Android before the Magisk init scripts are executed can not be changed using this method. These files must be replaced by changing the files in the ramdisk on the boot partition (see How to change files in the boot image using Magisk and How to trigger an action when a property is changed )

There are various Magisk Modules available in the internet to replace the animation that use this technique

To test a boot animation while the Android OS is running do:

Bash:
mount -o bind /data/adb/bootanimation_android12.zip   /system/media/bootanimation.zip                                                       
bootanimation
Hello,

I would like to create a Magisk module that targets the file /odm/etc/mixer_paths.xml.

I am a little confused about the examples you have given. Can you please guide me using the directory I mentioned? It would be very helpful. Thank you.
 

bnsmb

Senior Member
Aug 22, 2017
243
128
Frankfurt
Hello,

I would like to create a Magisk module that targets the file /odm/etc/mixer_paths.xml.

I am a little confused about the examples you have given. Can you please guide me using the directory I mentioned? It would be very helpful. Thank you.
Hi

no Magisk module necessary (but it can be done also via Magisk Module, of course)

Use

- install Magisk

- become root user

- create the file /data/adb/mixer_paths.xml with the changed contents

- create the script /data/adb/post-fs-data.d/change_odm_etc_mixer.sh :

echo "mount -o bind /data/adb/mixer_paths.xml /odm/etc/mixer_paths.xml " >/data/adb/post-fs-data.d/change_odm_etc_mixer.sh

- make the script executable

chmod 755 /data/adb/post-fs-data.d/change_odm_etc_mixer.sh

- reboot


Note that these instructions only work if the file /odm/etc/mixer_paths.xml already exists - you can not create additional files using this approach.


regards

Bernd
 
  • Like
Reactions: sargodian2

sargodian2

Member
Nov 15, 2012
24
1
30
Sargodha
Hi

no Magisk module necessary (but it can be done also via Magisk Module, of course)

Use

- install Magisk

- become root user

- create the file /data/adb/mixer_paths.xml with the changed contents

- create the script /data/adb/post-fs-data.d/change_odm_etc_mixer.sh :

echo "mount -o bind /data/adb/mixer_paths.xml /odm/etc/mixer_paths.xml " >/data/adb/post-fs-data.d/change_odm_etc_mixer.sh

- make the script executable

chmod 755 /data/adb/post-fs-data.d/change_odm_etc_mixer.sh

- reboot


Note that these instructions only work if the file /odm/etc/mixer_paths.xml already exists - you can not create additional files using this approach.


regards

Bernd
Thank You, It worked. 🥳
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    To change a file (or directory) in one of the read-only mounted filesystems in the Android OS Magisk can be used.
    (see How to change files in the directory /system with Magisk and How to make files in /system writable )

    But this method only works for files in the directories /system, /vendor, /product, or /system_ext.

    In current Android OS implementations there are a lot of other directories on read-only filesystems with files that must be changed or replaced to change the behaviour of Android.

    For example on some Android implementations the boot animation is in the file /my_product/media/bootanimation/bootanimation.zip. The standard mechanism to change a file on a read-only mounted filesystem via Magisk can not be used to replace this file with another file.

    But Magisk also supports executing scripts while booting the phone (see How to run a script at every boot using Magisk)

    And the Magisk init scripts in the directory /data/adb/post-fs-data.d are executed early in the boot process. Therefor we can create a Magisk init script to replace any file with another file using the same method Magisk is using (that is a "mount -o bind ..." ):

    Note

    All commands in this Howto must be done by the user root.

    Example

    To replace the boot animation with another one copy the ZIP file with the new boot animation to the directory /data/adb (or any other read-write mounted directory available early in the boot process), e.g:

    Code:
    ASUS_I006D:/data # ls -l /data/adb/Earth_bootanimation.zip                                                                      
    -rw-r--r-- 1 u0_a130 media_rw 13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
    ASUS_I006D:/data #

    Make sure that the permissions and SELinux contexts for the file are okay using these commands:

    Bash:
    chown root:root /data/adb/Earth_bootanimation.zip
    chmod 0644 /data/adb/Earth_bootanimation.zip
    chcon -v u:object_r:system_file:s0 /data/adb/Earth_bootanimation.zip

    Result:

    Code:
    ASUS_I006D:/data # ls -ldZ /data/adb/Earth_bootanimation.zip                                                                    
    -rw-r--r-- 1 root root u:object_r:system_file:s0  13227720 2022-04-16 10:58 /data/adb/Earth_bootanimation.zip
    ASUS_I006D:/data #

    Now create a Magisk init script to replace the file via bind mount:

    Bash:
    echo "mount -o bind /data/adb/Earth_bootanimation.zip   /system/media/bootanimation.zip " >/data/adb/post-fs-data.d/change_bootanimation.sh
    chmod 755 /data/adb/post-fs-data.d/change_bootanimation.sh

    That's it .. Reboot the phone and enjoy the new animation.

    To remove the new animation just delete the script /data/adb/post-fs-data.d/change_bootanimation.sh and reboot the phone.


    The same method can be used to replace a complete directory using these steps:

    e.g. to make the directory /odm/etc writable do:

    Bash:
    #
    # create the new directory
    #
    mkdir /data/adb/odm_etc
    
    #
    # copy the existing files in /odm/etc to the new directory
    #
    cd /odm/etc && find . | cpio -pdum /data/adb/odm_etc
    
    #
    # create the Magisk init script to replace /odm/etc with the new directory /data/adb/odm_etc
    #
    echo "# make /odm writable
    mount -o bind /data/adb/odm_etc /odm/etc
    " >/data/adb/post-fs-data.d/make_odm_etc_writable
    chmod 0755 /data/adb/post-fs-data.d/make_odm_etc_writable


    Now reboot the phone and check the result:

    Code:
    ASUS_I006D:/ #
    ASUS_I006D:/ # ls -l /odm/etc
    total 15
    -rw-r--r-- 1 root root 4961 2009-01-01 01:00 NOTICE.xml.gz
    -rw------- 1 root root 1136 2009-01-01 01:00 build.prop
    -r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_dirs
    -r--r--r-- 1 root root    0 2009-01-01 01:00 fs_config_files
    -rw-r--r-- 1 root root    0 2009-01-01 01:00 group
    -rw-r--r-- 1 root root    0 2009-01-01 01:00 passwd
    drwxr-xr-x 2 root root 3452 2023-01-18 16:30 selinux
    ASUS_I006D:/ #
    
    #
    # create a new file in the directory used to replace /odm/etc
    #
    ASUS_I006D:/ # touch /data/adb/odm_etc/test.$$                                                                                                              
    
    ASUS_I006D:/ # ls -l /data/adb/odm_etc/test.$$                                                                                                              
    -rw-r--r-- 1 root root 0 2023-01-18 16:41 /data/adb/odm_etc/test.4597
    ASUS_I006D:/ #
    
    #
    # check the contents of the directory /odm/etc
    #
    ASUS_I006D:/ # ls -l /odm/etc/test.$$                                                                                                                      
    -rw-r--r-- 1 root root 0 2023-01-18 16:41 //odm/etc/test.4597
    ASUS_I006D:/ #


    Caution

    I'm sure there is a reason why this feature is not implemented for all directories by default in Magisk
    And, for example, if you make the directory /odm/etc writable using the method described above Android will complain after the next reboot with an error message that something is wrong with your phone.
    Therefor please use with care! If possible only use this approach to make single files writable.


    Trouble Shooting


    In case the phone does not boot anymore after replacing a file or directory using this method:

    Reboot the phone from a recovery with adb support (like TWRP) and delete the script in /data/adb/post-fs-data to fix the error


    Notes

    Files or directories that are used by Android before the Magisk init scripts are executed can not be changed using this method. These files must be replaced by changing the files in the ramdisk on the boot partition (see How to change files in the boot image using Magisk and How to trigger an action when a property is changed )

    There are various Magisk Modules available in the internet to replace the animation that use this technique

    To test a boot animation while the Android OS is running do:

    Bash:
    mount -o bind /data/adb/bootanimation_android12.zip   /system/media/bootanimation.zip                                                        
    bootanimation
    1
    My purpose is to put a new certificate in this folder /system/etc/security/cacerts/. I have to try.

    That should work . But I suggest to use a "dummy" Magisk module for that purpose -- see:


    regards


    Bernd
    1
    Hello,

    I would like to create a Magisk module that targets the file /odm/etc/mixer_paths.xml.

    I am a little confused about the examples you have given. Can you please guide me using the directory I mentioned? It would be very helpful. Thank you.
    Hi

    no Magisk module necessary (but it can be done also via Magisk Module, of course)

    Use

    - install Magisk

    - become root user

    - create the file /data/adb/mixer_paths.xml with the changed contents

    - create the script /data/adb/post-fs-data.d/change_odm_etc_mixer.sh :

    echo "mount -o bind /data/adb/mixer_paths.xml /odm/etc/mixer_paths.xml " >/data/adb/post-fs-data.d/change_odm_etc_mixer.sh

    - make the script executable

    chmod 755 /data/adb/post-fs-data.d/change_odm_etc_mixer.sh

    - reboot


    Note that these instructions only work if the file /odm/etc/mixer_paths.xml already exists - you can not create additional files using this approach.


    regards

    Bernd